Skip to content

Commit

Permalink
Merge pull request #289 from vsg-dev/Profiler
Browse files Browse the repository at this point in the history
Profiler
  • Loading branch information
robertosfield authored Mar 6, 2024
2 parents b88197d + 48ea012 commit 7520ed3
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 143 deletions.
18 changes: 18 additions & 0 deletions examples/animation/vsganimation/vsganimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ int main(int argc, char** argv)

instrumentation = gpu_instrumentation;
}
else if (arguments.read({"--profiler", "--pr"}))
{
// set Profiler options
auto settings = vsg::Profiler::Settings::create();
arguments.read("--cpu", settings->cpu_instrumentation_level);
arguments.read("--gpu", settings->gpu_instrumentation_level);
arguments.read("--log-size", settings->log_size);
arguments.read("--gpu-size", settings->gpu_timestamp_size);

// create the profiler
instrumentation = vsg::Profiler::create(settings);
}
#ifdef Tracy_FOUND
else if (arguments.read("--tracy"))
{
Expand Down Expand Up @@ -490,5 +502,11 @@ int main(int argc, char** argv)
std::cout << "Average update time = " << (updateTime / numFramesCompleted)*1000.0 <<" ms"<< std::endl;
}

if (auto profiler = instrumentation.cast<vsg::Profiler>())
{
instrumentation->finish();
profiler->log->report(std::cout);
}

return 0;
}
18 changes: 18 additions & 0 deletions examples/app/vsgviewer/vsgviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ int main(int argc, char** argv)

instrumentation = gpu_instrumentation;
}
else if (arguments.read({"--profiler", "--pr"}))
{
// set Profiler options
auto settings = vsg::Profiler::Settings::create();
arguments.read("--cpu", settings->cpu_instrumentation_level);
arguments.read("--gpu", settings->gpu_instrumentation_level);
arguments.read("--log-size", settings->log_size);
arguments.read("--gpu-size", settings->gpu_timestamp_size);

// create the profiler
instrumentation = vsg::Profiler::create(settings);
}

// should animations be automatically played
auto autoPlay = !arguments.read({"--no-auto-play", "--nop"});
Expand Down Expand Up @@ -287,6 +299,12 @@ int main(int argc, char** argv)
double fps = static_cast<double>(fs->frameCount) / std::chrono::duration<double, std::chrono::seconds::period>(vsg::clock::now() - viewer->start_point()).count();
std::cout<<"Average frame rate = "<<fps<<" fps"<<std::endl;
}

if (auto profiler = instrumentation.cast<vsg::Profiler>())
{
instrumentation->finish();
profiler->log->report(std::cout);
}
}
catch (const vsg::Exception& ve)
{
Expand Down
18 changes: 18 additions & 0 deletions examples/nodes/vsgshadow/vsgshadow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ int main(int argc, char** argv)

instrumentation = gpu_instrumentation;
}
else if (arguments.read({"--profiler", "--pr"}))
{
// set Profiler options
auto settings = vsg::Profiler::Settings::create();
arguments.read("--cpu", settings->cpu_instrumentation_level);
arguments.read("--gpu", settings->gpu_instrumentation_level);
arguments.read("--log-size", settings->log_size);
arguments.read("--gpu-size", settings->gpu_timestamp_size);

// create the profiler
instrumentation = vsg::Profiler::create(settings);
}
#ifdef Tracy_FOUND
else if (arguments.read("--tracy"))
{
Expand Down Expand Up @@ -575,5 +587,11 @@ int main(int argc, char** argv)
std::cout << "Average frame rate = " << (numFramesCompleted / duration) << std::endl;
}

if (auto profiler = instrumentation.cast<vsg::Profiler>())
{
instrumentation->finish();
profiler->log->report(std::cout);
}

return 0;
}
18 changes: 18 additions & 0 deletions examples/threading/vsgdynamicload/vsgdynamicload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ int main(int argc, char** argv)

