Skip to content

Commit

Permalink
Update for Arma v1.90
Browse files Browse the repository at this point in the history
  • Loading branch information
dedmen committed Mar 6, 2019
1 parent 361f830 commit 30410ac
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 54 deletions.
9 changes: 2 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand All @@ -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()
Expand Down
22 changes: 11 additions & 11 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -86,7 +86,7 @@ if(CMAKE_COMPILER_IS_GNUCXX)
target_compile_options(
${INTERCEPT_PLUGIN_NAME} PRIVATE
"-std=c++1z"
"$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:-O3>"
"$<$<CONFIG:Release>:-O3>"
"-s"
"-fPIC"
"-fpermissive"
Expand All @@ -96,13 +96,13 @@ if(CMAKE_COMPILER_IS_GNUCXX)
"-m32"
"-Wno-ignored-attributes"
"-static"
"$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:-ffunction-sections>"
"$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:-fdata-sections>"
"$<$<CONFIG:Release>:-ffunction-sections>"
"$<$<CONFIG:Release>:-fdata-sections>"

)
target_link_options(${INTERCEPT_PLUGIN_NAME} PRIVATE "-m32" "-fPIC" "-static" "-static-libgcc" "-static-libstdc++"
"$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:-Wl,--gc-sections>"
"$<$<OR:$<CONFIG:Release>>:-Wl,--strip-all>"
"$<$<CONFIG:Release>:-Wl,--gc-sections>"
"$<$<CONFIG:Release>:-Wl,--strip-all>"
)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")

Expand All @@ -112,11 +112,11 @@ else()
target_compile_options(
${INTERCEPT_PLUGIN_NAME} PRIVATE
"/MP" "/Zi"
"$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:/MT>"
"$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:/Ox>"
"$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:/Ob2>"
"$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:/Oi>"
"$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:/Ot>"
"$<$<CONFIG:Release>:/MT>"
"$<$<CONFIG:Release>:/Ox>"
"$<$<CONFIG:Release>:/Ob2>"
"$<$<CONFIG:Release>:/Oi>"
"$<$<CONFIG:Release>:/Ot>"
)
target_link_options(${INTERCEPT_PLUGIN_NAME} PRIVATE "/OPT:REF" "/OPT:ICF" "/DEBUG:FULL")
endif()
Expand Down
22 changes: 11 additions & 11 deletions src/EngineProfiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<compact_array<ref<game_instruction>>>& bodyCode, const r_string& scriptName);
void addScopeInstruction(auto_array<ref<game_instruction>>& bodyCode, const r_string& scriptName);


extern "C" {
Expand All @@ -47,14 +47,14 @@ extern "C" {
void compileCacheIns();

void insertCompileCache(uintptr_t code, sourcedocpos& sdp) {

auto x = reinterpret_cast<ref<compact_array<ref<game_instruction>>>*>(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 != "<unknown>"sv)
addScopeInstruction(*x, name);
//broken
//auto x = reinterpret_cast<ref<compact_array<ref<game_instruction>>>*>(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 != "<unknown>"sv)
// addScopeInstruction(x, name);
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -210,7 +210,7 @@ void EngineProfiling::init() {
hooks.placeHook(hookTypes::shouldTime, pat_shouldTime, reinterpret_cast<uintptr_t>(shouldTime), shouldTimeJmpback, 0);
hooks.placeHook(hookTypes::frameEnd, pat_frameEnd, reinterpret_cast<uintptr_t>(frameEnd), frameEndJmpback, 0);
#ifndef __linux__
hooks.placeHook(hookTypes::compileCacheIns, pat_compileCacheIns, reinterpret_cast<uintptr_t>(compileCacheIns), compileCacheInsJmpback, 0);
//hooks.placeHook(hookTypes::compileCacheIns, pat_compileCacheIns, reinterpret_cast<uintptr_t>(compileCacheIns), compileCacheInsJmpback, 0);
#endif
#ifdef __linux__
auto found = hooks.findPattern(pat_doEnd, 0);
Expand Down
40 changes: 17 additions & 23 deletions src/scriptProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,57 +557,51 @@ class GameInstructionConst : public game_instruction {
r_string get_name() const override { return ""sv; }
};

void addScopeInstruction(ref<compact_array<ref<game_instruction>>>& bodyCode, const r_string& scriptName) {
void addScopeInstruction(auto_array<ref<game_instruction>>& 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<GameInstructionProfileScopeStart> curElInstruction = rv_allocator<GameInstructionProfileScopeStart>::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 == "<unknown>")
//curElInstruction->eventDescription->source = src;


auto oldInstructions = bodyCode;
ref<compact_array<ref<game_instruction>>> newInstr = compact_array<ref<game_instruction>>::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<GameInstructionProfileScopeStart*>(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();
Expand All @@ -620,7 +614,7 @@ void addScopeInstruction(ref<compact_array<ref<game_instruction>>>& bodyCode, co
if (inst->value.type_enum() != game_data_type::CODE) continue;

auto bodyCodeNext = static_cast<game_data_code*>(inst->value.data.get());
if (bodyCodeNext->instructions && bodyCodeNext->instructions->size() > 20)
if (bodyCodeNext->instructions.size() > 20)
addScopeInstruction(bodyCodeNext->instructions, scriptName);
}
}
Expand Down Expand Up @@ -655,7 +649,7 @@ game_value compileRedirect2(game_state& state, game_value_parameter message) {

auto comp = sqf::compile(str);
auto bodyCode = static_cast<game_data_code*>(comp.data.get());
if (!bodyCode->instructions) {
if (bodyCode->instructions.empty()) {
GProfilerAdapter->leaveScope(tempData);
return comp;
}
Expand All @@ -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 = "<unknown>";

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

return comp;
Expand All @@ -694,7 +688,7 @@ game_value compileRedirectFinal(game_state& state, game_value_parameter message)

auto comp = sqf::compile_final(str);
auto bodyCode = static_cast<game_data_code*>(comp.data.get());
if (!bodyCode->instructions) {
if (bodyCode->instructions.empty()) {
GProfilerAdapter->leaveScope(tempData);
return comp;
}
Expand All @@ -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 = "<unknown>";

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

return comp;
Expand Down
2 changes: 1 addition & 1 deletion tracy
Submodule tracy updated from 455850 to 6c86db

0 comments on commit 30410ac

Please sign in to comment.