Skip to content

Commit

Permalink
Linux compatability
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
dedmen committed Jan 25, 2019
1 parent 07c858f commit aedf4be
Show file tree
Hide file tree
Showing 20 changed files with 306 additions and 176 deletions.
18 changes: 10 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
cmake_minimum_required (VERSION 3.6)
project (ArmaScriptProfiler)
cmake_minimum_required (VERSION 3.13)
project (ArmaScriptProfiler CXX ASM)

find_package (Threads)

option(USE_64BIT_BUILD "USE_64BIT_BUILD" OFF)
option(USE_STATIC_LINKING "USE_STATIC_LINKING" ON)
option(WITH_BROFILER "WITH_BROFILER" OFF)
option(WITH_CHROME "WITH_CHROME" OFF)

if(USE_STATIC_LINKING)
message("WARNING: Linking statically")
Expand All @@ -14,13 +16,13 @@ else()
set(INTERCEPT_LINK_TYPE "dynamic")
endif()

if("${CMAKE_GENERATOR}" MATCHES "Visual Studio 15 2017 Win64")
if(MSVC AND CMAKE_CL_64)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest" )
set( USE_64BIT_BUILD ON)
elseif("${CMAKE_GENERATOR}" MATCHES "Visual Studio 15 2017")
elseif(MSVC)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest" )
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
message(FATAL_ERROR "ERROR: You need a C++17 compatible compiler")
#elseif(MSVC)
# message(FATAL_ERROR "ERROR: You need a C++17 compatible compiler")
endif()

message("GENERATOR USED: '${CMAKE_GENERATOR}'")
Expand All @@ -29,9 +31,9 @@ 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}/build/win64/")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/release/@ArmaScriptProfiler/intercept")
else()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/build/win32/")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/release/@ArmaScriptProfiler/intercept")
endif()

set(CMAKE_CXX_STANDARD 17)
Expand Down
13 changes: 4 additions & 9 deletions src/AdapterArmaDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@
#include "scriptProfiler.hpp"
#include <numeric>

extern scriptProfiler profiler;

AdapterArmaDiag::AdapterArmaDiag() {
frames.resize(framesToGo + 1);
type = AdapterType::ArmaDiag;
}


AdapterArmaDiag::~AdapterArmaDiag() {}

