diff --git a/easy_profiler_core/CMakeLists.txt b/easy_profiler_core/CMakeLists.txt index 0d7b694..15c9014 100644 --- a/easy_profiler_core/CMakeLists.txt +++ b/easy_profiler_core/CMakeLists.txt @@ -162,19 +162,26 @@ endif(WIN32) add_library(${LIB_NAME} SHARED ${SOURCES} resources.rc) -if (CMAKE_VERSION VERSION_LESS "3.1") +if (MINGW) + add_definitions( + -D_WIN32_WINNT=0x0600 + -DSTRSAFE_NO_DEPRECATE + ) + set (PLATFORM_LIBS ${PLATFORM_LIBS} ws2_32 psapi) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +elseif (CMAKE_VERSION VERSION_LESS "3.1") if (UNIX OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set (CMAKE_CXX_FLAGS "-std=gnu++11 ${CMAKE_CXX_FLAGS}") + set (CMAKE_CXX_FLAGS "-std=gnu++11 ${CMAKE_CXX_FLAGS}") endif (UNIX OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") else () set_target_properties(${LIB_NAME} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON ) -endif (CMAKE_VERSION VERSION_LESS "3.1") +endif (MINGW) if(UNIX) - set(PLATFORM_LIBS pthread) + set(PLATFORM_LIBS ${PLATFORM_LIBS} pthread) endif(UNIX) target_link_libraries(${LIB_NAME} ${PLATFORM_LIBS}) diff --git a/easy_profiler_core/event_trace_win.cpp b/easy_profiler_core/event_trace_win.cpp index f12aaaa..663634d 100644 --- a/easy_profiler_core/event_trace_win.cpp +++ b/easy_profiler_core/event_trace_win.cpp @@ -56,6 +56,8 @@ #include "event_trace_win.h" #include +#include +//#include #if EASY_OPTION_LOG_ENABLED != 0 # include @@ -112,10 +114,11 @@ extern const ::profiler::color_t EASY_COLOR_INTERNAL_EVENT; -#ifdef _MSC_VER -::std::atomic_uint64_t TRACING_END_TIME = ATOMIC_VAR_INIT(~0ULL); -#else +#ifdef __MINGW32__ ::std::atomic TRACING_END_TIME = ATOMIC_VAR_INIT(~0ULL); +char KERNEL_LOGGER[] = KERNEL_LOGGER_NAME; +#else +::std::atomic_uint64_t TRACING_END_TIME = ATOMIC_VAR_INIT(~0ULL); #endif namespace profiler { @@ -451,7 +454,11 @@ namespace profiler { return res; memset(&m_trace, 0, sizeof(m_trace)); +#ifdef __MINGW32__ + m_trace.LoggerName = KERNEL_LOGGER; +#else m_trace.LoggerName = KERNEL_LOGGER_NAME; +#endif m_trace.ProcessTraceMode = PROCESS_TRACE_MODE_REAL_TIME | PROCESS_TRACE_MODE_EVENT_RECORD | PROCESS_TRACE_MODE_RAW_TIMESTAMP; m_trace.EventRecordCallback = ::profiler::processTraceEvent; @@ -471,15 +478,14 @@ namespace profiler { https://msdn.microsoft.com/en-us/library/windows/desktop/aa364093(v=vs.85).aspx */ - m_processThread = ::std::move(::std::thread([this]() + m_processThread = ::std::thread([this](bool _lowPriority) { + if (_lowPriority) // Set low priority for event tracing thread + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST); EASY_THREAD_SCOPE("EasyProfiler.ETW"); ProcessTrace(&m_openedHandle, 1, 0, 0); - })); - // Set low priority for event tracing thread - if (m_lowPriority.load(::std::memory_order_acquire)) - SetThreadPriority(m_processThread.native_handle(), THREAD_PRIORITY_LOWEST); + }, m_lowPriority.load(::std::memory_order_acquire)); m_bEnabled = true; diff --git a/easy_profiler_core/event_trace_win.h b/easy_profiler_core/event_trace_win.h index 8c11b8e..fcce6b2 100644 --- a/easy_profiler_core/event_trace_win.h +++ b/easy_profiler_core/event_trace_win.h @@ -50,7 +50,6 @@ #define INITGUID // This is to enable using SystemTraceControlGuid in evntrace.h. #include #include -#include #include #include #include diff --git a/profiler_gui/CMakeLists.txt b/profiler_gui/CMakeLists.txt index 5db6431..24a126b 100644 --- a/profiler_gui/CMakeLists.txt +++ b/profiler_gui/CMakeLists.txt @@ -58,19 +58,26 @@ add_executable(${PROJECT_NAME} resources.rc ) -if (CMAKE_VERSION VERSION_LESS "3.1") +if (MINGW) + add_definitions( + -D_WIN32_WINNT=0x0600 + -DSTRSAFE_NO_DEPRECATE + ) + set (SPECIAL_LIB ${SPECIAL_LIB} ws2_32 psapi) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +elseif (CMAKE_VERSION VERSION_LESS "3.1") if (UNIX OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set (CMAKE_CXX_FLAGS "-std=gnu++11 ${CMAKE_CXX_FLAGS}") + set (CMAKE_CXX_FLAGS "-std=gnu++11 ${CMAKE_CXX_FLAGS}") endif (UNIX OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") else () set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON ) -endif (CMAKE_VERSION VERSION_LESS "3.1") +endif (MINGW) if(UNIX) - set(SPECIAL_LIB pthread) + set(SPECIAL_LIB ${SPECIAL_LIB} pthread) endif(UNIX) target_link_libraries(${PROJECT_NAME} Qt5::Widgets easy_profiler ${SPECIAL_LIB}) diff --git a/profiler_gui/blocks_tree_widget.cpp b/profiler_gui/blocks_tree_widget.cpp index 8d74470..ae28c4a 100644 --- a/profiler_gui/blocks_tree_widget.cpp +++ b/profiler_gui/blocks_tree_widget.cpp @@ -72,6 +72,7 @@ #ifdef _WIN32 #include +#include #endif #ifdef max @@ -428,14 +429,16 @@ void EasyTreeWidget::clearSilent(bool _global) for (int i = topLevelItemCount() - 1; i >= 0; --i) topLevelItems.push_back(takeTopLevelItem(i)); - auto deleter_thread = ::std::thread([](decltype(topLevelItems) _items) { + auto deleter_thread = ::std::thread([](decltype(topLevelItems) _items) + { +#ifdef _WIN32 + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST); +#endif + for (auto item : _items) delete item; - }, ::std::move(topLevelItems)); -#ifdef _WIN32 - SetThreadPriority(deleter_thread.native_handle(), THREAD_PRIORITY_LOWEST); -#endif + }, ::std::move(topLevelItems)); deleter_thread.detach(); diff --git a/profiler_gui/descriptors_tree_widget.cpp b/profiler_gui/descriptors_tree_widget.cpp index 737665a..bb41f88 100644 --- a/profiler_gui/descriptors_tree_widget.cpp +++ b/profiler_gui/descriptors_tree_widget.cpp @@ -64,6 +64,7 @@ #ifdef _WIN32 #include +#include #endif #ifdef max @@ -333,14 +334,16 @@ void EasyDescTreeWidget::clearSilent(bool _global) topLevelItems.push_back(item); } - auto deleter_thread = ::std::thread([](decltype(topLevelItems) _items) { + auto deleter_thread = ::std::thread([](decltype(topLevelItems) _items) + { +#ifdef _WIN32 + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST); +#endif + for (auto item : _items) delete item; - }, ::std::move(topLevelItems)); -#ifdef _WIN32 - SetThreadPriority(deleter_thread.native_handle(), THREAD_PRIORITY_LOWEST); -#endif + }, ::std::move(topLevelItems)); deleter_thread.detach(); diff --git a/profiler_gui/tree_widget_loader.cpp b/profiler_gui/tree_widget_loader.cpp index 774db24..b830267 100644 --- a/profiler_gui/tree_widget_loader.cpp +++ b/profiler_gui/tree_widget_loader.cpp @@ -50,6 +50,7 @@ #ifdef _WIN32 #include +#include #endif #ifdef max @@ -131,14 +132,16 @@ void EasyTreeWidgetLoader::interrupt(bool _wait) if (!_wait) { - auto deleter_thread = ::std::thread([](decltype(m_topLevelItems) _items) { + auto deleter_thread = ::std::thread([](decltype(m_topLevelItems) _items) + { +#ifdef _WIN32 + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST); +#endif + for (auto item : _items) delete item.second; - }, ::std::move(m_topLevelItems)); -#ifdef _WIN32 - SetThreadPriority(deleter_thread.native_handle(), THREAD_PRIORITY_LOWEST); -#endif + }, ::std::move(m_topLevelItems)); deleter_thread.detach(); } diff --git a/reader/CMakeLists.txt b/reader/CMakeLists.txt index d25ff8d..b362a98 100644 --- a/reader/CMakeLists.txt +++ b/reader/CMakeLists.txt @@ -10,8 +10,12 @@ set(SOURCES add_executable(${PROJECT_NAME} ${SOURCES}) +if(MINGW OR UNIX) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") +endif(MINGW OR UNIX) + if(UNIX) - set(SPEC_LIB pthread) + set(SPEC_LIB ${SPEC_LIB} pthread) endif(UNIX) target_link_libraries(${PROJECT_NAME} easy_profiler ${SPEC_LIB}) diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt index fdc7fa8..eb0257d 100644 --- a/sample/CMakeLists.txt +++ b/sample/CMakeLists.txt @@ -21,22 +21,35 @@ set(DISABLED_PROFILER_NAME ) add_executable(${DISABLED_PROFILER_NAME} ${SOURCES}) +if (MINGW) + + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + +elseif (CMAKE_VERSION VERSION_LESS "3.1") + + if (UNIX OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") + endif (UNIX OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + +else () + + set_target_properties(${PROJECT_NAME} PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED ON + ) + + set_target_properties(${DISABLED_PROFILER_NAME} PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED ON + ) + +endif (MINGW) + if(UNIX) - set(SPEC_LIB pthread) + set(SPEC_LIB ${SPEC_LIB} pthread) endif(UNIX) target_link_libraries(${PROJECT_NAME} easy_profiler ${SPEC_LIB}) target_link_libraries(${DISABLED_PROFILER_NAME} easy_profiler ${SPEC_LIB}) -if (CMAKE_VERSION VERSION_LESS "3.1") - if (UNIX OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") - endif (UNIX OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") -else () - set_target_properties(${PROJECT_NAME} PROPERTIES - CXX_STANDARD 11 - CXX_STANDARD_REQUIRED ON - ) -endif (CMAKE_VERSION VERSION_LESS "3.1") - target_compile_definitions(${PROJECT_NAME} PRIVATE BUILD_WITH_EASY_PROFILER)