instrumentation = gpu_instrumentation;
}
else if (arguments.read({"--profiler", "--pr"}))
{
// set Profiler options
auto settings = vsg::Profiler::Settings::create();
arguments.read("--cpu", settings->cpu_instrumentation_level);
arguments.read("--gpu", settings->gpu_instrumentation_level);
arguments.read("--log-size", settings->log_size);
arguments.read("--gpu-size", settings->gpu_timestamp_size);

// create the profiler
instrumentation = vsg::Profiler::create(settings);
}
#ifdef Tracy_FOUND
else if (arguments.read("--tracy"))
{
Expand Down Expand Up @@ -263,6 +275,12 @@ int main(int argc, char** argv)

// if (loadThreads->queue->empty()) break;
}

if (auto profiler = instrumentation.cast<vsg::Profiler>())
{
instrumentation->finish();
profiler->log->report(std::cout);
}
}
catch (const vsg::Exception& ve)
{
Expand Down
1 change: 0 additions & 1 deletion examples/utils/vsginstrumentation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
set(SOURCES
vsginstrumentation.cpp
Profiler.cpp
)

add_executable(vsginstrumentation ${SOURCES})
Expand Down
96 changes: 0 additions & 96 deletions examples/utils/vsginstrumentation/Profiler.cpp

This file was deleted.

39 changes: 0 additions & 39 deletions examples/utils/vsginstrumentation/Profiler.h

This file was deleted.

22 changes: 15 additions & 7 deletions examples/utils/vsginstrumentation/vsginstrumentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
#include <iostream>
#include <thread>

#include "Profiler.h"


class InstrumentationHandler : public vsg::Inherit<vsg::Visitor, InstrumentationHandler>
{
public:
Expand Down Expand Up @@ -122,9 +119,14 @@ int main(int argc, char** argv)
bool decorate = arguments.read("--decorate");

// set Profiler options
auto instrumentation = vsg::Profiler::create();
arguments.read("--cpu", instrumentation->settings->cpu_instrumentation_level);
arguments.read("--gpu", instrumentation->settings->gpu_instrumentation_level);
auto settings = vsg::Profiler::Settings::create();
arguments.read("--cpu", settings->cpu_instrumentation_level);
arguments.read("--gpu", settings->gpu_instrumentation_level);
arguments.read("--log-size", settings->log_size);
arguments.read("--gpu-size", settings->gpu_timestamp_size);

// create the profiler
auto instrumentation = vsg::Profiler::create(settings);

auto window = vsg::Window::create(windowTraits);
if (!window)
Expand Down Expand Up @@ -239,7 +241,7 @@ int main(int argc, char** argv)
animationPathHandler->printFrameStatsToConsole = true;
viewer->addEventHandler(animationPathHandler);

// add event handler to control the cpu and gpu_instrumentation_level using the 'c', 'g' keys to reduce the cpu and gpu instruemntation level, and 'C' and 'G' to increase them respectively.
// add event handler to control the cpu and gpu_instrumentation_level using the 'c', 'g' keys to reduce the cpu and gpu instrumentation level, and 'C' and 'G' to increase them respectively.
viewer->addEventHandler(InstrumentationHandler::create(instrumentation));

viewer->addEventHandler(vsg::Trackball::create(camera, ellipsoidModel));
Expand Down Expand Up @@ -276,6 +278,12 @@ int main(int argc, char** argv)
double fps = static_cast<double>(fs->frameCount) / std::chrono::duration<double, std::chrono::seconds::period>(vsg::clock::now() - viewer->start_point()).count();
std::cout<<"Average frame rate = "<<fps<<" fps"<<std::endl;
}

if (instrumentation && instrumentation->log)
{
instrumentation->finish();
instrumentation->log->report(std::cout);
}
}
catch (const vsg::Exception& ve)
{
Expand Down

0 comments on commit 7520ed3

Please sign in to comment.