std::shared_ptr<ScopeInfo> AdapterArmaDiag::createScope(intercept::types::r_string name,
intercept::types::r_string filename, uint32_t fileline) {

Expand Down Expand Up @@ -132,7 +127,7 @@ void AdapterArmaDiag::addLog(intercept::types::r_string message) {

}

void AdapterArmaDiag::iterateElementTree(const frameData& frame, std::function<void(profileElement*, size_t)> func) {
void AdapterArmaDiag::iterateElementTree(const frameData& frame, const std::function<void(profileElement*, size_t)>& func) {
//https://stackoverflow.com/a/5988138
for (auto& element : frame.elements) {
profileElement* node = element.get();
Expand Down Expand Up @@ -163,7 +158,7 @@ intercept::types::r_string AdapterArmaDiag::dumpLog() {
if (frames.size() == 1 && frames[currentFrame].elements.empty() || frames[currentFrame].scopes.empty()) return intercept::types::r_string();
std::stringstream output;
auto baseTimeReference = frameStart;
chrono::milliseconds totalRuntime = std::chrono::duration_cast<chrono::milliseconds>(std::chrono::high_resolution_clock::now() - baseTimeReference);
auto totalRuntime = std::chrono::duration_cast<chrono::milliseconds>(std::chrono::high_resolution_clock::now() - baseTimeReference);
output.precision(4);
output << "* THREAD! YEAH!\n";
output << std::fixed << "total; " << 0.0 << "; " << totalRuntime.count() << ";\"Frame " << intercept::sqf::diag_frameno() << "\"\n";
Expand All @@ -173,7 +168,7 @@ intercept::types::r_string AdapterArmaDiag::dumpLog() {
for (size_t i = 0; i < depth; ++i) {
output << " ";
}
chrono::milliseconds startTime = std::chrono::duration_cast<chrono::milliseconds>(element->getStartTime() - baseTimeReference);
auto startTime = std::chrono::duration_cast<chrono::milliseconds>(element->getStartTime() - baseTimeReference);
switch (element->type) {

case profileElementType::scope:
Expand All @@ -191,7 +186,7 @@ intercept::types::r_string AdapterArmaDiag::dumpLog() {
};


for (int i = 0; i < frames.size(); ++i) {
for (auto i = 0u; i < frames.size(); ++i) {
output << "* Frame " << i << "\n";
iterateElementTree(frames[i], iterateFunc);
}
Expand Down
12 changes: 6 additions & 6 deletions src/AdapterArmaDiag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ScopeInfoArmaDiag final : public ScopeInfo {

class ScopeTempStorageArmaDiag final : public ScopeTempStorage {
public:
uint64_t scopeID;
uint64_t scopeID = -1;
std::chrono::high_resolution_clock::time_point startTime;
};

Expand All @@ -36,7 +36,7 @@ class profileElement {
std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();
profileElement(profileElementType _type) : type(_type) {}

virtual ~profileElement() {}
virtual ~profileElement() = default;
virtual intercept::types::r_string getAsString() = 0;

virtual std::chrono::high_resolution_clock::time_point getStartTime() { return start; }
Expand All @@ -46,7 +46,7 @@ class profileElement {

class profileScope : public profileElement {
public:
~profileScope() override {};
~profileScope() override = default;
explicit profileScope(uint64_t _scopeID) : profileElement(profileElementType::scope), scopeID(_scopeID) {}
intercept::types::r_string getAsString() override { return info->name; };
std::chrono::microseconds getRunTime() override { return runtime; }
Expand All @@ -58,7 +58,7 @@ class profileScope : public profileElement {
class profileLog : public profileElement {
public:
explicit profileLog(intercept::types::r_string&& _message) : profileElement(profileElementType::log), message(_message) {}
~profileLog() override {};
~profileLog() override = default;
intercept::types::r_string getAsString() override { return message; }
std::chrono::microseconds getRunTime() override { return std::chrono::microseconds(0); }
intercept::types::r_string message;
Expand All @@ -75,7 +75,7 @@ class AdapterArmaDiag final : public ProfilerAdapter
{
public:
AdapterArmaDiag();
virtual ~AdapterArmaDiag();
virtual ~AdapterArmaDiag() = default;

std::shared_ptr<ScopeInfo> createScope(intercept::types::r_string name, intercept::types::r_string filename, uint32_t fileline) override;

Expand Down Expand Up @@ -123,7 +123,7 @@ class AdapterArmaDiag final : public ProfilerAdapter
std::chrono::high_resolution_clock::time_point frameStart;
uint32_t framesToGo = 0;

void iterateElementTree(const frameData& frame, std::function<void(profileElement*, size_t)> func);
static void iterateElementTree(const frameData& frame, const std::function<void(profileElement*, size_t)>& func);

};

3 changes: 2 additions & 1 deletion src/AdapterBrofiler.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "ProfilerAdapter.hpp"

#ifdef WITH_BROFILER

namespace Brofiler {
struct EventData;
Expand Down Expand Up @@ -38,3 +38,4 @@ class AdapterBrofiler final : public ProfilerAdapter
Brofiler::EventData* frameEvent = nullptr;
};

#endif
5 changes: 0 additions & 5 deletions src/AdapterChrome.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include "AdapterChrome.hpp"
#include <iostream>

#include <fstream>

void printClean(std::ofstream& str, intercept::types::r_string string) {
Expand Down Expand Up @@ -45,9 +43,6 @@ AdapterChrome::AdapterChrome() {
type = AdapterType::Chrome;
}


AdapterChrome::~AdapterChrome() {}

void AdapterChrome::perFrame() {}

std::shared_ptr<ScopeInfo> AdapterChrome::createScope(intercept::types::r_string name,
Expand Down
6 changes: 4 additions & 2 deletions src/AdapterChrome.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#ifdef WITH_CHROME
#include "ProfilerAdapter.hpp"
#include <filesystem>

Expand All @@ -11,7 +12,7 @@ class ScopeInfoChrome final: public ScopeInfo {
public:
intercept::types::r_string name;
intercept::types::r_string file;
uint32_t line;
uint32_t line = 0;
};

enum class ChromeEventCategory {
Expand Down Expand Up @@ -54,7 +55,7 @@ class AdapterChrome final : public ProfilerAdapter
{
public:
AdapterChrome();
~AdapterChrome();
~AdapterChrome() = default;
void perFrame() override;
std::shared_ptr<ScopeInfo> createScope(intercept::types::r_string name, intercept::types::r_string filename,
uint32_t fileline) override;
Expand All @@ -73,3 +74,4 @@ class AdapterChrome final : public ProfilerAdapter
std::vector<ChromeEvent> storedEvents;
};

#endif
4 changes: 2 additions & 2 deletions src/AdapterTracy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ std::shared_ptr<ScopeInfo> AdapterTracy::createScope(intercept::types::r_string
auto info = std::make_shared<ScopeInfoTracy>();
info->info = tracy::SourceLocationData{nullptr, std::get<0>(tuple).c_str(), std::get<1>(tuple).c_str(), std::get<2>(tuple), 0};

auto res = scopeCache.insert({tuple, info});
scopeCache.insert({tuple, info});
return info;
}
return found->second;
Expand Down Expand Up @@ -79,7 +79,7 @@ void AdapterTracy::setCounter(intercept::types::r_string name, float val) {
tracy::Profiler::PlotData(name.c_str(), val);
}

std::shared_ptr<ScopeInfo> AdapterTracy::createScopeStatic(const char* name, const char* filename, uint32_t fileline) {
std::shared_ptr<ScopeInfo> AdapterTracy::createScopeStatic(const char* name, const char* filename, uint32_t fileline) const {
auto info = std::make_shared<ScopeInfoTracy>();
info->info = tracy::SourceLocationData{nullptr, name, filename,fileline, 0};
return info;
Expand Down
6 changes: 3 additions & 3 deletions src/AdapterTracy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class AdapterTracy final : public ProfilerAdapter
void addLog(intercept::types::r_string message) override;
void setCounter(intercept::types::r_string name, float val) override;

std::shared_ptr<ScopeInfo> createScopeStatic(const char* name, const char* filename, uint32_t fileline);
bool isConnected();
std::shared_ptr<ScopeInfo> createScopeStatic(const char* name, const char* filename, uint32_t fileline) const;
static bool isConnected();

private:
void ensureReady();
static void ensureReady();
using scopeCacheKey = std::tuple<intercept::types::r_string, intercept::types::r_string,uint32_t>;

struct ScopeCacheFastEqual {
Expand Down
4 changes: 3 additions & 1 deletion src/ArmaScriptProfiler.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@
<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" />
<ClCompile Include="AdapterBrofiler.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="AdapterChrome.cpp" />
<ClCompile Include="AdapterTracy.cpp" />
<ClCompile Include="EngineProfiling.cpp" />
Expand Down
102 changes: 80 additions & 22 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.0)
cmake_minimum_required (VERSION 3.13)

set(INTERCEPT_CLIENT_PATH "${CMAKE_SOURCE_DIR}/intercept/src/client")
set(BROFILER_BASE_PATH "${CMAKE_SOURCE_DIR}/brofiler")
Expand All @@ -22,31 +22,64 @@ add_definitions(/D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS) #No I don't cheat!

#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/rv/${INTERCEPT_PLUGIN_NAME}/intercept")

file(GLOB_RECURSE INTERCEPT_ASP_SOURCES *.h *.hpp *.c *.cpp)
file(GLOB_RECURSE INTERCEPT_ASP_SOURCES *.h *.hpp *.c *.cpp *.asm *.s)
SOURCE_GROUP("src" FILES ${INTERCEPT_ASP_SOURCES})

file(GLOB INTERCEPT_SOURCES "${INTERCEPT_CLIENT_PATH}/intercept/client/*.cpp" "${INTERCEPT_CLIENT_PATH}/intercept/client/sqf/*.cpp" "${INTERCEPT_CLIENT_PATH}/intercept/shared/*.cpp")
SOURCE_GROUP("intercept" FILES ${INTERCEPT_SOURCES})

file(GLOB BROFILER_SOURCES
"${BROFILER_BASE_PATH}/ThirdParty/TaskScheduler/Scheduler/Source/"
#"${BROFILER_BASE_PATH}/BrofilerCore/CallstackCollector.cpp"
#"${BROFILER_BASE_PATH}/BrofilerCore/Core.cpp"
#"${BROFILER_BASE_PATH}/BrofilerCore/Event.cpp"
#"${BROFILER_BASE_PATH}/BrofilerCore/EventDescriptionBoard.cpp"
#"${BROFILER_BASE_PATH}/BrofilerCore/Message.cpp"
#"${BROFILER_BASE_PATH}/BrofilerCore/ProfilerServer.cpp"
#"${BROFILER_BASE_PATH}/BrofilerCore/Serialization.cpp"
#"${BROFILER_BASE_PATH}/BrofilerCore/SysCallCollector.cpp"
"${BROFILER_BASE_PATH}/BrofilerCore/*.cpp"
"${BROFILER_BASE_PATH}/BrofilerCore/Platform/*.cpp"
)
SOURCE_GROUP("src/brofiler" FILES ${BROFILER_SOURCES})
if (WITH_BROFILER)
add_compile_definitions(WITH_BROFILER)
file(GLOB BROFILER_SOURCES
"${BROFILER_BASE_PATH}/ThirdParty/TaskScheduler/Scheduler/Source/"
#"${BROFILER_BASE_PATH}/BrofilerCore/CallstackCollector.cpp"
#"${BROFILER_BASE_PATH}/BrofilerCore/Core.cpp"
#"${BROFILER_BASE_PATH}/BrofilerCore/Event.cpp"
#"${BROFILER_BASE_PATH}/BrofilerCore/EventDescriptionBoard.cpp"
#"${BROFILER_BASE_PATH}/BrofilerCore/Message.cpp"
#"${BROFILER_BASE_PATH}/BrofilerCore/ProfilerServer.cpp"
#"${BROFILER_BASE_PATH}/BrofilerCore/Serialization.cpp"
#"${BROFILER_BASE_PATH}/BrofilerCore/SysCallCollector.cpp"
"${BROFILER_BASE_PATH}/BrofilerCore/*.cpp"
"${BROFILER_BASE_PATH}/BrofilerCore/Platform/*.cpp"
"${BROFILER_BASE_PATH}/BrofilerCore/Platform/Windows/*.cpp"
)
SOURCE_GROUP("src/brofiler" FILES ${BROFILER_SOURCES})
else()
SET(BROFILER_SOURCES "")
list(REMOVE_ITEM INTERCEPT_ASP_SOURCES "${CMAKE_SOURCE_DIR}/src/AdapterBrofiler.cpp")
endif()

if (WITH_CHROME)
add_compile_definitions(WITH_CHROME)
else()
list(REMOVE_ITEM INTERCEPT_ASP_SOURCES "${CMAKE_SOURCE_DIR}/src/AdapterChrome.cpp")
endif()


if(CMAKE_COMPILER_IS_GNUCXX)
list(REMOVE_ITEM INTERCEPT_ASP_SOURCES "${CMAKE_SOURCE_DIR}/src/hooks.asm")
endif()

set(library_sources ${INTERCEPT_ASP_SOURCES})

add_library( ${INTERCEPT_PLUGIN_NAME} SHARED ${library_sources} ${INTERCEPT_SOURCES} ${BROFILER_SOURCES})



if (MSVC AND CMAKE_CL_64)
add_custom_command(TARGET ${INTERCEPT_PLUGIN_NAME}
PRE_BUILD
COMMAND "ml64" /c /W2 /nologo /errorReport:none /Zf
/Fo${CMAKE_BINARY_DIR}/src/CMakeFiles/ArmaScriptProfiler_x64.dir/hooks.asm.obj
#${CMAKE_PROJECT_NAME}.dir/Debug/
#/Fo"C:/MYPROJECT/Build/Main_ms100_64/MYPROJECT.dir/Debug/"
${CMAKE_SOURCE_DIR}/src/hooks.asm
COMMENT "Building asm file")
endif()



include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${INTERCEPT_INCLUDE_PATH} )
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${BROFILER_INCLUDE_PATH} )
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${TRACY_INCLUDE_PATH} )
Expand All @@ -58,15 +91,40 @@ target_link_libraries(${INTERCEPT_PLUGIN_NAME} ${LINK_LIBS})
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(CMAKE_CXX_FLAGS "-std=c++1z -O2 -s -fPIC -fpermissive -static-libgcc -static-libstdc++")#-march=i686 -m32
set_source_files_properties(hooks.s PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp")
add_compile_definitions(__linux__)
list(REMOVE_ITEM INTERCEPT_ASP_SOURCES "${CMAKE_SOURCE_DIR}/src/hooks.asm")

target_compile_options(
${INTERCEPT_PLUGIN_NAME} PRIVATE
"-std=c++1z"
"-O2"
"-s"
"-fPIC"
"-fpermissive"
"-static-libgcc"
"-static-libstdc++"
"-march=i686"
"-m32"
"-Wno-ignored-attributes"
"-static"
)
target_link_options(${INTERCEPT_PLUGIN_NAME} PRIVATE "-m32" "-fPIC" "-static" "-static-libgcc" "-static-libstdc++")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
set(CMAKE_SHARED_LINKER_FLAGS "-static -static-libgcc -static-libstdc++")
else()
set(CMAKE_CXX_FLAGS_DEBUG "/D _DEBUG /MTd /Zi /Ob0 /Od /RTC1 /MP /EHsc")
set(CMAKE_CXX_FLAGS_RELEASE "/MT /Zi /O2 /Ob1 /EHsc /MP") #with debug info
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "/OPT:REF /DEBUG:FULL")

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>"
)
target_link_options(${INTERCEPT_PLUGIN_NAME} PRIVATE "/OPT:REF" "/OPT:ICF" "/DEBUG:FULL")
endif()


Expand Down
Loading

0 comments on commit aedf4be

Please sign in to comment.