Skip to content

Commit

Permalink
Don't redirect compileFinal to compile
Browse files Browse the repository at this point in the history
  • Loading branch information
dedmen committed Jan 26, 2019
1 parent aedf4be commit fe36e23
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 40 deletions.
12 changes: 5 additions & 7 deletions src/ArmaScriptProfiler.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<SDLCheck>true</SDLCheck>
<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>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;INTERCEPT_SQF_STRTYPE_RSTRING;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WITH_BROFILER;WITH_CHROME;_CRT_SECURE_NO_WARNINGS;INTERCEPT_SQF_STRTYPE_RSTRING;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<LanguageStandard>stdcpplatest</LanguageStandard>
<MinimalRebuild>false</MinimalRebuild>
</ClCompile>
Expand All @@ -106,7 +106,7 @@
<SDLCheck>true</SDLCheck>
<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>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;INTERCEPT_SQF_STRTYPE_RSTRING;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WITH_BROFILER;WITH_CHROME;_CRT_SECURE_NO_WARNINGS;INTERCEPT_SQF_STRTYPE_RSTRING;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<LanguageStandard>stdcpplatest</LanguageStandard>
<MinimalRebuild>false</MinimalRebuild>
</ClCompile>
Expand All @@ -120,7 +120,7 @@
<SDLCheck>true</SDLCheck>
<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>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;INTERCEPT_SQF_STRTYPE_RSTRING;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WITH_BROFILER;WITH_CHROME;_CRT_SECURE_NO_WARNINGS;INTERCEPT_SQF_STRTYPE_RSTRING;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<LanguageStandard>stdcpplatest</LanguageStandard>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
Expand All @@ -142,7 +142,7 @@
<SDLCheck>true</SDLCheck>
<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>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;INTERCEPT_SQF_STRTYPE_RSTRING;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WITH_BROFILER;WITH_CHROME;_CRT_SECURE_NO_WARNINGS;INTERCEPT_SQF_STRTYPE_RSTRING;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<LanguageStandard>stdcpplatest</LanguageStandard>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
Expand Down Expand Up @@ -234,9 +234,7 @@
<ClCompile Include="..\intercept\src\client\intercept\shared\containers.cpp" />
<ClCompile Include="..\intercept\src\client\intercept\shared\types.cpp" />
<ClCompile Include="AdapterArmaDiag.cpp" />
<ClCompile Include="AdapterBrofiler.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="AdapterBrofiler.cpp" />
<ClCompile Include="AdapterChrome.cpp" />
<ClCompile Include="AdapterTracy.cpp" />
<ClCompile Include="EngineProfiling.cpp" />
Expand Down
2 changes: 0 additions & 2 deletions src/hooks.asm
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
option casemap :none
.intel_syntax noprefix


_TEXT SEGMENT
;https://msdn.microsoft.com/en-us/library/windows/hardware/ff561499(v=vs.85).aspx
Expand Down
113 changes: 82 additions & 31 deletions src/scriptProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "Event.h"
#include "AdapterChrome.hpp"
#include "AdapterTracy.hpp"
#include <memory>
#include <string>

using namespace intercept;
using namespace std::chrono_literals;
Expand Down Expand Up @@ -579,6 +581,46 @@ game_value compileRedirect2(const game_state& state, game_value_parameter messag
return comp;
}

game_value compileRedirectFinal(const game_state& state, game_value_parameter message) {
if (!profiler.compileScope) {
static r_string compileEventText("compile");
static r_string profName("scriptProfiler.cpp");
profiler.compileScope = GProfilerAdapter->createScope(compileEventText, profName, __LINE__);
}

auto tempData = GProfilerAdapter->enterScope(profiler.compileScope);

r_string str = message;

auto comp = sqf::compile_final(str);
auto bodyCode = static_cast<game_data_code*>(comp.data.get());
if (!bodyCode->instructions) {
GProfilerAdapter->leaveScope(tempData);
return comp;
}

#ifdef WITH_BROFILER
if (auto brofilerData = std::dynamic_pointer_cast<ScopeTempStorageBrofiler>(tempData)) {
r_string src = getScriptFromFirstLine(bodyCode->instructions->front()->sdp, false);
brofilerData->evtDt->sourceCode = src;
}
#endif

GProfilerAdapter->leaveScope(tempData);

auto& funcPath = bodyCode->instructions->front()->sdp.sourcefile;
std::string scriptName = getScriptName(str, funcPath, 32);
//if (scriptName.empty()) scriptName = "<unknown>";

if (bodyCode->instructions && !scriptName.empty() && scriptName != "<unknown>")
addScopeInstruction(bodyCode, scriptName);

return comp;
}




