Skip to content

Commit fe36e23

Browse files
committed
Don't redirect compileFinal to compile
1 parent aedf4be commit fe36e23

File tree

3 files changed

+87
-40
lines changed

3 files changed

+87
-40
lines changed

src/ArmaScriptProfiler.vcxproj

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
<SDLCheck>true</SDLCheck>
9292
<AdditionalIncludeDirectories>$(SolutionDir)..\Intercept\src\client\headers;$(SolutionDir)..\Intercept\src\client\headers\client;$(SolutionDir)..\Intercept\src\client\headers\shared;$(SolutionDir)..\Intercept\src\client\headers\client\sqf;$(SolutionDir)..\Intercept\src;$(SolutionDir)..\brofiler\BrofilerCore;$(SolutionDir)..\brofiler\ThirdParty\TaskScheduler\Scheduler\Include;$(SolutionDir)..\tracy;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
9393
<MultiProcessorCompilation>true</MultiProcessorCompilation>
94-
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;INTERCEPT_SQF_STRTYPE_RSTRING;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
94+
<PreprocessorDefinitions>WITH_BROFILER;WITH_CHROME;_CRT_SECURE_NO_WARNINGS;INTERCEPT_SQF_STRTYPE_RSTRING;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
9595
<LanguageStandard>stdcpplatest</LanguageStandard>
9696
<MinimalRebuild>false</MinimalRebuild>
9797
</ClCompile>
@@ -106,7 +106,7 @@
106106
<SDLCheck>true</SDLCheck>
107107
<AdditionalIncludeDirectories>$(SolutionDir)..\Intercept\src\client\headers;$(SolutionDir)..\Intercept\src\client\headers\client;$(SolutionDir)..\Intercept\src\client\headers\shared;$(SolutionDir)..\Intercept\src\client\headers\client\sqf;$(SolutionDir)..\Intercept\src;$(SolutionDir)..\brofiler\BrofilerCore;$(SolutionDir)..\brofiler\ThirdParty\TaskScheduler\Scheduler\Include;$(SolutionDir)..\tracy;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
108108
<MultiProcessorCompilation>true</MultiProcessorCompilation>
109-
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;INTERCEPT_SQF_STRTYPE_RSTRING;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
109+
<PreprocessorDefinitions>WITH_BROFILER;WITH_CHROME;_CRT_SECURE_NO_WARNINGS;INTERCEPT_SQF_STRTYPE_RSTRING;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
110110
<LanguageStandard>stdcpplatest</LanguageStandard>
111111
<MinimalRebuild>false</MinimalRebuild>
112112
</ClCompile>
@@ -120,7 +120,7 @@
120120
<SDLCheck>true</SDLCheck>
121121
<AdditionalIncludeDirectories>$(SolutionDir)..\Intercept\src\client\headers;$(SolutionDir)..\Intercept\src\client\headers\client;$(SolutionDir)..\Intercept\src\client\headers\shared;$(SolutionDir)..\Intercept\src\client\headers\client\sqf;$(SolutionDir)..\Intercept\src;$(SolutionDir)..\brofiler\BrofilerCore;$(SolutionDir)..\brofiler\ThirdParty\TaskScheduler\Scheduler\Include;$(SolutionDir)..\tracy;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
122122
<MultiProcessorCompilation>true</MultiProcessorCompilation>
123-
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;INTERCEPT_SQF_STRTYPE_RSTRING;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
123+
<PreprocessorDefinitions>WITH_BROFILER;WITH_CHROME;_CRT_SECURE_NO_WARNINGS;INTERCEPT_SQF_STRTYPE_RSTRING;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
124124
<LanguageStandard>stdcpplatest</LanguageStandard>
125125
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
126126
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
@@ -142,7 +142,7 @@
142142
<SDLCheck>true</SDLCheck>
143143
<AdditionalIncludeDirectories>$(SolutionDir)..\Intercept\src\client\headers;$(SolutionDir)..\Intercept\src\client\headers\client;$(SolutionDir)..\Intercept\src\client\headers\shared;$(SolutionDir)..\Intercept\src\client\headers\client\sqf;$(SolutionDir)..\Intercept\src;$(SolutionDir)..\brofiler\BrofilerCore;$(SolutionDir)..\brofiler\ThirdParty\TaskScheduler\Scheduler\Include;$(SolutionDir)..\tracy;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
144144
<MultiProcessorCompilation>true</MultiProcessorCompilation>
145-
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;INTERCEPT_SQF_STRTYPE_RSTRING;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
145+
<PreprocessorDefinitions>WITH_BROFILER;WITH_CHROME;_CRT_SECURE_NO_WARNINGS;INTERCEPT_SQF_STRTYPE_RSTRING;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
146146
<LanguageStandard>stdcpplatest</LanguageStandard>
147147
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
148148
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
@@ -234,9 +234,7 @@
234234
<ClCompile Include="..\intercept\src\client\intercept\shared\containers.cpp" />
235235
<ClCompile Include="..\intercept\src\client\intercept\shared\types.cpp" />
236236
<ClCompile Include="AdapterArmaDiag.cpp" />
237-
<ClCompile Include="AdapterBrofiler.cpp">
238-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
239-
</ClCompile>
237+
<ClCompile Include="AdapterBrofiler.cpp" />
240238
<ClCompile Include="AdapterChrome.cpp" />
241239
<ClCompile Include="AdapterTracy.cpp" />
242240
<ClCompile Include="EngineProfiling.cpp" />

