Skip to content

Commit

Permalink
Display duration
Browse files Browse the repository at this point in the history
  • Loading branch information
sguionni committed Oct 8, 2024
1 parent 365d469 commit bd63dd1
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 45 deletions.
2 changes: 2 additions & 0 deletions lib/app/include/app/core/renderer/renderer_system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace VTX::App::Core::Renderer
inline static FilePath SHADER_DIR = Util::Filesystem::getExecutableDir();

RendererSystem() : VTX::Renderer::Facade( 1, 1, SHADER_DIR ) {}

inline static void init( const FilePath & p_shaderPath ) { SHADER_DIR = p_shaderPath; }
};

} // namespace VTX::App::Core::Renderer
Expand Down
43 changes: 15 additions & 28 deletions lib/app/src/app/core/action/action_system.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "app/core/action/action_system.hpp"
#include <exception>
#include <typeinfo>
#include <util/chrono.hpp>
#include <util/logger.hpp>
#include <util/string.hpp>

namespace VTX::App::Core::Action
{
Expand All @@ -12,46 +14,31 @@ namespace VTX::App::Core::Action
VTX_DEBUG( "ActionSystem::execute( {} )", typeid( *p_actionPtr ).name() );
try
{
p_actionPtr->execute();
// VTX_EVENT( ACTION_EXECUTED_EVENT, *actionPtr );
// // Signal catched and managed by ScenePathData component
// switch ( p_action->getTag() )
//{
// case ACTION_TAG::MODIFY_SCENE:
// if ( isActionUndonable )
// App::Old::APP::getScenePathData().incrementSceneModifications();
// else // if the action is not undoable, it make a permanent modification on scene
// App::Old::APP::getScenePathData().forceSceneModifications();
// break;
// case ACTION_TAG::NONE:
// default: break;
//}
auto duration = Util::CHRONO_CPU( [ &p_actionPtr ]() { p_actionPtr->execute(); } );
VTX_DEBUG(
"ActionSystem::execute( {} ) - done ({})",
typeid( *p_actionPtr ).name(),
Util::String::durationToStr( duration )
);
}
catch ( const std::exception & p_e )
{
VTX_ERROR( "Error with action of type {} : {}", typeid( *p_actionPtr ).name(), p_e.what() );
return;
}
}

void ActionSystem::execute( std::unique_ptr<BaseActionUndonable> & p_actionPtr )
{
VTX_DEBUG( "ActionSystem::execute( {} )", typeid( *p_actionPtr ).name() );
try
{
p_actionPtr->execute();
// VTX_EVENT( ACTION_EXECUTED_EVENT, *actionPtr );
// // Signal catched and managed by ScenePathData component
// switch ( p_action->getTag() )
//{
// case ACTION_TAG::MODIFY_SCENE:
// if ( isActionUndonable )
// App::Old::APP::getScenePathData().incrementSceneModifications();
// else // if the action is not undoable, it make a permanent modification on scene
// App::Old::APP::getScenePathData().forceSceneModifications();
// break;
// case ACTION_TAG::NONE:
// default: break;
//}
auto duration = Util::CHRONO_CPU( [ &p_actionPtr ]() { p_actionPtr->execute(); } );
VTX_DEBUG(
"ActionSystem::execute( {} ) - done ({})",
typeid( *p_actionPtr ).name(),
Util::String::durationToStr( duration )
);
}
catch ( const std::exception & p_e )
{
Expand Down
3 changes: 2 additions & 1 deletion lib/app/src/app/serialization/io/reader/molecule_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <util/color/rgba.hpp>
#include <util/enum.hpp>
#include <util/logger.hpp>
#include <util/string.hpp>

namespace VTX::App::Serialization::IO::Reader
{
Expand All @@ -32,7 +33,7 @@ namespace VTX::App::Serialization::IO::Reader
chrono.start();
p_molecule.setMoleculeStruct( moleculeStruct );
chrono.stop();
VTX_INFO( "Build Molecule convenient structure : {}", chrono.elapsedTimeStr() );
VTX_INFO( "Build Molecule convenient structure : {}", Util::String::durationToStr( chrono.elapsedTime() ) );
}

void MoleculeLoader::readBuffer(
Expand Down
2 changes: 1 addition & 1 deletion lib/app/src/app/vtx_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace VTX::App
Settings::initSettings();

// Init renderer.
Core::Renderer::RendererSystem::SHADER_DIR = Filesystem::getShadersDir();
Core::Renderer::RendererSystem::init( Filesystem::getShadersDir() );

// Setup entity creation routines (add components, setup components, etc.).
Internal::ECS::setupEntityDirector();
Expand Down
11 changes: 6 additions & 5 deletions lib/io/src/io/reader/chemfiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <util/color/rgba.hpp>
#include <util/exceptions.hpp>
#include <util/logger.hpp>
#include <util/string.hpp>

#pragma warning( push, 0 )
#include <chemfiles.hpp>
Expand Down Expand Up @@ -108,7 +109,7 @@ namespace VTX::IO::Reader
std::unique_ptr<Chemfiles> chemfilesReader = std::make_unique<Chemfiles>( p_path );

chrono.stop();
VTX_INFO( "readFile : {}", chrono.elapsedTimeStr() );
VTX_INFO( "readFile : {}", Util::String::durationToStr( chrono.elapsedTime() ) );

return chemfilesReader;
}
Expand All @@ -123,7 +124,7 @@ namespace VTX::IO::Reader
std::unique_ptr<Chemfiles> chemfilesReader = std::make_unique<Chemfiles>( p_buffer, p_path );

chrono.stop();
VTX_INFO( "readBuffer : {}", chrono.elapsedTimeStr() );
VTX_INFO( "readBuffer : {}", Util::String::durationToStr( chrono.elapsedTime() ) );

return chemfilesReader;
}
Expand Down Expand Up @@ -154,18 +155,18 @@ namespace VTX::IO::Reader
chrono.start();
_preRead();
chrono.stop();
VTX_INFO( "_preRead: {}", chrono.elapsedTimeStr() );
VTX_INFO( "_preRead: {}", Util::String::durationToStr( chrono.elapsedTime() ) );

chrono.start();
chemfiles::Frame frame;
_read();
chrono.stop();
VTX_INFO( "Trajectory read in: {}", chrono.elapsedTimeStr() );
VTX_INFO( "Trajectory read in: {}", Util::String::durationToStr( chrono.elapsedTime() ) );

chrono.start();
_postRead();
chrono.stop();
VTX_INFO( "_postRead: {}", chrono.elapsedTimeStr() );
VTX_INFO( "_postRead: {}", Util::String::durationToStr( chrono.elapsedTime() ) );
}