game_value callExtensionRedirect(uintptr_t st, game_value_parameter ext, game_value_parameter msg) {
if (!profiler.callExtScope) {
static r_string compileEventText("callExtension");
Expand Down Expand Up @@ -640,36 +682,6 @@ std::optional<std::string> getCommandLineParam(std::string_view needle) {
}

scriptProfiler::scriptProfiler() {
if (getCommandLineParam("-profilerEnableInstruction"sv)) {
instructionLevelProfiling = true;
}

auto startAdapter = getCommandLineParam("-profilerAdapter"sv);

if (startAdapter) {
if (false) {
#ifdef WITH_CHROME
} else if (*startAdapter == "Chrome"sv) {
auto chromeAdapter = std::make_shared<AdapterChrome>();
GProfilerAdapter = chromeAdapter;

auto chromeOutput = getCommandLineParam("-profilerOutput"sv);
if (chromeOutput)
chromeAdapter->setTargetFile(*chromeOutput);
#endif
#ifdef WITH_BROFILER
} else if (*startAdapter == "Brofiler"sv) {
GProfilerAdapter = std::make_shared<AdapterBrofiler>();
#endif
} else if (*startAdapter == "Arma"sv) {
GProfilerAdapter = std::make_shared<AdapterArmaDiag>();
} else if (*startAdapter == "Tracy"sv) {
GProfilerAdapter = std::make_shared<AdapterTracy>();
}
} else {
GProfilerAdapter = std::make_shared<AdapterTracy>();
}


}
#ifndef __linux__
Expand Down Expand Up @@ -980,6 +992,45 @@ class GameInstructionNewExpression : public game_instruction {
#pragma endregion Instructions
#endif
void scriptProfiler::preStart() {

if (getCommandLineParam("-profilerEnableInstruction"sv)) {
instructionLevelProfiling = true;
}

auto startAdapter = getCommandLineParam("-profilerAdapter"sv);

if (startAdapter) {
if (false) {
#ifdef WITH_CHROME
}
else if (*startAdapter == "Chrome"sv) {
auto chromeAdapter = std::make_shared<AdapterChrome>();
GProfilerAdapter = chromeAdapter;

auto chromeOutput = getCommandLineParam("-profilerOutput"sv);
if (chromeOutput)
chromeAdapter->setTargetFile(*chromeOutput);
#endif
#ifdef WITH_BROFILER
}
else if (*startAdapter == "Brofiler"sv) {
GProfilerAdapter = std::make_shared<AdapterBrofiler>();
#endif
}
else if (*startAdapter == "Arma"sv) {
GProfilerAdapter = std::make_shared<AdapterArmaDiag>();
}
else if (*startAdapter == "Tracy"sv) {
GProfilerAdapter = std::make_shared<AdapterTracy>();
}
}
else {
GProfilerAdapter = std::make_shared<AdapterTracy>();
}




#ifndef __linux__
if (getCommandLineParam("-profilerEnableEngine"sv)) {
engineProf = std::make_shared<EngineProfiling>();
Expand All @@ -1003,7 +1054,7 @@ void scriptProfiler::preStart() {
static auto _profilerCompile = client::host::register_sqf_command("compile", "Profiler redirect", compileRedirect2, game_data_type::CODE, game_data_type::STRING);
//static auto _profilerCompile2 = client::host::register_sqf_command("compile2", "Profiler redirect", compileRedirect, game_data_type::CODE, game_data_type::STRING);
//static auto _profilerCompile3 = client::host::register_sqf_command("compile3", "Profiler redirect", compileRedirect2, game_data_type::CODE, game_data_type::STRING);
static auto _profilerCompileF = client::host::register_sqf_command("compileFinal", "Profiler redirect", compileRedirect2, game_data_type::CODE, game_data_type::STRING);
static auto _profilerCompileF = client::host::register_sqf_command("compileFinal", "Profiler redirect", compileRedirectFinal, game_data_type::CODE, game_data_type::STRING);
static auto _profilerCallExt = client::host::register_sqf_command("callExtension", "Profiler redirect", callExtensionRedirect, game_data_type::STRING, game_data_type::STRING, game_data_type::STRING);
static auto _profilerDiagLog = client::host::register_sqf_command("diag_log", "Profiler redirect", diag_logRedirect, game_data_type::NOTHING, game_data_type::ANY);
static auto _profilerProfScript = client::host::register_sqf_command("profileScript", "Profiler redirect", profileScript, game_data_type::ARRAY, game_data_type::ARRAY);
Expand Down

0 comments on commit fe36e23

Please sign in to comment.