0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-26 16:11:02 +08:00

MinGW build fixes: Thanks to https://github.com/Nitrotoluol for help!

This commit is contained in:
Victor Zarubkin 2017-02-14 21:22:26 +03:00
parent d54ef45c3a
commit 6d3a4a0aed
9 changed files with 90 additions and 45 deletions

View File

@ -162,19 +162,26 @@ endif(WIN32)
add_library(${LIB_NAME} SHARED ${SOURCES} resources.rc) 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") 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") endif (UNIX OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
else () else ()
set_target_properties(${LIB_NAME} PROPERTIES set_target_properties(${LIB_NAME} PROPERTIES
CXX_STANDARD 11 CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON CXX_STANDARD_REQUIRED ON
) )
endif (CMAKE_VERSION VERSION_LESS "3.1") endif (MINGW)
if(UNIX) if(UNIX)
set(PLATFORM_LIBS pthread) set(PLATFORM_LIBS ${PLATFORM_LIBS} pthread)
endif(UNIX) endif(UNIX)
target_link_libraries(${LIB_NAME} ${PLATFORM_LIBS}) target_link_libraries(${LIB_NAME} ${PLATFORM_LIBS})

View File

@ -56,6 +56,8 @@
#include "event_trace_win.h" #include "event_trace_win.h"
#include <Psapi.h> #include <Psapi.h>
#include <processthreadsapi.h>
//#include <Shellapi.h>
#if EASY_OPTION_LOG_ENABLED != 0 #if EASY_OPTION_LOG_ENABLED != 0
# include <iostream> # include <iostream>
@ -112,10 +114,11 @@
extern const ::profiler::color_t EASY_COLOR_INTERNAL_EVENT; extern const ::profiler::color_t EASY_COLOR_INTERNAL_EVENT;
#ifdef _MSC_VER #ifdef __MINGW32__
::std::atomic_uint64_t TRACING_END_TIME = ATOMIC_VAR_INIT(~0ULL);
#else
::std::atomic<uint64_t> TRACING_END_TIME = ATOMIC_VAR_INIT(~0ULL); ::std::atomic<uint64_t> 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 #endif
namespace profiler { namespace profiler {
@ -451,7 +454,11 @@ namespace profiler {
return res; return res;
memset(&m_trace, 0, sizeof(m_trace)); memset(&m_trace, 0, sizeof(m_trace));
#ifdef __MINGW32__
m_trace.LoggerName = KERNEL_LOGGER;
#else
m_trace.LoggerName = KERNEL_LOGGER_NAME; 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.ProcessTraceMode = PROCESS_TRACE_MODE_REAL_TIME | PROCESS_TRACE_MODE_EVENT_RECORD | PROCESS_TRACE_MODE_RAW_TIMESTAMP;
m_trace.EventRecordCallback = ::profiler::processTraceEvent; 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 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"); EASY_THREAD_SCOPE("EasyProfiler.ETW");
ProcessTrace(&m_openedHandle, 1, 0, 0); ProcessTrace(&m_openedHandle, 1, 0, 0);
}));
// Set low priority for event tracing thread }, m_lowPriority.load(::std::memory_order_acquire));
if (m_lowPriority.load(::std::memory_order_acquire))
SetThreadPriority(m_processThread.native_handle(), THREAD_PRIORITY_LOWEST);
m_bEnabled = true; m_bEnabled = true;

View File

@ -50,7 +50,6 @@
#define INITGUID // This is to enable using SystemTraceControlGuid in evntrace.h. #define INITGUID // This is to enable using SystemTraceControlGuid in evntrace.h.
#include <Windows.h> #include <Windows.h>
#include <Strsafe.h> #include <Strsafe.h>
#include <Shellapi.h>
#include <wmistr.h> #include <wmistr.h>
#include <evntrace.h> #include <evntrace.h>
#include <evntcons.h> #include <evntcons.h>

View File

@ -58,19 +58,26 @@ add_executable(${PROJECT_NAME}
resources.rc 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") 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") endif (UNIX OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
else () else ()
set_target_properties(${PROJECT_NAME} PROPERTIES set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 11 CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON CXX_STANDARD_REQUIRED ON
) )
endif (CMAKE_VERSION VERSION_LESS "3.1") endif (MINGW)
if(UNIX) if(UNIX)
set(SPECIAL_LIB pthread) set(SPECIAL_LIB ${SPECIAL_LIB} pthread)
endif(UNIX) endif(UNIX)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets easy_profiler ${SPECIAL_LIB}) target_link_libraries(${PROJECT_NAME} Qt5::Widgets easy_profiler ${SPECIAL_LIB})

