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

CMake + core: added options to CMakeLists.txt. TODO: maybe set them via CMake "option(...)" command

This commit is contained in:
Victor Zarubkin 2016-12-13 21:53:29 +03:00
parent b67e078e55
commit 7b63ae39d2
5 changed files with 175 additions and 62 deletions

View File

@ -4,6 +4,102 @@ IF (NOT DEFINED LIB_NAME)
SET(LIB_NAME ${PROJECT_NAME})
ENDIF()
if(NOT DEFINED EASY_PROGRAM_VERSION_MAJOR)
file (STRINGS ${CMAKE_CURRENT_LIST_DIR}/version.info EASY_PRODUCT_VERSION_STRING)
string(REPLACE "." ";" VERSION_LIST ${EASY_PRODUCT_VERSION_STRING})
list(GET VERSION_LIST 0 EASY_PROGRAM_VERSION_MAJOR)
list(GET VERSION_LIST 1 EASY_PROGRAM_VERSION_MINOR)
list(GET VERSION_LIST 2 EASY_PROGRAM_VERSION_PATCH)
# EasyProfiler version
add_definitions(
-DEASY_PROFILER_VERSION_MAJOR=${EASY_PROGRAM_VERSION_MAJOR}
-DEASY_PROFILER_VERSION_MINOR=${EASY_PROGRAM_VERSION_MINOR}
-DEASY_PROFILER_VERSION_PATCH=${EASY_PROGRAM_VERSION_PATCH}
)
# EasyProfiler version
set(EASY_PROGRAM_VERSION_MAJOR ${EASY_PROGRAM_VERSION_MAJOR} PARENT_SCOPE)
set(EASY_PROGRAM_VERSION_MINOR ${EASY_PROGRAM_VERSION_MINOR} PARENT_SCOPE)
set(EASY_PROGRAM_VERSION_PATCH ${EASY_PROGRAM_VERSION_PATCH} PARENT_SCOPE)
endif(NOT DEFINED EASY_PROGRAM_VERSION_MAJOR)
message(STATUS "")
message(STATUS "EASY_PROFILER.Core version = ${EASY_PROGRAM_VERSION_MAJOR}.${EASY_PROGRAM_VERSION_MINOR}.${EASY_PROGRAM_VERSION_PATCH}")
message(STATUS "")
# EasyProfiler options:----------------------------------------------
set(EASY_DEFAULT_PORT 28077) # default listening port
set(EASY_OPTION_LISTEN OFF) # enable automatic startListen on startup
set(EASY_OPTION_PROFILE_SELF OFF) # enable self profiling (measure time for internal storage expand)
set(EASY_OPTION_PROFILE_SELF_BLOCKS_ON OFF) # storage expand default status (profiler::ON or profiler::OFF)
set(EASY_OPTION_LOG OFF) # print errors to stderr
if(WIN32)
set(EASY_OPTION_EVENT_TRACING ON) # Enable event tracing by default
set(EASY_OPTION_LOW_PRIORITY_EVENT_TRACING ON) # Set low priority for event tracing thread
endif(WIN32)
MESSAGE(STATUS "EASY_PROFILER OPTIONS:--------------")
MESSAGE(STATUS " Default listening port\t\t= ${EASY_DEFAULT_PORT}")
MESSAGE(STATUS " Auto-start listening\t\t= ${EASY_OPTION_LISTEN}")
MESSAGE(STATUS " Profile self\t\t\t= ${EASY_OPTION_PROFILE_SELF}")
MESSAGE(STATUS " Profile self blocks initial status\t= ${EASY_OPTION_PROFILE_SELF_BLOCKS_ON}")
if(WIN32)
MESSAGE(STATUS " Event tracing\t\t\t= ${EASY_OPTION_EVENT_TRACING}")
if(EASY_OPTION_LOW_PRIORITY_EVENT_TRACING)
MESSAGE(STATUS " Event tracing has low priority\t= Yes")
else()
MESSAGE(STATUS " Event tracing has low priority\t= No")
endif(EASY_OPTION_LOW_PRIORITY_EVENT_TRACING)
endif(WIN32)
MESSAGE(STATUS " Print errors to stderr\t\t= ${EASY_OPTION_LOG}")
MESSAGE(STATUS "END EASY_PROFILER OPTIONS.----------")
MESSAGE(STATUS "")
# END EasyProfiler options.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
add_definitions(-DEASY_DEFAULT_PORT=${EASY_DEFAULT_PORT})
if(EASY_OPTION_LISTEN)
add_definitions(-DEASY_OPTION_START_LISTEN_ON_STARTUP=1)
else()
add_definitions(-DEASY_OPTION_START_LISTEN_ON_STARTUP=0)
endif(EASY_OPTION_LISTEN)
if(EASY_OPTION_PROFILE_SELF)
add_definitions(-DEASY_OPTION_MEASURE_STORAGE_EXPAND=1)
if(EASY_OPTION_PROFILE_SELF_BLOCKS_ON)
add_definitions(-DEASY_OPTION_STORAGE_EXPAND_BLOCKS_ON=true)
else()
add_definitions(-DEASY_OPTION_STORAGE_EXPAND_BLOCKS_ON=false)
endif(EASY_OPTION_PROFILE_SELF_BLOCKS_ON)
else()
add_definitions(-DEASY_OPTION_MEASURE_STORAGE_EXPAND=0)
endif(EASY_OPTION_PROFILE_SELF)
if(WIN32)
if(EASY_OPTION_EVENT_TRACING)
add_definitions(-DEASY_OPTION_EVENT_TRACING_ENABLED=true)
else()
add_definitions(-DEASY_OPTION_EVENT_TRACING_ENABLED=false)
endif(EASY_OPTION_EVENT_TRACING)
if(EASY_OPTION_LOW_PRIORITY_EVENT_TRACING)
add_definitions(-DEASY_OPTION_LOW_PRIORITY_EVENT_TRACING=true)
else()
add_definitions(-DEASY_OPTION_LOW_PRIORITY_EVENT_TRACING=false)
endif(EASY_OPTION_LOW_PRIORITY_EVENT_TRACING)
endif(WIN32)
if(EASY_OPTION_LOG)
add_definitions(-DEASY_OPTION_LOG_ENABLED=1)
else()
add_definitions(-DEASY_OPTION_LOG_ENABLED=0)
endif(EASY_OPTION_LOG)
set(CPP_FILES
block.cpp
profile_manager.cpp
@ -36,33 +132,6 @@ set(INCLUDE_FILES
)
source_group(include FILES ${INCLUDE_FILES})
if(NOT DEFINED EASY_PROGRAM_VERSION_MAJOR)
file (STRINGS ${CMAKE_CURRENT_LIST_DIR}/version.info EASY_PRODUCT_VERSION_STRING)
string(REPLACE "." ";" VERSION_LIST ${EASY_PRODUCT_VERSION_STRING})
list(GET VERSION_LIST 0 EASY_PROGRAM_VERSION_MAJOR)
list(GET VERSION_LIST 1 EASY_PROGRAM_VERSION_MINOR)
list(GET VERSION_LIST 2 EASY_PROGRAM_VERSION_PATCH)
message(STATUS "EASY_PROGRAM_VERSION_MAJOR: ${EASY_PROGRAM_VERSION_MAJOR}")
message(STATUS "EASY_PROGRAM_VERSION_MINOR: ${EASY_PROGRAM_VERSION_MINOR}")
message(STATUS "EASY_PROGRAM_VERSION_PATCH: ${EASY_PROGRAM_VERSION_PATCH}")
# EasyProfiler version
add_definitions(
-DEASY_PROFILER_VERSION_MAJOR=${EASY_PROGRAM_VERSION_MAJOR}
-DEASY_PROFILER_VERSION_MINOR=${EASY_PROGRAM_VERSION_MINOR}
-DEASY_PROFILER_VERSION_PATCH=${EASY_PROGRAM_VERSION_PATCH}
)
# EasyProfiler version
set(EASY_PROGRAM_VERSION_MAJOR ${EASY_PROGRAM_VERSION_MAJOR} PARENT_SCOPE)
set(EASY_PROGRAM_VERSION_MINOR ${EASY_PROGRAM_VERSION_MINOR} PARENT_SCOPE)
set(EASY_PROGRAM_VERSION_PATCH ${EASY_PROGRAM_VERSION_PATCH} PARENT_SCOPE)
endif(NOT DEFINED EASY_PROGRAM_VERSION_MAJOR)
set(SOURCES
${CPP_FILES}
${H_FILES}

View File

@ -57,7 +57,7 @@
#include "event_trace_win.h"
#include <Psapi.h>
#if EASY_LOG_ENABLED != 0
#if EASY_OPTION_LOG_ENABLED != 0
#include <iostream>
#endif
@ -229,7 +229,7 @@ namespace profiler {
EasyEventTracer::EasyEventTracer()
{
m_lowPriority = ATOMIC_VAR_INIT(EASY_LOW_PRIORITY_EVENT_TRACING);
m_lowPriority = ATOMIC_VAR_INIT(EASY_OPTION_LOW_PRIORITY_EVENT_TRACING);
}
EasyEventTracer::~EasyEventTracer()
@ -264,7 +264,7 @@ namespace profiler {
}
}
#if EASY_LOG_ENABLED != 0
#if EASY_OPTION_LOG_ENABLED != 0
if (!success)
::std::cerr << "Warning: EasyProfiler failed to set " << _privelegeName << " privelege for the application.\n";
#endif
@ -283,7 +283,7 @@ namespace profiler {
HANDLE hToken = nullptr;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
#if EASY_LOG_ENABLED != 0
#if EASY_OPTION_LOG_ENABLED != 0
const bool success = setPrivilege(hToken, SE_DEBUG_NAME);
if (!success)
::std::cerr << "Warning: Some context switch events could not get process name.\n";
@ -293,7 +293,7 @@ namespace profiler {
CloseHandle(hToken);
}
#if EASY_LOG_ENABLED != 0
#if EASY_OPTION_LOG_ENABLED != 0
else
{
::std::cerr << "Warning: EasyProfiler failed to open process to adjust priveleges.\n";
@ -348,26 +348,26 @@ namespace profiler {
}
}
#if EASY_LOG_ENABLED != 0
#if EASY_OPTION_LOG_ENABLED != 0
::std::cerr << "Error: EasyProfiler.ETW not launched: ERROR_ALREADY_EXISTS. To stop another session execute cmd: logman stop \"" << KERNEL_LOGGER_NAME << "\" -ets\n";
#endif
return EVENT_TRACING_WAS_LAUNCHED_BY_SOMEBODY_ELSE;
}
case ERROR_ACCESS_DENIED:
#if EASY_LOG_ENABLED != 0
#if EASY_OPTION_LOG_ENABLED != 0
::std::cerr << "Error: EasyProfiler.ETW not launched: ERROR_ACCESS_DENIED. Try to launch your application as Administrator.\n";
#endif
return EVENT_TRACING_NOT_ENOUGH_ACCESS_RIGHTS;
case ERROR_BAD_LENGTH:
#if EASY_LOG_ENABLED != 0
#if EASY_OPTION_LOG_ENABLED != 0
::std::cerr << "Error: EasyProfiler.ETW not launched: ERROR_BAD_LENGTH. It seems that your KERNEL_LOGGER_NAME differs from \"" << m_properties.sessionName << "\". Try to re-compile easy_profiler or contact EasyProfiler developers.\n";
#endif
return EVENT_TRACING_BAD_PROPERTIES_SIZE;
}
#if EASY_LOG_ENABLED != 0
#if EASY_OPTION_LOG_ENABLED != 0
::std::cerr << "Error: EasyProfiler.ETW not launched: StartTrace() returned " << startTraceResult << ::std::endl;
#endif
return EVENT_TRACING_MISTERIOUS_ERROR;
@ -408,7 +408,7 @@ namespace profiler {
m_openedHandle = OpenTrace(&m_trace);
if (m_openedHandle == INVALID_PROCESSTRACE_HANDLE)
{
#if EASY_LOG_ENABLED != 0
#if EASY_OPTION_LOG_ENABLED != 0
::std::cerr << "Error: EasyProfiler.ETW not launched: OpenTrace() returned invalid handle.\n";
#endif
return EVENT_TRACING_OPEN_TRACE_ERROR;

View File

@ -206,11 +206,11 @@ This is just for user's comfort. There is no difference for EasyProfiler GUI bet
/** Enable or disable event tracing (context switch events).
\note Default value is controlled by EASY_EVENT_TRACING_ENABLED macro.
\note Default value is controlled by EASY_OPTION_EVENT_TRACING_ENABLED macro.
\note Change will take effect on the next call to EASY_PROFILER_ENABLE.
\sa EASY_PROFILER_ENABLE, EASY_EVENT_TRACING_ENABLED
\sa EASY_PROFILER_ENABLE, EASY_OPTION_EVENT_TRACING_ENABLED
\ingroup profiler
*/
@ -227,7 +227,7 @@ Event tracing with normal priority could gather more information about processes
it could affect performance as it has more work to do. Usually you will not notice any performance
breakdown, but if you care about that then you change set event tracing priority level to low.
\sa EASY_LOW_PRIORITY_EVENT_TRACING
\sa EASY_OPTION_LOW_PRIORITY_EVENT_TRACING
\ingroup profiler
*/
@ -239,13 +239,13 @@ breakdown, but if you care about that then you change set event tracing priority
\ingroup profiler
*/
# define EASY_EVENT_TRACING_SET_LOG(filename) ::profiler::setContextSwitchLogFilename(filename);
# define EASY_EVENT_TRACING_SET_LOG(filename) ::profiler::setContextSwitchLogFilename(filename);
/** Macro returning current path to the temporary log-file for Unix event tracing system.
\ingroup profiler
*/
# define EASY_EVENT_TRACING_LOG ::profiler::getContextSwitchLogFilename();
# define EASY_EVENT_TRACING_LOG ::profiler::getContextSwitchLogFilename();
// EasyProfiler settings:
@ -257,15 +257,22 @@ These are "EasyProfiler.ExpandStorage" blocks on a diagram.
\ingroup profiler
*/
# define EASY_MEASURE_STORAGE_EXPAND 0
# ifndef EASY_OPTION_MEASURE_STORAGE_EXPAND
# define EASY_OPTION_MEASURE_STORAGE_EXPAND 0
# endif
/** If true then "EasyProfiler.ExpandStorage" events are enabled by default and will be
# if EASY_OPTION_MEASURE_STORAGE_EXPAND != 0
/** If true then "EasyProfiler.ExpandStorage" blocks are enabled by default and will be
writed to output file or translated over the net.
If false then you need to enable these events via GUI if you'll want to see them.
If false then you need to enable these blocks via GUI if you want to see them.
\ingroup profiler
*/
# define EASY_STORAGE_EXPAND_ENABLED true
# ifndef EASY_OPTION_STORAGE_EXPAND_BLOCKS_ON
# define EASY_OPTION_STORAGE_EXPAND_BLOCKS_ON true
# endif
# endif // EASY_OPTION_MEASURE_STORAGE_EXPAND != 0
/** If true then EasyProfiler event tracing is enabled by default
and will be turned on and off when you call profiler::setEnabled().
@ -274,7 +281,9 @@ turned on/off with next calls of profiler::setEnabled().
\ingroup profiler
*/
# define EASY_EVENT_TRACING_ENABLED true
# ifndef EASY_OPTION_EVENT_TRACING_ENABLED
# define EASY_OPTION_EVENT_TRACING_ENABLED true
# endif
/** If true then EasyProfiler.ETW thread (Event tracing for Windows) will have low priority by default.
@ -285,7 +294,9 @@ You don't need to rebuild or restart your application for that.
\ingroup profiler
*/
# define EASY_LOW_PRIORITY_EVENT_TRACING true
# ifndef EASY_OPTION_LOW_PRIORITY_EVENT_TRACING
# define EASY_OPTION_LOW_PRIORITY_EVENT_TRACING true
# endif
/** If != 0 then EasyProfiler will print error messages into stderr.
@ -293,8 +304,19 @@ Otherwise, no log messages will be printed.
\ingroup profiler
*/
# define EASY_LOG_ENABLED 0
# ifndef EASY_OPTION_LOG_ENABLED
# define EASY_OPTION_LOG_ENABLED 0
# endif
/** If != 0 then EasyProfiler will start listening thread immidiately on ProfileManager initialization.
\sa startListen
\ingroup profiler
*/
# ifndef EASY_OPTION_START_LISTEN_ON_STARTUP
# define EASY_OPTION_START_LISTEN_ON_STARTUP 0
# endif
#else // #ifdef BUILD_WITH_EASY_PROFILER
@ -315,14 +337,32 @@ Otherwise, no log messages will be printed.
# define EASY_EVENT_TRACING_LOG ""
# endif
# define EASY_MEASURE_STORAGE_EXPAND 0
# define EASY_STORAGE_EXPAND_ENABLED false
# define EASY_EVENT_TRACING_ENABLED false
# define EASY_LOW_PRIORITY_EVENT_TRACING true
# define EASY_LOG_ENABLED 0
# ifndef EASY_OPTION_MEASURE_STORAGE_EXPAND
# define EASY_OPTION_MEASURE_STORAGE_EXPAND 0
# endif
# ifndef EASY_OPTION_EVENT_TRACING_ENABLED
# define EASY_OPTION_EVENT_TRACING_ENABLED false
# endif
# ifndef EASY_OPTION_LOW_PRIORITY_EVENT_TRACING
# define EASY_OPTION_LOW_PRIORITY_EVENT_TRACING true
# endif
# ifndef EASY_OPTION_LOG_ENABLED
# define EASY_OPTION_LOG_ENABLED 0
# endif
# ifndef EASY_OPTION_START_LISTEN_ON_STARTUP
# define EASY_OPTION_START_LISTEN_ON_STARTUP 0
# endif
#endif // #ifndef BUILD_WITH_EASY_PROFILER
# ifndef EASY_DEFAULT_PORT
# define EASY_DEFAULT_PORT 28077
# endif
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
@ -334,7 +374,7 @@ namespace profiler {
//////////////////////////////////////////////////////////////////////
// Core types
const uint16_t DEFAULT_PORT = 28077;
const uint16_t DEFAULT_PORT = EASY_DEFAULT_PORT;
typedef uint64_t timestamp_t;
typedef uint32_t thread_id_t;

View File

@ -338,9 +338,9 @@ ThreadStorage::ThreadStorage() : id(getCurrentThreadId()), allowChildren(true),
void ThreadStorage::storeBlock(const profiler::Block& block)
{
#if EASY_MEASURE_STORAGE_EXPAND != 0
#if EASY_OPTION_MEASURE_STORAGE_EXPAND != 0
EASY_LOCAL_STATIC_PTR(const BaseBlockDescriptor*, desc,\
MANAGER.addBlockDescriptor(EASY_STORAGE_EXPAND_ENABLED ? profiler::ON : profiler::OFF, EASY_UNIQUE_LINE_ID, "EasyProfiler.ExpandStorage",\
MANAGER.addBlockDescriptor(EASY_OPTION_STORAGE_EXPAND_BLOCKS_ON ? profiler::ON : profiler::OFF, EASY_UNIQUE_LINE_ID, "EasyProfiler.ExpandStorage",\
__FILE__, __LINE__, profiler::BLOCK_TYPE_BLOCK, profiler::colors::White));
EASY_THREAD_LOCAL static profiler::timestamp_t beginTime = 0ULL;
@ -350,21 +350,21 @@ void ThreadStorage::storeBlock(const profiler::Block& block)
auto name_length = static_cast<uint16_t>(strlen(block.name()));
auto size = static_cast<uint16_t>(sizeof(BaseBlockData) + name_length + 1);
#if EASY_MEASURE_STORAGE_EXPAND != 0
#if EASY_OPTION_MEASURE_STORAGE_EXPAND != 0
const bool expanded = (desc->m_status & profiler::ON) && blocks.closedList.need_expand(size);
if (expanded) beginTime = getCurrentTime();
#endif
auto data = blocks.closedList.allocate(size);
#if EASY_MEASURE_STORAGE_EXPAND != 0
#if EASY_OPTION_MEASURE_STORAGE_EXPAND != 0
if (expanded) endTime = getCurrentTime();
#endif
::new (data) SerializedBlock(block, name_length);
blocks.usedMemorySize += size;
#if EASY_MEASURE_STORAGE_EXPAND != 0
#if EASY_OPTION_MEASURE_STORAGE_EXPAND != 0
if (expanded)
{
profiler::Block b(beginTime, desc->id(), "");
@ -421,9 +421,13 @@ ProfileManager::ProfileManager() :
, m_endTime(0)
{
m_isEnabled = ATOMIC_VAR_INIT(false);
m_isEventTracingEnabled = ATOMIC_VAR_INIT(EASY_EVENT_TRACING_ENABLED);
m_isEventTracingEnabled = ATOMIC_VAR_INIT(EASY_OPTION_EVENT_TRACING_ENABLED);
m_isAlreadyListening = ATOMIC_VAR_INIT(false);
m_stopListen = ATOMIC_VAR_INIT(false);
#if !defined(EASY_PROFILER_API_DISABLED) && EASY_OPTION_START_LISTEN_ON_STARTUP != 0
startListen(profiler::DEFAULT_PORT);
#endif
}
ProfileManager::~ProfileManager()

View File

@ -458,7 +458,7 @@ EasyMainWindow::EasyMainWindow() : Parent(), m_lastAddress("localhost"), m_lastP
m_eventTracingPriorityAction = submenu->addAction("Low priority event tracing");
m_eventTracingPriorityAction->setCheckable(true);
m_eventTracingPriorityAction->setChecked(EASY_LOW_PRIORITY_EVENT_TRACING);
m_eventTracingPriorityAction->setChecked(EASY_OPTION_LOW_PRIORITY_EVENT_TRACING);
m_eventTracingPriorityAction->setEnabled(false);
connect(m_eventTracingPriorityAction, &QAction::triggered, this, &This::onEventTracingPriorityChange);