@@ -1180,7 +1180,9 @@ void scriptProfiler::preStart() {
11801180 static auto _profilerSetAdapter = client::host::register_sqf_command (" profilerSetAdapter" , " Set's profiler Adapter" , profilerSetAdapter, game_data_type::NOTHING, game_data_type::STRING);
11811181 static auto _profilerSetCounter = client::host::register_sqf_command (" profilerSetCounter" , " Set's a counter value" , profilerSetCounter, game_data_type::NOTHING, game_data_type::STRING, game_data_type::SCALAR);
11821182
1183- if (!getCommandLineParam (" -profilerNoInstrumentation" sv)) {
1183+ auto compHookDisabled = client::host::request_plugin_interface (" ProfilerNoCompile" , 1 ); // ASM will call us via interface instead
1184+
1185+ if (!compHookDisabled && !getCommandLineParam (" -profilerNoInstrumentation" sv)) {
11841186 static auto _profilerCompile = client::host::register_sqf_command (" compile" , " Profiler redirect" , compileRedirect2, game_data_type::CODE, game_data_type::STRING);
11851187 // static auto _profilerCompile2 = client::host::register_sqf_command("compile2", "Profiler redirect", compileRedirect, game_data_type::CODE, game_data_type::STRING);
11861188 // static auto _profilerCompile3 = client::host::register_sqf_command("compile3", "Profiler redirect", compileRedirect2, game_data_type::CODE, game_data_type::STRING);
@@ -1189,41 +1191,42 @@ void scriptProfiler::preStart() {
11891191 static auto _profilerCallExt = client::host::register_sqf_command (" callExtension" , " Profiler redirect" , callExtensionRedirect, game_data_type::STRING, game_data_type::STRING, game_data_type::STRING);
11901192 static auto _profilerDiagLog = client::host::register_sqf_command (" diag_log" , " Profiler redirect" , diag_logRedirect, game_data_type::NOTHING, game_data_type::ANY);
11911193 static auto _profilerProfScript = client::host::register_sqf_command (" profileScript" , " Profiler redirect" , profileScript, game_data_type::ARRAY, game_data_type::ARRAY);
1192- static auto _profilerPrepFile = client::host::register_sqf_command (" preprocessFile" , " Profiler redirect" , [](game_state&, game_value_parameter arg) -> game_value {
1193- if (!profiler.preprocFileScope ) {
1194- static r_string compileEventText (" preprocessFile" );
1195- static r_string profName (" scriptProfiler.cpp" );
1196- profiler.preprocFileScope = GProfilerAdapter->createScope (compileEventText, profName, __LINE__);
1197- }
1194+ if (!compHookDisabled) {
1195+ static auto _profilerPrepFile = client::host::register_sqf_command (" preprocessFile" , " Profiler redirect" , [](game_state&, game_value_parameter arg) -> game_value {
1196+ if (!profiler.preprocFileScope ) {
1197+ static r_string compileEventText (" preprocessFile" );
1198+ static r_string profName (" scriptProfiler.cpp" );
1199+ profiler.preprocFileScope = GProfilerAdapter->createScope (compileEventText, profName, __LINE__);
1200+ }
11981201
1199- auto tempData = GProfilerAdapter->enterScope (profiler.preprocFileScope );
1202+ auto tempData = GProfilerAdapter->enterScope (profiler.preprocFileScope );
12001203
1201- GProfilerAdapter->setName (tempData, " preprocessFile " +static_cast <r_string>(arg));
1204+ GProfilerAdapter->setName (tempData, " preprocessFile " +static_cast <r_string>(arg));
12021205
1203- auto res = sqf::preprocess_file_line_numbers (arg);
1206+ auto res = sqf::preprocess_file_line_numbers (arg);
12041207
1205- GProfilerAdapter->leaveScope (tempData);
1208+ GProfilerAdapter->leaveScope (tempData);
12061209
1207- return res;
1208- }, game_data_type::STRING, game_data_type::STRING);
1209- static auto _profilerPrepFileLN = client::host::register_sqf_command (" preprocessFileLineNumbers" , " Profiler redirect" , [](game_state&, game_value_parameter arg) -> game_value {
1210- if (!profiler.preprocFileScope ) {
1211- static r_string compileEventText (" preprocessFileLineNumbers" );
1212- static r_string profName (" scriptProfiler.cpp" );
1213- profiler.preprocFileScope = GProfilerAdapter->createScope (compileEventText, profName, __LINE__);
1214- }
1215-
1216- auto tempData = GProfilerAdapter->enterScope (profiler.preprocFileScope );
1210+ return res;
1211+ }, game_data_type::STRING, game_data_type::STRING);
1212+ static auto _profilerPrepFileLN = client::host::register_sqf_command (" preprocessFileLineNumbers" , " Profiler redirect" , [](game_state&, game_value_parameter arg) -> game_value {
1213+ if (!profiler.preprocFileScope ) {
1214+ static r_string compileEventText (" preprocessFileLineNumbers" );
1215+ static r_string profName (" scriptProfiler.cpp" );
1216+ profiler.preprocFileScope = GProfilerAdapter->createScope (compileEventText, profName, __LINE__);
1217+ }
12171218
1218- GProfilerAdapter-> setName ( tempData, " preprocessFile " + static_cast <r_string>(arg) );
1219+ auto tempData = GProfilerAdapter-> enterScope (profiler. preprocFileScope );
12191220
1220- auto res = sqf::preprocess_file_line_numbers ( arg);
1221+ GProfilerAdapter-> setName (tempData, " preprocessFile " + static_cast <r_string>( arg) );
12211222
1222- GProfilerAdapter-> leaveScope (tempData );
1223+ auto res = sqf::preprocess_file_line_numbers (arg );
12231224
1224- return res;
1225- }, game_data_type::STRING, game_data_type::STRING);
1225+ GProfilerAdapter->leaveScope (tempData);
12261226
1227+ return res;
1228+ }, game_data_type::STRING, game_data_type::STRING);
1229+ }
12271230#ifndef __linux__
12281231 auto iface = client::host::request_plugin_interface (" sqf_asm_devIf" , 1 );
12291232 if (iface) {
@@ -1389,6 +1392,38 @@ class ArmaScriptProfiler_ProfInterface {
13891392
13901393 return game_value (new GameDataProfileScope (std::move (data)));
13911394 }
1395+
1396+ // v3
1397+ virtual void ASM_createScopeInstr (game_state& state, game_data_code* bodyCode) {
1398+ if (bodyCode->instructions .empty ()) {
1399+ return ;
1400+ }
1401+
1402+ #ifdef WITH_BROFILER
1403+ if (auto brofilerData = std::dynamic_pointer_cast<ScopeTempStorageBrofiler>(tempData)) {
1404+ r_string src = getScriptFromFirstLine (bodyCode->instructions ->front ()->sdp , false );
1405+ brofilerData->evtDt ->sourceCode = src;
1406+ }
1407+ #endif
1408+
1409+ auto & funcPath = bodyCode->instructions .front ()->sdp .sourcefile ;
1410+
1411+ auto scriptName = tryGetNameFromInitFunctions (state);
1412+ if (!scriptName) scriptName = tryGetNameFromCBACompile (state);
1413+ if (!scriptName) scriptName = getScriptName (bodyCode->code_string , funcPath, 32 );
1414+ // if (scriptName.empty()) scriptName = "<unknown>";
1415+
1416+ if (bodyCode->instructions .size () > 4 && scriptName && !scriptName->empty ())// && scriptName != "<unknown>"
1417+ addScopeInstruction (bodyCode->instructions , *scriptName);
1418+
1419+ return ;
1420+ }
1421+
1422+ virtual game_value compile (game_state& state, game_value_parameter code, bool final ) {
1423+ if (final ) return compileRedirectFinal (state, code);
1424+ return compileRedirect2 (state, code);
1425+ }
1426+
13921427};
13931428
13941429static ArmaScriptProfiler_ProfInterface profIface;
@@ -1397,4 +1432,6 @@ static ArmaScriptProfiler_ProfInterface profIface;
13971432void scriptProfiler::registerInterfaces () {
13981433 client::host::register_plugin_interface (" ArmaScriptProfilerProfIFace" sv, 1 , &profIface);
13991434 client::host::register_plugin_interface (" ArmaScriptProfilerProfIFace" sv, 2 , &profIface);
1435+ if (!getCommandLineParam (" -profilerNoInstrumentation" sv)) // Don't offer ourselves to ASM
1436+ client::host::register_plugin_interface (" ArmaScriptProfilerProfIFace" sv, 3 , &profIface);
14001437}
0 commit comments