View File

@ -72,6 +72,7 @@
#ifdef _WIN32 #ifdef _WIN32
#include <Windows.h> #include <Windows.h>
#include <processthreadsapi.h>
#endif #endif
#ifdef max #ifdef max
@ -428,14 +429,16 @@ void EasyTreeWidget::clearSilent(bool _global)
for (int i = topLevelItemCount() - 1; i >= 0; --i) for (int i = topLevelItemCount() - 1; i >= 0; --i)
topLevelItems.push_back(takeTopLevelItem(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) for (auto item : _items)
delete item; delete item;
}, ::std::move(topLevelItems));
#ifdef _WIN32 }, ::std::move(topLevelItems));
SetThreadPriority(deleter_thread.native_handle(), THREAD_PRIORITY_LOWEST);
#endif
deleter_thread.detach(); deleter_thread.detach();

View File

@ -64,6 +64,7 @@
#ifdef _WIN32 #ifdef _WIN32
#include <Windows.h> #include <Windows.h>
#include <processthreadsapi.h>
#endif #endif
#ifdef max #ifdef max
@ -333,14 +334,16 @@ void EasyDescTreeWidget::clearSilent(bool _global)
topLevelItems.push_back(item); 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) for (auto item : _items)
delete item; delete item;
}, ::std::move(topLevelItems));
#ifdef _WIN32 }, ::std::move(topLevelItems));
SetThreadPriority(deleter_thread.native_handle(), THREAD_PRIORITY_LOWEST);
#endif
deleter_thread.detach(); deleter_thread.detach();

View File

@ -50,6 +50,7 @@
#ifdef _WIN32 #ifdef _WIN32
#include <Windows.h> #include <Windows.h>
#include <processthreadsapi.h>
#endif #endif
#ifdef max #ifdef max
@ -131,14 +132,16 @@ void EasyTreeWidgetLoader::interrupt(bool _wait)
if (!_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) for (auto item : _items)
delete item.second; delete item.second;
}, ::std::move(m_topLevelItems));
#ifdef _WIN32 }, ::std::move(m_topLevelItems));
SetThreadPriority(deleter_thread.native_handle(), THREAD_PRIORITY_LOWEST);
#endif
deleter_thread.detach(); deleter_thread.detach();
} }

View File

@ -10,8 +10,12 @@ set(SOURCES
add_executable(${PROJECT_NAME} ${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) if(UNIX)
set(SPEC_LIB pthread) set(SPEC_LIB ${SPEC_LIB} pthread)
endif(UNIX) endif(UNIX)
target_link_libraries(${PROJECT_NAME} easy_profiler ${SPEC_LIB}) target_link_libraries(${PROJECT_NAME} easy_profiler ${SPEC_LIB})

View File

@ -21,22 +21,35 @@ set(DISABLED_PROFILER_NAME
) )
add_executable(${DISABLED_PROFILER_NAME} ${SOURCES}) 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) if(UNIX)
set(SPEC_LIB pthread) set(SPEC_LIB ${SPEC_LIB} pthread)
endif(UNIX) endif(UNIX)
target_link_libraries(${PROJECT_NAME} easy_profiler ${SPEC_LIB}) target_link_libraries(${PROJECT_NAME} easy_profiler ${SPEC_LIB})
target_link_libraries(${DISABLED_PROFILER_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) target_compile_definitions(${PROJECT_NAME} PRIVATE BUILD_WITH_EASY_PROFILER)