src/hooks.asm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
option casemap :none
2-
.intel_syntax noprefix
3-
42

53
_TEXT SEGMENT
64
;https://msdn.microsoft.com/en-us/library/windows/hardware/ff561499(v=vs.85).aspx

src/scriptProfiler.cpp

Lines changed: 82 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "Event.h"
1414
#include "AdapterChrome.hpp"
1515
#include "AdapterTracy.hpp"
16+
#include <memory>
17+
#include <string>
1618

1719
using namespace intercept;
1820
using namespace std::chrono_literals;
@@ -579,6 +581,46 @@ game_value compileRedirect2(const game_state& state, game_value_parameter messag
579581
return comp;
580582
}
581583

584+
game_value compileRedirectFinal(const game_state& state, game_value_parameter message) {
585+
if (!profiler.compileScope) {
586+
static r_string compileEventText("compile");
587+
static r_string profName("scriptProfiler.cpp");
588+
profiler.compileScope = GProfilerAdapter->createScope(compileEventText, profName, __LINE__);
589+
}
590+
591+
auto tempData = GProfilerAdapter->enterScope(profiler.compileScope);
592+
593+
r_string str = message;
594+
595+
auto comp = sqf::compile_final(str);
596+
auto bodyCode = static_cast<game_data_code*>(comp.data.get());
597+
if (!bodyCode->instructions) {
598+
GProfilerAdapter->leaveScope(tempData);
599+
return comp;
600+
}
601+
602+
#ifdef WITH_BROFILER
603+
if (auto brofilerData = std::dynamic_pointer_cast<ScopeTempStorageBrofiler>(tempData)) {
604+
r_string src = getScriptFromFirstLine(bodyCode->instructions->front()->sdp, false);
605+
brofilerData->evtDt->sourceCode = src;
606+
}
607+
#endif
608+
609+
GProfilerAdapter->leaveScope(tempData);
610+
611+
auto& funcPath = bodyCode->instructions->front()->sdp.sourcefile;
612+
std::string scriptName = getScriptName(str, funcPath, 32);
613+
//if (scriptName.empty()) scriptName = "<unknown>";
614+
615+
if (bodyCode->instructions && !scriptName.empty() && scriptName != "<unknown>")
616+
addScopeInstruction(bodyCode, scriptName);
617+
618+
return comp;
619+
}
620+
621+
622+
623+
582624
game_value callExtensionRedirect(uintptr_t st, game_value_parameter ext, game_value_parameter msg) {
583625
if (!profiler.callExtScope) {
584626
static r_string compileEventText("callExtension");
@@ -640,36 +682,6 @@ std::optional<std::string> getCommandLineParam(std::string_view needle) {
640682
}
641683

642684
scriptProfiler::scriptProfiler() {
643-
if (getCommandLineParam("-profilerEnableInstruction"sv)) {
644-
instructionLevelProfiling = true;
645-
}
646-
647-
auto startAdapter = getCommandLineParam("-profilerAdapter"sv);
648-
649-
if (startAdapter) {
650-
if (false) {
651-
#ifdef WITH_CHROME
652-
} else if (*startAdapter == "Chrome"sv) {
653-
auto chromeAdapter = std::make_shared<AdapterChrome>();
654-
GProfilerAdapter = chromeAdapter;
655-
656-
auto chromeOutput = getCommandLineParam("-profilerOutput"sv);
657-
if (chromeOutput)
658-
chromeAdapter->setTargetFile(*chromeOutput);
659-
#endif
660-
#ifdef WITH_BROFILER
661-
} else if (*startAdapter == "Brofiler"sv) {
662-
GProfilerAdapter = std::make_shared<AdapterBrofiler>();
663-
#endif
664-
} else if (*startAdapter == "Arma"sv) {
665-
GProfilerAdapter = std::make_shared<AdapterArmaDiag>();
666-
} else if (*startAdapter == "Tracy"sv) {
667-
GProfilerAdapter = std::make_shared<AdapterTracy>();
668-
}
669-
} else {
670-
GProfilerAdapter = std::make_shared<AdapterTracy>();
671-
}
672-
673685

674686
}
675687
#ifndef __linux__
@@ -980,6 +992,45 @@ class GameInstructionNewExpression : public game_instruction {
980992
#pragma endregion Instructions
981993
#endif
982994
void scriptProfiler::preStart() {
995+
996+
if (getCommandLineParam("-profilerEnableInstruction"sv)) {
997+
instructionLevelProfiling = true;
998+
}
999+
1000+
auto startAdapter = getCommandLineParam("-profilerAdapter"sv);
1001+
1002+
if (startAdapter) {
1003+
if (false) {
1004+
#ifdef WITH_CHROME
1005+
}
1006+
else if (*startAdapter == "Chrome"sv) {
1007+
auto chromeAdapter = std::make_shared<AdapterChrome>();
1008+
GProfilerAdapter = chromeAdapter;
1009+
1010+
auto chromeOutput = getCommandLineParam("-profilerOutput"sv);
1011+
if (chromeOutput)
1012+
chromeAdapter->setTargetFile(*chromeOutput);
1013+
#endif
1014+
#ifdef WITH_BROFILER
1015+
}
1016+
else if (*startAdapter == "Brofiler"sv) {
1017+
GProfilerAdapter = std::make_shared<AdapterBrofiler>();
1018+
#endif
1019+
}
1020+
else if (*startAdapter == "Arma"sv) {
1021+
GProfilerAdapter = std::make_shared<AdapterArmaDiag>();
1022+
}
1023+
else if (*startAdapter == "Tracy"sv) {
1024+
GProfilerAdapter = std::make_shared<AdapterTracy>();
1025+
}
1026+
}
1027+
else {
1028+
GProfilerAdapter = std::make_shared<AdapterTracy>();
1029+
}
1030+
1031+
1032+
1033+
9831034
#ifndef __linux__
9841035
if (getCommandLineParam("-profilerEnableEngine"sv)) {
9851036
engineProf = std::make_shared<EngineProfiling>();
@@ -1003,7 +1054,7 @@ void scriptProfiler::preStart() {
10031054
static auto _profilerCompile = client::host::register_sqf_command("compile", "Profiler redirect", compileRedirect2, game_data_type::CODE, game_data_type::STRING);
10041055
//static auto _profilerCompile2 = client::host::register_sqf_command("compile2", "Profiler redirect", compileRedirect, game_data_type::CODE, game_data_type::STRING);
10051056
//static auto _profilerCompile3 = client::host::register_sqf_command("compile3", "Profiler redirect", compileRedirect2, game_data_type::CODE, game_data_type::STRING);
1006-
static auto _profilerCompileF = client::host::register_sqf_command("compileFinal", "Profiler redirect", compileRedirect2, game_data_type::CODE, game_data_type::STRING);
1057+
static auto _profilerCompileF = client::host::register_sqf_command("compileFinal", "Profiler redirect", compileRedirectFinal, game_data_type::CODE, game_data_type::STRING);
10071058
static auto _profilerCallExt = client::host::register_sqf_command("callExtension", "Profiler redirect", callExtensionRedirect, game_data_type::STRING, game_data_type::STRING, game_data_type::STRING);
10081059
static auto _profilerDiagLog = client::host::register_sqf_command("diag_log", "Profiler redirect", diag_logRedirect, game_data_type::NOTHING, game_data_type::ANY);
10091060
static auto _profilerProfScript = client::host::register_sqf_command("profileScript", "Profiler redirect", profileScript, game_data_type::ARRAY, game_data_type::ARRAY);

0 commit comments

Comments
 (0)