diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d90337..d8129c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ endif() project (ArmaScriptProfiler CXX ASM_MASM) find_package (Threads) -option(USE_64BIT_BUILD "USE_64BIT_BUILD" OFF) +set(USE_64BIT_BUILD ${CMAKE_CL_64}) option(USE_STATIC_LINKING "USE_STATIC_LINKING" ON) option(WITH_BROFILER "WITH_BROFILER" OFF) option(WITH_CHROME "WITH_CHROME" OFF) @@ -18,10 +18,7 @@ else() set(INTERCEPT_LINK_TYPE "dynamic") endif() -if(MSVC AND CMAKE_CL_64) - set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest" ) - set( USE_64BIT_BUILD ON) -elseif(MSVC) +if(MSVC) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest" ) #elseif(MSVC) # message(FATAL_ERROR "ERROR: You need a C++17 compatible compiler") @@ -30,8 +27,6 @@ endif() message("GENERATOR USED: '${CMAKE_GENERATOR}'") message("COMPILER USED: '${CMAKE_CXX_COMPILER_ID}'") -set(CMAKE_CL_64 ${USE_64BIT_BUILD}) - if(USE_64BIT_BUILD) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/release/@ArmaScriptProfiler/intercept") else() diff --git a/intercept b/intercept index de0d688..c7f9d3b 160000 --- a/intercept +++ b/intercept @@ -1 +1 @@ -Subproject commit de0d688c027c49b294c96d9f179c236fe9a1c6c1 +Subproject commit c7f9d3b376f9fbb17c39a3f45788a16a76be7808 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 006a9a3..63ee4dc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -77,7 +77,7 @@ target_link_libraries(${INTERCEPT_PLUGIN_NAME} ${LINK_LIBS}) set_target_properties(${INTERCEPT_PLUGIN_NAME} PROPERTIES PREFIX "") set_target_properties(${INTERCEPT_PLUGIN_NAME} PROPERTIES FOLDER ArmaScriptProfiler) -message("${CONFIGURATION}") + if(CMAKE_COMPILER_IS_GNUCXX) set_source_files_properties(hooks.s PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp") add_compile_definitions(__linux__) @@ -86,7 +86,7 @@ if(CMAKE_COMPILER_IS_GNUCXX) target_compile_options( ${INTERCEPT_PLUGIN_NAME} PRIVATE "-std=c++1z" - "$<$,$>:-O3>" + "$<$:-O3>" "-s" "-fPIC" "-fpermissive" @@ -96,13 +96,13 @@ if(CMAKE_COMPILER_IS_GNUCXX) "-m32" "-Wno-ignored-attributes" "-static" - "$<$,$>:-ffunction-sections>" - "$<$,$>:-fdata-sections>" + "$<$:-ffunction-sections>" + "$<$:-fdata-sections>" ) target_link_options(${INTERCEPT_PLUGIN_NAME} PRIVATE "-m32" "-fPIC" "-static" "-static-libgcc" "-static-libstdc++" - "$<$,$>:-Wl,--gc-sections>" - "$<$>:-Wl,--strip-all>" + "$<$:-Wl,--gc-sections>" + "$<$:-Wl,--strip-all>" ) set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") @@ -112,11 +112,11 @@ else() target_compile_options( ${INTERCEPT_PLUGIN_NAME} PRIVATE "/MP" "/Zi" - "$<$,$>:/MT>" - "$<$,$>:/Ox>" - "$<$,$>:/Ob2>" - "$<$,$>:/Oi>" - "$<$,$>:/Ot>" + "$<$:/MT>" + "$<$:/Ox>" + "$<$:/Ob2>" + "$<$:/Oi>" + "$<$:/Ot>" ) target_link_options(${INTERCEPT_PLUGIN_NAME} PRIVATE "/OPT:REF" "/OPT:ICF" "/DEBUG:FULL") endif() diff --git a/src/EngineProfiling.cpp b/src/EngineProfiling.cpp index b813f73..01adfbf 100644 --- a/src/EngineProfiling.cpp +++ b/src/EngineProfiling.cpp @@ -30,7 +30,7 @@ bool checkMainThread = false; thread_local bool isMainThread = false; std::string getScriptName(const r_string& str, const r_string& filePath, uint32_t returnFirstLineIfNoName = 0); -void addScopeInstruction(ref>>& bodyCode, const r_string& scriptName); +void addScopeInstruction(auto_array>& bodyCode, const r_string& scriptName); extern "C" { @@ -47,14 +47,14 @@ extern "C" { void compileCacheIns(); void insertCompileCache(uintptr_t code, sourcedocpos& sdp) { - - auto x = reinterpret_cast>>*>(code); - - if (sdp.content.length() < 64 || !x || !*x || x->get()->size() < 16) return; - - r_string name(getScriptName(sdp.content, sdp.sourcefile, 32)); - if (!name.empty() && name != ""sv) - addScopeInstruction(*x, name); + //broken + //auto x = reinterpret_cast>>*>(code); + // + //if (sdp.content.length() < 64 || !x || !*x || x->get()->size() < 16) return; + // + //r_string name(getScriptName(sdp.content, sdp.sourcefile, 32)); + //if (!name.empty() && name != ""sv) + // addScopeInstruction(x, name); } } @@ -161,7 +161,7 @@ HookManager::Pattern pat_shouldTime{ }; #else - +//#FIXME HookManager::Pattern pat_compileCacheIns{ //1.88.145.302 profv1 013D40B3 "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx?xxx????xxxx????xxxxx????xxxxxxxxxxxxxxxxxxxxxxxxx????xxx?????xxxx?x????xxxxxxxxxxxxxxxxxxxxx????xxxxxxxxxxxxxxxxx"sv, "\x48\x89\x45\xB0\x8B\x43\x10\x89\x45\xB8\x48\x8B\x43\x18\x48\x85\xC0\x74\x03\xF0\xFF\x00\x48\x89\x45\xC0\x8B\x43\x20\x48\x8D\x54\x24\x00\x48\x8D\x0D\x00\x00\x00\x00\x89\x45\xC8\xE8\x00\x00\x00\x00\x48\x8D\x4D\xA8\xE8\x00\x00\x00\x00\x48\x8B\x4D\xA0\x48\x85\xC9\x74\x1C\x41\x8B\xC7\xF0\x0F\xC1\x01\xFF\xC8\x75\x09\x48\x8B\x4D\xA0\xE8\x00\x00\x00\x00\x48\xC7\x45\x00\x00\x00\x00\x00\x48\x8D\x4C\x24\x00\xE8\x00\x00\x00\x00\x4D\x85\xE4\x74\x1D\x41\x8B\xC7\xF0\x41\x0F\xC1\x04\x24\xFF\xC8\x75\x10\x48\x8B\x0D\x00\x00\x00\x00\x49\x8B\xD4\x48\x8B\x01\xFF\x50\x18\x4D\x85\xF6\x74\x1C\x41\x8B\xC7"sv @@ -210,7 +210,7 @@ void EngineProfiling::init() { hooks.placeHook(hookTypes::shouldTime, pat_shouldTime, reinterpret_cast(shouldTime), shouldTimeJmpback, 0); hooks.placeHook(hookTypes::frameEnd, pat_frameEnd, reinterpret_cast(frameEnd), frameEndJmpback, 0); #ifndef __linux__ - hooks.placeHook(hookTypes::compileCacheIns, pat_compileCacheIns, reinterpret_cast(compileCacheIns), compileCacheInsJmpback, 0); + //hooks.placeHook(hookTypes::compileCacheIns, pat_compileCacheIns, reinterpret_cast(compileCacheIns), compileCacheInsJmpback, 0); #endif #ifdef __linux__ auto found = hooks.findPattern(pat_doEnd, 0); diff --git a/src/scriptProfiler.cpp b/src/scriptProfiler.cpp index 9dae310..c45bc69 100644 --- a/src/scriptProfiler.cpp +++ b/src/scriptProfiler.cpp @@ -557,57 +557,51 @@ class GameInstructionConst : public game_instruction { r_string get_name() const override { return ""sv; } }; -void addScopeInstruction(ref>>& bodyCode, const r_string& scriptName) { +void addScopeInstruction(auto_array>& bodyCode, const r_string& scriptName) { #ifndef __linux__ #ifndef _WIN64 #error "no x64 hash codes yet" #endif #endif - if (!bodyCode) return; + if (bodyCode.empty()) return; - auto lt = typeid(bodyCode->data()[0]).hash_code(); + auto lt = typeid(bodyCode.data()[0]).hash_code(); auto rt = typeid(GameInstructionProfileScopeStart).hash_code(); if (lt == rt) return; - if (bodyCode->size() < 4) return; + if (bodyCode.size() < 4) return; - auto& funcPath = bodyCode->front()->sdp.sourcefile; + auto& funcPath = bodyCode.front()->sdp.sourcefile; //r_string src = getScriptFromFirstLine(bodyCode->instructions->front()->sdp, false); //Insert instruction to set _x ref curElInstruction = rv_allocator::create_single(scriptName); - curElInstruction->sdp = bodyCode->front()->sdp; + curElInstruction->sdp = bodyCode.front()->sdp; curElInstruction->scopeInfo = GProfilerAdapter->createScope(curElInstruction->name, funcPath.empty() ? curElInstruction->name : funcPath, curElInstruction->sdp.sourceline); //if (scriptName == "") //curElInstruction->eventDescription->source = src; - - auto oldInstructions = bodyCode; - ref>> newInstr = compact_array>::create(*oldInstructions, oldInstructions->size() + 1); - - std::copy(oldInstructions->begin(), oldInstructions->begin() + oldInstructions->size(), newInstr->begin() + 1); - newInstr->data()[0] = curElInstruction; - bodyCode = newInstr; - + //Add instruction at start + bodyCode.insert(bodyCode.begin(), curElInstruction); #ifdef __linux__ static const size_t ConstTypeIDHash = 600831349; #else static const size_t ConstTypeIDHash = 0x0a56f03038a03360ull; #endif - for (auto& it : *bodyCode) { + for (auto& it : bodyCode) { auto instC = dynamic_cast(it.get()); if (instC) { break; } - auto typeHash = typeid(*it.get()).hash_code(); + auto typeHash = typeid(it.get()).hash_code(); //linux //auto typeN = typeid(*it.get()).name(); @@ -620,7 +614,7 @@ void addScopeInstruction(ref>>& bodyCode, co if (inst->value.type_enum() != game_data_type::CODE) continue; auto bodyCodeNext = static_cast(inst->value.data.get()); - if (bodyCodeNext->instructions && bodyCodeNext->instructions->size() > 20) + if (bodyCodeNext->instructions.size() > 20) addScopeInstruction(bodyCodeNext->instructions, scriptName); } } @@ -655,7 +649,7 @@ game_value compileRedirect2(game_state& state, game_value_parameter message) { auto comp = sqf::compile(str); auto bodyCode = static_cast(comp.data.get()); - if (!bodyCode->instructions) { + if (bodyCode->instructions.empty()) { GProfilerAdapter->leaveScope(tempData); return comp; } @@ -669,13 +663,13 @@ game_value compileRedirect2(game_state& state, game_value_parameter message) { GProfilerAdapter->leaveScope(tempData); - auto& funcPath = bodyCode->instructions->front()->sdp.sourcefile; + auto& funcPath = bodyCode->instructions.front()->sdp.sourcefile; //#TODO pass instructions to getScriptName and check if there is a "scriptName" or "scopeName" unary command call r_string scriptName(getScriptName(str, funcPath, 32)); //if (scriptName.empty()) scriptName = ""; - if (bodyCode->instructions&& bodyCode->instructions->size() > 4 && !scriptName.empty())// && scriptName != "" + if (bodyCode->instructions.size() > 4 && !scriptName.empty())// && scriptName != "" addScopeInstruction(bodyCode->instructions, scriptName); return comp; @@ -694,7 +688,7 @@ game_value compileRedirectFinal(game_state& state, game_value_parameter message) auto comp = sqf::compile_final(str); auto bodyCode = static_cast(comp.data.get()); - if (!bodyCode->instructions) { + if (bodyCode->instructions.empty()) { GProfilerAdapter->leaveScope(tempData); return comp; } @@ -708,14 +702,14 @@ game_value compileRedirectFinal(game_state& state, game_value_parameter message) GProfilerAdapter->leaveScope(tempData); - auto& funcPath = bodyCode->instructions->front()->sdp.sourcefile; + auto& funcPath = bodyCode->instructions.front()->sdp.sourcefile; auto scriptName = tryGetNameFromInitFunctions(state); if (!scriptName) scriptName = tryGetNameFromCBACompile(state); if (!scriptName) scriptName = getScriptName(str, funcPath, 32); //if (scriptName.empty()) scriptName = ""; - if (bodyCode->instructions&& bodyCode->instructions->size() > 4 && scriptName && !scriptName->empty())// && scriptName != "" + if (bodyCode->instructions.size() > 4 && scriptName && !scriptName->empty())// && scriptName != "" addScopeInstruction(bodyCode->instructions, *scriptName); return comp; diff --git a/tracy b/tracy index 4558508..6c86db8 160000 --- a/tracy +++ b/tracy @@ -1 +1 @@ -Subproject commit 455850868fce62260df207fd682e5ba921ee0e80 +Subproject commit 6c86db8965f6eea4985ce9425ab06f3eb3ca08d2