@@ -56,29 +56,8 @@ namespace FREYR_NAMESPACE
5656 void Scene::BeginProfiling ()
5757 {
5858#ifdef FREYR_PROFILING
59- auto args = perfetto::TracingInitArgs ();
60- args.backends |= perfetto::kInProcessBackend ;
6159
62- perfetto::Tracing::Initialize (args);
63- perfetto::TrackEvent::Register ();
64-
65- perfetto::protos::gen::TrackEventConfig track_event_cfg;
66-
67- perfetto::TraceConfig cfg;
68- cfg.add_buffers ()->set_size_kb (1024 * 1024 ); // Record up to 1 GiB.
69-
70- auto * ds_cfg = cfg.add_data_sources ()->mutable_config ();
71- ds_cfg->set_name (" track_event" );
72- ds_cfg->set_track_event_config_raw (track_event_cfg.SerializeAsString ());
73-
74- mTracingSession = perfetto::Tracing::NewTrace ();
75- mTracingSession ->Setup (cfg);
76-
77- mTracingSession ->StartBlocking ();
78-
79- FREYR_PROFILING_BEGIN (" FREYR" , " Main Thread" , perfetto::Track (0 ));
80-
81- mTaskManager ->BeginProfiling ();
60+ mBeginProfiling = true ;
8261
8362#endif // FREYR_PROFILING
8463 }
@@ -105,6 +84,38 @@ namespace FREYR_NAMESPACE
10584
10685 void Scene::Update (float dt)
10786 {
87+ #ifdef FREYR_PROFILING
88+
89+ if (BeginProfiling)
90+ {
91+ BeginProfiling = false ;
92+ auto args = perfetto::TracingInitArgs ();
93+ args.backends |= perfetto::kInProcessBackend ;
94+
95+ perfetto::Tracing::Initialize (args);
96+ perfetto::TrackEvent::Register ();
97+
98+ perfetto::protos::gen::TrackEventConfig track_event_cfg;
99+
100+ perfetto::TraceConfig cfg;
101+ cfg.add_buffers ()->set_size_kb (1024 * 1024 ); // Record up to 1 GiB.
102+
103+ auto * ds_cfg = cfg.add_data_sources ()->mutable_config ();
104+ ds_cfg->set_name (" track_event" );
105+ ds_cfg->set_track_event_config_raw (track_event_cfg.SerializeAsString ());
106+
107+ mTracingSession = perfetto::Tracing::NewTrace ();
108+ mTracingSession ->Setup (cfg);
109+
110+ mTracingSession ->StartBlocking ();
111+
112+ FREYR_PROFILING_BEGIN (" FREYR" , " Main Thread" , perfetto::Track (0 ));
113+
114+ mTaskManager ->BeginProfiling ();
115+ }
116+
117+ #endif // FREYR_PROFILING
118+
108119 const auto provider = mServiceProvider .lock ()->CreateServiceScope ()->GetServiceProvider ();
109120
110121 mFixedDeltaTimeAccumulator += dt;
0 commit comments