Skip to content

Commit 038a331

Browse files
committed
client: Enable profiler if set in config
1 parent a491372 commit 038a331

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

client/src/CV8ScriptRuntime.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "inspector/CV8InspectorChannel.h"
55
#include "V8Module.h"
66
#include "events/Events.h"
7+
#include "CProfiler.h"
78

89
CV8ScriptRuntime::CV8ScriptRuntime()
910
{
@@ -204,6 +205,28 @@ CV8ScriptRuntime::CV8ScriptRuntime()
204205
}
205206

206207
RegisterEvents();
208+
209+
ProcessConfigOptions();
210+
}
211+
212+
void CV8ScriptRuntime::ProcessConfigOptions()
213+
{
214+
alt::config::Node moduleConfig = alt::ICore::Instance().GetClientConfig()["js-module"];
215+
if(!moduleConfig.IsDict()) return;
216+
217+
alt::config::Node profiler = moduleConfig["profiler"];
218+
if(!profiler.IsNone())
219+
{
220+
try
221+
{
222+
bool result = profiler.ToBool();
223+
CProfiler::Instance().SetIsEnabled(result);
224+
}
225+
catch(alt::config::Error&)
226+
{
227+
Log::Error << "Invalid value for 'profiler' config option" << Log::Endl;
228+
}
229+
}
207230
}
208231

209232
void CV8ScriptRuntime::OnDispose()
@@ -214,6 +237,8 @@ void CV8ScriptRuntime::OnDispose()
214237
v8::V8::ShutdownPlatform();
215238
delete create_params.array_buffer_allocator;
216239

240+
if(CProfiler::Instance().IsEnabled()) CProfiler::Instance().Dump(alt::ICore::Instance().GetClientPath().ToString());
241+
217242
CV8ScriptRuntime::SetInstance(nullptr);
218243
delete this;
219244
}

client/src/CV8ScriptRuntime.h

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class CV8ScriptRuntime : public alt::IScriptRuntime
4141
public:
4242
CV8ScriptRuntime();
4343

44+
void ProcessConfigOptions();
45+
4446
void OnDispose() override;
4547

4648
static void SetInstance(CV8ScriptRuntime* runtime)

0 commit comments

Comments
 (0)