void Chemfiles::_preRead()
Expand Down
10 changes: 7 additions & 3 deletions lib/ui/qt/src/ui/qt/dock_widget/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ namespace VTX::UI::QT::DockWidget

groupCacheBox->setLayout( groupCacheLayout );

auto * buttonCacheLayout = new QHBoxLayout( this );
auto * buttonOpenCache = new QPushButton( "Open", this );
auto * buttonClearCache = new QPushButton( "Clear", this );
auto * buttonCacheLayout = new QHBoxLayout( this );
auto * buttonOpenCache = new QPushButton( "Open", this );
auto * buttonClearCache = new QPushButton( "Clear", this );
auto * buttonRefreshCache = new QPushButton( "Refresh", this );

const FilePath cachePath = App::Filesystem::getCacheDir();
connect(
Expand All @@ -47,13 +48,16 @@ namespace VTX::UI::QT::DockWidget
}
);

connect( buttonRefreshCache, &QPushButton::clicked, [ this ]() { _refreshCacheInfos(); } );

_labelCacheCount = new QLabel( this );
_labelCacheSize = new QLabel( this );

groupCacheLayout->addWidget( _labelCacheCount );
groupCacheLayout->addWidget( _labelCacheSize );
buttonCacheLayout->addWidget( buttonOpenCache );
buttonCacheLayout->addWidget( buttonClearCache );
buttonCacheLayout->addWidget( buttonRefreshCache );
groupCacheLayout->addLayout( buttonCacheLayout );

layout->addWidget( groupCacheBox );
Expand Down
9 changes: 4 additions & 5 deletions lib/util/include/util/chrono.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ namespace VTX::Util

static long long getTimestamp();

void start();
void stop();
float elapsedTime() const;
std::string elapsedTimeStr() const;
float intervalTime();
void start();
void stop();
float elapsedTime() const;
float intervalTime();

private:
using SystemClock = std::chrono::system_clock;
Expand Down
2 changes: 2 additions & 0 deletions lib/util/include/util/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace VTX::Util::String
std::string toUpper( const std::string & p_str );
// Memory size to string.
std::string memSizeToStr( const size_t p_size );
// Duration to string.
std::string durationToStr( const float p_durationInSeconds );

} // namespace VTX::Util::String

Expand Down
2 changes: 0 additions & 2 deletions lib/util/src/util/chrono.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ namespace VTX::Util
return ( std::chrono::duration_cast<Duration>( Clock::now() - _begin ) ).count();
}

std::string Chrono::elapsedTimeStr() const { return std::to_string( elapsedTime() ) + 's'; }

float Chrono::intervalTime()
{
Duration intervalTime = std::chrono::duration_cast<Duration>( Clock::now() - _interval );
Expand Down
34 changes: 34 additions & 0 deletions lib/util/src/util/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,38 @@ namespace VTX::Util::String
return oss.str();
}

std::string durationToStr( const float p_durationInSeconds )
{
std::ostringstream oss;
int totalMilliseconds = static_cast<int>( p_durationInSeconds * 1000 );

int hours = totalMilliseconds / 3600000;
totalMilliseconds %= 3600000;

int minutes = totalMilliseconds / 60000;
totalMilliseconds %= 60000;

int seconds = totalMilliseconds / 1000;
int milliseconds = totalMilliseconds % 1000;

if ( hours > 0 )
{
oss << hours << " h ";
}
if ( minutes > 0 || hours > 0 )
{
oss << minutes << " min ";
}
if ( seconds > 0 || minutes > 0 || hours > 0 )
{
oss << seconds << " s ";
}
if ( milliseconds > 0 || ( hours == 0 && minutes == 0 && seconds == 0 ) )
{
oss << milliseconds << " ms";
}

return oss.str();
}

} // namespace VTX::Util::String

0 comments on commit bd63dd1

Please sign in to comment.