### Install Generated Configuration and License Files Source: https://github.com/yse/easy_profiler/blob/develop/easy_profiler_core/CMakeLists.txt Specifies the installation of the generated CMake configuration files (`.cmake`) and the project's license files (`LICENSE.MIT`, `LICENSE.APACHE`) to their designated installation directories. ```CMake install( FILES "${project_config}" "${version_config}" DESTINATION "${config_install_dir}" ) install( FILES LICENSE.MIT LICENSE.APACHE DESTINATION . ) ``` -------------------------------- ### Profiling Application Startup with Network Streaming in C++ Source: https://github.com/yse/easy_profiler/blob/develop/README.md This example combines `EASY_PROFILER_ENABLE` and `profiler::startListen()` to enable profiling from application startup, even before a profiler GUI connects. This ensures that initial execution phases are captured. ```cpp void main() { EASY_PROFILER_ENABLE; profiler::startListen(); /* do work */ } ``` -------------------------------- ### Install Project Headers and Export Build Targets Source: https://github.com/yse/easy_profiler/blob/develop/easy_profiler_core/CMakeLists.txt Defines installation rules for the project's public header directory and the `easy_profiler` target. It specifies distinct installation paths for libraries, archives, and runtimes based on component types, and exports the target for external use. ```CMake install( DIRECTORY ${EASY_INCLUDE_DIR} DESTINATION include/ ) install( TARGETS easy_profiler EXPORT ${targets_export_name} LIBRARY DESTINATION lib COMPONENT Runtime ARCHIVE DESTINATION lib COMPONENT Development RUNTIME DESTINATION bin COMPONENT Runtime BUNDLE DESTINATION bin COMPONENT Runtime PUBLIC_HEADER DESTINATION include COMPONENT Development BUNDLE DESTINATION bin COMPONENT Runtime ) install( EXPORT "${targets_export_name}" DESTINATION "${config_install_dir}" ) ``` -------------------------------- ### Generate and Configure CMake Package Files Source: https://github.com/yse/easy_profiler/blob/develop/easy_profiler_core/CMakeLists.txt Uses `write_basic_package_version_file` to create a version configuration and `configure_package_config_file` to process a template for the main project configuration, preparing them for installation. ```CMake write_basic_package_version_file( "${version_config}" VERSION ${EASY_PRODUCT_VERSION_STRING} COMPATIBILITY SameMajorVersion ) configure_package_config_file( "cmake/config.cmake.in" "${project_config}" INSTALL_DESTINATION "${config_install_dir}" ) ``` -------------------------------- ### Main CMakeLists.txt for easy_profiler Project Setup Source: https://github.com/yse/easy_profiler/blob/develop/CMakeLists.txt This snippet contains the complete CMake configuration for the 'easy_profiler' project. It defines project properties, sets C++ standards (C++11), applies compiler-specific flags for MSVC and GNU/Clang, manages build options such as enabling/disabling the GUI, sets version information, and includes various subprojects like 'easy_profiler_core', 'profiler_gui', and 'easy_profiler_converter'. ```CMake cmake_minimum_required(VERSION 3.0) project(easy_profiler CXX) set_property(GLOBAL PROPERTY USE_FOLDERS ON) if (CMAKE_VERSION VERSION_LESS "3.1") if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") endif () else () set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) endif () if (MSVC) if (NOT (MSVC_VERSION LESS 1914)) # turn on valid __cplusplus macro value for visual studio (available since msvc 2017 update 7) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus") endif () endif () option(EASY_PROFILER_NO_GUI "Build easy_profiler without the GUI application (required Qt)" OFF) set(EASY_PROGRAM_VERSION_MAJOR 2) set(EASY_PROGRAM_VERSION_MINOR 1) set(EASY_PROGRAM_VERSION_PATCH 0) set(EASY_PRODUCT_VERSION_STRING "${EASY_PROGRAM_VERSION_MAJOR}.${EASY_PROGRAM_VERSION_MINOR}.${EASY_PROGRAM_VERSION_PATCH}") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) # set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_LIST_DIR}/sdk) macro(easy_define_target_option TARGET SOURCE_OPTION TARGET_DEFINITION) if (${SOURCE_OPTION}) set(_VALUE 1) else () set(_VALUE 0) endif () target_compile_options(${TARGET} PUBLIC -D${TARGET_DEFINITION}=${_VALUE}) endmacro() SET(CMAKE_INSTALL_RPATH "$ORIGIN") add_subdirectory(easy_profiler_core) if (NOT EASY_PROFILER_NO_GUI) add_subdirectory(profiler_gui) endif() add_subdirectory(easy_profiler_converter) if (NOT EASY_PROFILER_NO_SAMPLES) add_subdirectory(sample) add_subdirectory(reader) endif () ``` -------------------------------- ### Collecting Profiling Data via Network Streaming in C++ Source: https://github.com/yse/easy_profiler/blob/develop/README.md This snippet shows the basic C++ code to start listening for profiling capture signals over the network using `profiler::startListen()`. It's part of a multi-step process involving a GUI for initiating and stopping the capture. ```cpp void main() { profiler::startListen(); /* do work */ } ``` -------------------------------- ### Configure EasyProfiler GUI Application Build Source: https://github.com/yse/easy_profiler/blob/develop/profiler_gui/CMakeLists.txt This CMake snippet defines the build process for the `profiler_gui` executable. It first attempts to locate Qt6 libraries, then conditionally adds the executable with a comprehensive list of source files if Qt6 is found. It links the application against `Qt6::Widgets`, `Qt6::Core5Compat`, and `easy_profiler`, and applies platform-specific compile definitions for Windows and MinGW. Finally, it sets up installation rules to place the executable in the `bin` directory. ```CMake #set(CMAKE_PREFIX_PATH f:/qt/5.5/5.6/msvc2013_64/lib/cmake) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) find_package(Qt6Widgets) find_package(Qt6Core5Compat) if (Qt6Widgets_FOUND) message(STATUS "Using Qt v${Qt6Widgets_VERSION}") if (NOT("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") AND WIN32) set(APPLICATION_PLATFORM WIN32) endif () add_executable(profiler_gui ${APPLICATION_PLATFORM} main.cpp arbitrary_value_inspector.h arbitrary_value_inspector.cpp arbitrary_value_tooltip.h arbitrary_value_tooltip.cpp blocks_graphics_view.h blocks_graphics_view.cpp blocks_tree_widget.h blocks_tree_widget.cpp bookmarks_editor.h bookmarks_editor.cpp common_functions.h common_functions.cpp common_types.h descriptors_tree_widget.h descriptors_tree_widget.cpp dialog.h dialog.cpp file_reader.h file_reader.cpp fps_widget.h fps_widget.cpp globals.h globals.cpp globals_qobjects.cpp graphics_block_item.h graphics_block_item.cpp graphics_image_item.h graphics_image_item.cpp graphics_ruler_item.h graphics_ruler_item.cpp graphics_scrollbar.h graphics_scrollbar.cpp graphics_slider_area.h graphics_slider_area.cpp main_window.h main_window.cpp round_progress_widget.h round_progress_widget.cpp socket_listener.h socket_listener.cpp text_highlighter.h text_highlighter.cpp timer.h timer.cpp thread_pool.h thread_pool.cpp thread_pool_task.h thread_pool_task.cpp tree_widget_item.h tree_widget_item.cpp tree_widget_loader.h tree_widget_loader.cpp window_header.h window_header.cpp resources.qrc resources.rc ) target_link_libraries(profiler_gui Qt6::Widgets Qt6::Core5Compat easy_profiler) if (WIN32) target_compile_definitions(profiler_gui PRIVATE -D_WIN32_WINNT=0x0600) endif () if (MINGW) target_compile_definitions(profiler_gui PRIVATE -DSTRSAFE_NO_DEPRECATE) endif () install( TARGETS profiler_gui RUNTIME DESTINATION bin ) set_property(TARGET profiler_gui PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE) else () message(STATUS "INFO\n\n\tQt6 not found! Generating EasyProfiler projects without GUI.\n") endif () ``` -------------------------------- ### Dumping Profiling Data to a File in C++ Source: https://github.com/yse/easy_profiler/blob/develop/README.md This example demonstrates how to enable profiling and dump the collected data to a specified file using `EASY_PROFILER_ENABLE` and `profiler::dumpBlocksToFile()`. This method allows for offline analysis of profiling results. ```cpp void main() { EASY_PROFILER_ENABLE; /* do work */ profiler::dumpBlocksToFile("test_profile.prof"); } ``` -------------------------------- ### Integrate easy_profiler with CMake Source: https://github.com/yse/easy_profiler/blob/develop/README.md This CMake example demonstrates how to find and link the easy_profiler library to your C++ application. It requires setting `CMAKE_PREFIX_PATH` to the easy_profiler release directory and then using `find_package` and `target_link_libraries` to include the profiler in your project. ```CMake project(my_application) set(SOURCES main.cpp ) # CMAKE_PREFIX_PATH should be set to /lib/cmake/easy_profiler find_package(easy_profiler REQUIRED) # STEP 1 ######################### add_executable(my_application ${SOURCES}) target_link_libraries(my_application easy_profiler) # STEP 2 ########## ``` -------------------------------- ### Build easy_profiler on Windows (CMake Way 1) Source: https://github.com/yse/easy_profiler/blob/develop/README.md Demonstrates how to generate a Visual Studio 2013 Win64 solution for easy_profiler using CMake, by explicitly specifying the path to Qt6's cmake scripts. This method requires the full path to the Qt6 installation's 'lib/cmake' directory. ```batch mkdir build cd build cmake -DCMAKE_PREFIX_PATH="C:\Qt\6.7.2\msvc2013_64\lib\cmake" .. -G "Visual Studio 12 2013 Win64" ``` -------------------------------- ### Configure Easy Profiler Converter Build with CMake Source: https://github.com/yse/easy_profiler/blob/develop/easy_profiler_converter/CMakeLists.txt This snippet outlines the CMake configuration for building the 'profiler_converter' application. It specifies C++ source and header files, includes necessary directories, links against the 'easy_profiler' library, and defines installation paths and runtime path properties. ```CMake set(CPP_FILES converter.cpp reader.cpp) set(HEADER_FILES converter.h reader.h) include_directories(../easy_profiler_core/) include_directories(./include) add_executable(profiler_converter ${HEADER_FILES} ${CPP_FILES} main.cpp) target_link_libraries(profiler_converter easy_profiler) install( TARGETS profiler_converter RUNTIME DESTINATION bin ) set_property(TARGET profiler_converter PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE) ``` -------------------------------- ### Configure EasyProfiler Include Directories and Global Definitions (CMake) Source: https://github.com/yse/easy_profiler/blob/develop/easy_profiler_core/CMakeLists.txt This snippet sets up the public and install include directories for the `easy_profiler` target. It also defines global compile definitions such as `_BUILD_PROFILER`, version numbers, and default port, and conditionally sets `EASY_PROFILER_STATIC` if building a static library. ```CMake target_include_directories(easy_profiler PUBLIC $ $ # /include ) target_compile_definitions(easy_profiler PRIVATE -D_BUILD_PROFILER=1 #-DEASY_PROFILER_API_DISABLED # uncomment this to disable profiler api only (you will have to rebuild only easy_profiler) ) if (NOT BUILD_SHARED_LIBS) target_compile_definitions(easy_profiler PUBLIC -DEASY_PROFILER_STATIC=1) endif () target_compile_definitions(easy_profiler PUBLIC -DEASY_PROFILER_VERSION_MAJOR=${EASY_PROGRAM_VERSION_MAJOR} -DEASY_PROFILER_VERSION_MINOR=${EASY_PROGRAM_VERSION_MINOR} -DEASY_PROFILER_VERSION_PATCH=${EASY_PROGRAM_VERSION_PATCH} -DEASY_DEFAULT_PORT=${EASY_DEFAULT_PORT} -DBUILD_WITH_EASY_PROFILER=1 ) ``` -------------------------------- ### Define Core CMake Configuration Variables Source: https://github.com/yse/easy_profiler/blob/develop/easy_profiler_core/CMakeLists.txt Sets up essential variables for CMake package configuration files and target export names. It also includes standard CMake modules for package helpers and system library installation. ```CMake set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake") set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake") set(targets_export_name "${PROJECT_NAME}Targets") include(CMakePackageConfigHelpers) include(InstallRequiredSystemLibraries) ``` -------------------------------- ### Storing Variable Values for Profiling in C++ Source: https://github.com/yse/easy_profiler/blob/develop/README.md This example illustrates how to dump arbitrary variable values and arrays into the profiling data using `EASY_VALUE` and `EASY_ARRAY`. It also shows how to use `EASY_VIN` to ensure consistent value IDs for variables whose addresses might change. ```cpp #include #include // EASY_VALUE, EASY_ARRAY are defined here class Object { Vector3 m_position; // Let's suppose Vector3 is a struct { float x, y, z; }; unsigned int m_id; public: void act() { EASY_FUNCTION(profiler::colors::Cyan); // Dump variables values constexpr auto Size = sizeof(Vector3) / sizeof(float); EASY_VALUE("id", m_id); EASY_ARRAY("position", &m_position.x, Size, profiler::color::Red); // Do something ... } void loop(uint32_t N) { EASY_FUNCTION(); EASY_VALUE("N", N, EASY_VIN("N")); /* EASY_VIN is used here to ensure that this value id will always be the same, because the address of N can change */ for (uint32_t i = 0; i < N; ++i) { // Do something } } }; ``` -------------------------------- ### Inserting Profiling Blocks in C++ with EasyProfiler Source: https://github.com/yse/easy_profiler/blob/develop/README.md This snippet demonstrates how to insert various types of profiling blocks using EasyProfiler macros like `EASY_FUNCTION` and `EASY_BLOCK`. It shows examples of named blocks, scoped blocks, and blocks with custom colors, highlighting that `EASY_END_BLOCK` is often implicit. ```cpp #include void foo() { EASY_FUNCTION(profiler::colors::Magenta); // Magenta block with name "foo" EASY_BLOCK("Calculating sum"); // Begin block with default color == Amber100 int sum = 0; for (int i = 0; i < 10; ++i) { EASY_BLOCK("Addition", profiler::colors::Red); // Scoped red block (no EASY_END_BLOCK needed) sum += i; } EASY_END_BLOCK; // End of "Calculating sum" block EASY_BLOCK("Calculating multiplication", profiler::colors::Blue500); // Blue block int mul = 1; for (int i = 1; i < 11; ++i) mul *= i; //EASY_END_BLOCK; // This is not needed because all blocks are ended on destructor when closing braces met } void bar() { EASY_FUNCTION(0xfff080aa); // Function block with custom ARGB color } void baz() { EASY_FUNCTION(); // Function block with default color == Amber100 } ``` -------------------------------- ### Build easy_profiler on QNX (CMake) Source: https://github.com/yse/easy_profiler/blob/develop/README.md Provides instructions for building easy_profiler on QNX. It involves sourcing the QNX environment and then using CMake with a specified toolchain file to generate the build system. ```bash souce $QNX_ENVIRONMENT mkdir build cd build cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/QNXToolchain.cmake .. ``` -------------------------------- ### Apply Platform-Specific Compile Options and Link Libraries (CMake) Source: https://github.com/yse/easy_profiler/blob/develop/easy_profiler_core/CMakeLists.txt This snippet applies platform-specific compile options and links necessary libraries for the `easy_profiler` target. It includes `-Wall` and other warnings for UNIX, links `pthread` (except Android/QNX) and `socket` (for QNX), and sets Windows-specific definitions (`_WIN32_WINNT`, `_CRT_SECURE_NO_WARNINGS`) and links `ws2_32`, `psapi`. MinGW and MSVC specific options are also handled. ```CMake if (UNIX) target_compile_options(easy_profiler PRIVATE -Wall -Wno-long-long -Wno-reorder -Wno-braced-scalar-init -pedantic) if (NOT ANDROID AND NOT QNX) target_link_libraries(easy_profiler pthread) endif() if (QNX) target_link_libraries(easy_profiler socket) endif() elseif (WIN32) target_compile_definitions(easy_profiler PRIVATE -D_WIN32_WINNT=0x0600 -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS) target_link_libraries(easy_profiler ws2_32 psapi) endif () if (MINGW) target_compile_definitions(easy_profiler PRIVATE -DSTRSAFE_NO_DEPRECATE) endif () if (MSVC) target_compile_options(easy_profiler PRIVATE /WX) endif () ``` -------------------------------- ### Building EasyProfiler on Linux Source: https://github.com/yse/easy_profiler/blob/develop/README.md This snippet provides the standard CMake and Make commands to build the EasyProfiler library on Linux. It includes steps for creating a build directory, configuring with CMake for a Release build, and compiling the project. ```bash $ mkdir build $ cd build $ cmake -DCMAKE_BUILD_TYPE="Release" .. $ make ``` -------------------------------- ### Build easy_profiler on Windows (CMake Way 2) Source: https://github.com/yse/easy_profiler/blob/develop/README.md Illustrates an alternative method to generate a Visual Studio 2013 Win64 solution for easy_profiler using CMake. This approach relies on setting the 'Qt6Widgets_DIR' system variable to the Qt6 cmake directory before running the CMake command. ```batch mkdir build cd build cmake .. -G "Visual Studio 12 2013 Win64" ``` -------------------------------- ### Build EasyProfiler Library Source: https://github.com/yse/easy_profiler/blob/develop/easy_profiler_core/CMakeLists.txt This CMake snippet organizes the public include files into a source group for IDEs, consolidates all C++ source, internal header, and public include files into a single `SOURCES` variable, and then uses `add_library` to compile them into the `easy_profiler` library, including a Windows resource file. ```CMake source_group(include FILES ${INCLUDE_FILES}) set(SOURCES ${CPP_FILES} ${H_FILES} ${INCLUDE_FILES} ) add_library(easy_profiler ${SOURCES} resources.rc) ``` -------------------------------- ### Display EasyProfiler Build Options Status Source: https://github.com/yse/easy_profiler/blob/develop/easy_profiler_core/CMakeLists.txt This CMake snippet prints the current configuration status of various EasyProfiler build options to the console. It details the selected timer, default listening port, auto-start behavior, self-profiling settings, dynamic name truncation, value data size checks, implicit thread registration, and event tracing options, including warnings for potential issues on Unix systems. ```CMake message(STATUS "-------- EASY_PROFILER OPTIONS: --------") if (BUILD_WITH_CHRONO_STEADY_CLOCK) message(STATUS " Use std::chrono::steady_clock as a timer") elseif (BUILD_WITH_CHRONO_HIGH_RESOLUTION_CLOCK) message(STATUS " Use std::chrono::high_resolution_clock as a timer") else () if (WIN32) message(STATUS " Use QueryPerformanceCounter as a timer") else () message(STATUS " Use rtdsc as a timer") endif () endif () message(STATUS " Default listening port = ${EASY_DEFAULT_PORT}") message(STATUS " Auto-start listening = ${EASY_OPTION_LISTEN}") message(STATUS " Profile self = ${EASY_OPTION_PROFILE_SELF}") message(STATUS " Profile self blocks initial status = ${EASY_OPTION_PROFILE_SELF_BLOCKS_ON}") if (EASY_OPTION_TRUNCATE_RUNTIME_NAMES) message(STATUS " Truncate block dynamic names = ${EASY_OPTION_TRUNCATE_RUNTIME_NAMES} (reduces performance)") else() message(STATUS " Truncate block dynamic names = ${EASY_OPTION_TRUNCATE_RUNTIME_NAMES} (may cause crash if using dynamic block names of length >${EASY_MAX_SIZE_VALUE} symbols)") endif() if (EASY_OPTION_CHECK_MAX_VALUE_SIZE) message(STATUS " Check maximum EASY_VALUE data size = ${EASY_OPTION_CHECK_MAX_VALUE_SIZE} (slightly reduces performance)") else() message(STATUS " Check maximum EASY_VALUE data size = ${EASY_OPTION_CHECK_MAX_VALUE_SIZE} (may cause crash if using EASY_VALUE arrays of total data size >${EASY_MAX_SIZE_VALUE} bytes)") endif() message(STATUS " Implicit thread registration = ${EASY_OPTION_IMPLICIT_THREAD_REGISTRATION}") if (WIN32) message(STATUS " Event tracing = ${EASY_OPTION_EVENT_TRACING}") message(STATUS " Event tracing has low priority = ${EASY_OPTION_LOW_PRIORITY_EVENT_TRACING}") elseif (NO_CXX11_THREAD_LOCAL_SUPPORT) if (EASY_OPTION_IMPLICIT_THREAD_REGISTRATION) message(STATUS " WARNING! Implicit thread registration for Unix systems can lead to memory leak") message(STATUS " because there is no possibility to check if thread is alive and remove dead threads.") endif () message(STATUS " Removing empty unguarded threads = ${EASY_OPTION_REMOVE_EMPTY_UNGUARDED_THREADS}") if (EASY_OPTION_REMOVE_EMPTY_UNGUARDED_THREADS) message(STATUS " WARNING! Removing empty unguarded threads may lead to an application crash!") message(STATUS " But fixes potential memory leak on Unix systems.") else () message(STATUS " WARNING! There is a possibility of memory leak without removing empty unguarded threads.") endif () endif () message(STATUS " Log messages = ${EASY_OPTION_LOG}") message(STATUS " Function names pretty-print = ${EASY_OPTION_PRETTY_PRINT}") message(STATUS " Use EasyProfiler colors palette = ${EASY_OPTION_PREDEFINED_COLORS}") message(STATUS " Shared library: ${BUILD_SHARED_LIBS}") message(STATUS "------ END EASY_PROFILER OPTIONS -------") message(STATUS "") ``` -------------------------------- ### CMake: Building and Linking with easy_profiler Source: https://github.com/yse/easy_profiler/blob/develop/reader/CMakeLists.txt This CMake snippet demonstrates how to define an executable named `profiler_reader` from `main.cpp` and link it against the `easy_profiler` library. This configuration is crucial for projects that utilize `easy_profiler` for performance profiling, ensuring the necessary library is correctly linked during compilation. ```CMake add_executable(profiler_reader main.cpp) target_link_libraries(profiler_reader easy_profiler) ``` -------------------------------- ### Capturing Thread Context-Switch Events on Linux Source: https://github.com/yse/easy_profiler/blob/develop/README.md This snippet provides a bash command to capture thread context-switch events on Linux systems using `systemtap`. It requires root privileges and specifies an output log file and the application name. ```bash #stap -o /tmp/cs_profiling_info.log scripts/context_switch_logger.stp name APPLICATION_NAME ``` -------------------------------- ### Define EasyProfiler Build Configuration Options in CMake Source: https://github.com/yse/easy_profiler/blob/develop/easy_profiler_core/CMakeLists.txt This section defines various build-time configuration options for the EasyProfiler library using CMake `set` commands with `CACHE` for user-configurable variables. Options include default listening port, automatic startup, self-profiling, runtime name truncation, value size checking, logging, pretty printing, predefined colors, and shared library build. It also conditionally sets implicit thread registration and event tracing options based on the operating system and C++11 `thread_local` support. ```CMake set(EASY_OPTION_IMPLICIT_THREAD_REGISTER_TEXT "Enable new threads registration when collecting context switch events") set(EASY_DEFAULT_PORT 28077 CACHE STRING "Default listening port") set(EASY_OPTION_LISTEN OFF CACHE BOOL "Enable automatic startListen on startup") set(EASY_OPTION_PROFILE_SELF OFF CACHE BOOL "Enable self profiling (measure time for internal storage expand)") set(EASY_OPTION_PROFILE_SELF_BLOCKS_ON OFF CACHE BOOL "Storage expand default status (profiler::ON or profiler::OFF)") set(EASY_OPTION_TRUNCATE_RUNTIME_NAMES OFF CACHE BOOL "Enable truncation of block dynamic names (set at run-time, not compile-time). Reduces performance. Turn ON only if you want to use dynamic block names of length >${EASY_MAX_SIZE_VALUE} symbols at runtime. It is better to use EASY_VALUE instead of such long names.") set(EASY_OPTION_CHECK_MAX_VALUE_SIZE OFF CACHE BOOL "Enable checking EASY_VALUE maximum data size. Slightly reduces performance. Turn ON only if you want to pass big EASY_ARRAY, EASY_STRING, EASY_TEXT of length >${EASY_MAX_SIZE_VALUE} bytes. It is better to split such arrays into the smaller ones.") set(EASY_OPTION_LOG OFF CACHE BOOL "Print errors to stderr") set(EASY_OPTION_PRETTY_PRINT OFF CACHE BOOL "Use pretty-printed function names with signature and argument types") set(EASY_OPTION_PREDEFINED_COLORS ON CACHE BOOL "Use predefined set of colors (see profiler_colors.h). If you want to use your own colors palette you can turn this option OFF") set(BUILD_SHARED_LIBS ON CACHE BOOL "Build easy_profiler as shared library.") if (WIN32) set(EASY_OPTION_IMPLICIT_THREAD_REGISTRATION ON CACHE BOOL ${EASY_OPTION_IMPLICIT_THREAD_REGISTER_TEXT}) set(EASY_OPTION_EVENT_TRACING ON CACHE BOOL "Enable event tracing by default") set(EASY_OPTION_LOW_PRIORITY_EVENT_TRACING ON CACHE BOOL "Set low priority for event tracing thread") else () if (NO_CXX11_THREAD_LOCAL_SUPPORT) set(EASY_OPTION_IMPLICIT_THREAD_REGISTRATION OFF CACHE BOOL ${EASY_OPTION_IMPLICIT_THREAD_REGISTER_TEXT}) set(EASY_OPTION_REMOVE_EMPTY_UNGUARDED_THREADS OFF CACHE BOOL "Enable easy_profiler to remove empty unguarded threads. This fixes potential memory leak on Unix systems, but may lead to an application crash! This is used when C++11 thread_local is unavailable.") else () set(EASY_OPTION_IMPLICIT_THREAD_REGISTRATION ON CACHE BOOL ${EASY_OPTION_IMPLICIT_THREAD_REGISTER_TEXT}) endif () endif () set(BUILD_WITH_CHRONO_STEADY_CLOCK OFF CACHE BOOL "Use std::chrono::steady_clock as a timer" ) set(BUILD_WITH_CHRONO_HIGH_RESOLUTION_CLOCK OFF CACHE BOOL "Use std::chrono::high_resolution_clock as a timer") ``` -------------------------------- ### Building EasyProfiler on MacOS Source: https://github.com/yse/easy_profiler/blob/develop/README.md This snippet outlines the CMake and Make commands required to build EasyProfiler on MacOS. It specifically includes flags to specify GCC 5 as the C++ and C compiler, which might be necessary for compatibility. ```bash $ mkdir build $ cd build $ cmake -DCMAKE_CXX_COMPILER=g++-5 -DCMAKE_C_COMPILER=gcc-5 -DCMAKE_BUILD_TYPE="Release" .. $ make ``` -------------------------------- ### Define EasyProfiler Build Options (CMake) Source: https://github.com/yse/easy_profiler/blob/develop/easy_profiler_core/CMakeLists.txt This section defines various build options for the `easy_profiler` target using the `easy_define_target_option` macro. These options control features like clock sources, listening behavior, self-profiling, runtime name truncation, and logging, with some options being platform-specific (e.g., event tracing on Windows). ```CMake easy_define_target_option(easy_profiler BUILD_WITH_CHRONO_STEADY_CLOCK EASY_CHRONO_STEADY_CLOCK) easy_define_target_option(easy_profiler BUILD_WITH_CHRONO_HIGH_RESOLUTION_CLOCK EASY_CHRONO_HIGHRES_CLOCK) easy_define_target_option(easy_profiler EASY_OPTION_LISTEN EASY_OPTION_START_LISTEN_ON_STARTUP) easy_define_target_option(easy_profiler EASY_OPTION_PROFILE_SELF EASY_OPTION_MEASURE_STORAGE_EXPAND) easy_define_target_option(easy_profiler EASY_OPTION_PROFILE_SELF_BLOCKS_ON EASY_OPTION_STORAGE_EXPAND_BLOCKS_ON) easy_define_target_option(easy_profiler EASY_OPTION_TRUNCATE_RUNTIME_NAMES EASY_OPTION_TRUNCATE_LONG_RUNTIME_NAMES) easy_define_target_option(easy_profiler EASY_OPTION_CHECK_MAX_VALUE_SIZE EASY_OPTION_CHECK_MAX_VALUE_DATA_SIZE) easy_define_target_option(easy_profiler EASY_OPTION_IMPLICIT_THREAD_REGISTRATION EASY_OPTION_IMPLICIT_THREAD_REGISTRATION) if (WIN32) easy_define_target_option(easy_profiler EASY_OPTION_EVENT_TRACING EASY_OPTION_EVENT_TRACING_ENABLED) easy_define_target_option(easy_profiler EASY_OPTION_LOW_PRIORITY_EVENT_TRACING EASY_OPTION_LOW_PRIORITY_EVENT_TRACING) else () easy_define_target_option(easy_profiler EASY_OPTION_REMOVE_EMPTY_UNGUARDED_THREADS EASY_OPTION_REMOVE_EMPTY_UNGUARDED_THREADS) endif () easy_define_target_option(easy_profiler EASY_OPTION_LOG EASY_OPTION_LOG_ENABLED) easy_define_target_option(easy_profiler EASY_OPTION_PRETTY_PRINT EASY_OPTION_PRETTY_PRINT_FUNCTIONS) easy_define_target_option(easy_profiler EASY_OPTION_PREDEFINED_COLORS EASY_OPTION_BUILTIN_COLORS) ``` -------------------------------- ### CMake Configuration for Easy Profiler Sample Executables Source: https://github.com/yse/easy_profiler/blob/develop/sample/CMakeLists.txt This CMake snippet defines source files, sets up include and link directories, and creates two executable targets: `profiler_sample` and `profiler_sample_disabled_profiler`. The `profiler_sample_disabled_profiler` target is specifically configured with `DISABLE_EASY_PROFILER` to demonstrate building an application where the profiler is conditionally disabled at compile time. Both executables link against the `easy_profiler` library. ```CMake set(CPP_FILES main.cpp ) set(SOURCES ${CPP_FILES} ) link_directories(${CMAKE_SOURCE_DIR}/../bin) add_executable(profiler_sample ${SOURCES}) target_link_libraries(profiler_sample easy_profiler) add_executable(profiler_sample_disabled_profiler ${SOURCES}) target_link_libraries(profiler_sample_disabled_profiler easy_profiler) target_compile_definitions(profiler_sample_disabled_profiler PRIVATE DISABLE_EASY_PROFILER) ``` -------------------------------- ### Define EasyProfiler Source and Header Files Source: https://github.com/yse/easy_profiler/blob/develop/easy_profiler_core/CMakeLists.txt This CMake snippet defines two lists: `CPP_FILES` for C++ source files and `H_FILES` for C++ header files. These lists enumerate all the core implementation and internal header files required to build the EasyProfiler library. ```CMake set(CPP_FILES base_block_descriptor.cpp block.cpp block_descriptor.cpp easy_socket.cpp event_trace_win.cpp nonscoped_block.cpp profile_manager.cpp profiler.cpp reader.cpp serialized_block.cpp thread_storage.cpp writer.cpp ) set(H_FILES block_descriptor.h chunk_allocator.h current_time.h current_thread.h event_trace_win.h nonscoped_block.h profile_manager.h thread_storage.h spin_lock.h stack_buffer.h ) ``` -------------------------------- ### Define EasyProfiler Public Include Files Source: https://github.com/yse/easy_profiler/blob/develop/easy_profiler_core/CMakeLists.txt This CMake snippet sets the base directory for EasyProfiler's public include files and then creates a list, `INCLUDE_FILES`, containing all header files intended for external use by projects linking against EasyProfiler. This includes headers from the main include directory and its subdirectories. ```CMake set(EASY_INCLUDE_DIR "include/easy") set(INCLUDE_FILES ${EASY_INCLUDE_DIR}/arbitrary_value.h ${EASY_INCLUDE_DIR}/easy_net.h ${EASY_INCLUDE_DIR}/easy_socket.h ${EASY_INCLUDE_DIR}/profiler.h ${EASY_INCLUDE_DIR}/reader.h ${EASY_INCLUDE_DIR}/utility.h ${EASY_INCLUDE_DIR}/serialized_block.h ${EASY_INCLUDE_DIR}/writer.h ${EASY_INCLUDE_DIR}/details/arbitrary_value_aux.h ${EASY_INCLUDE_DIR}/details/arbitrary_value_public_types.h ${EASY_INCLUDE_DIR}/details/easy_compiler_support.h ${EASY_INCLUDE_DIR}/details/profiler_aux.h ${EASY_INCLUDE_DIR}/details/profiler_colors.h ${EASY_INCLUDE_DIR}/details/profiler_in_use.h ${EASY_INCLUDE_DIR}/details/profiler_public_types.h ) ``` -------------------------------- ### Configure Public Compile Definitions for easy_profiler Source: https://github.com/yse/easy_profiler/blob/develop/easy_profiler_core/CMakeLists.txt Sets public compile definitions for the `easy_profiler` target, which can influence how the target is built and linked by other projects. ```CMake target_compile_definitions(easy_profiler PUBLIC ) ``` -------------------------------- ### EasyProfiler v2.0.0 File Header Structure Source: https://github.com/yse/easy_profiler/blob/develop/README.md Defines the 'EasyFileHeader' C++ structure used in easy_profiler version 2.0.0. This structure represents the header of the '.prof' file, noting a change in the order of 'memory_size' and 'blocks_number' fields compared to v1.3.0. ```cpp struct EasyFileHeader { uint32_t signature = 0; uint32_t version = 0; profiler::processid_t pid = 0; int64_t cpu_frequency = 0; profiler::timestamp_t begin_time = 0; profiler::timestamp_t end_time = 0; // Changed order of memory_size and blocks_number relative to v1.3.0 uint64_t memory_size = 0; uint64_t descriptors_memory_size = 0; uint32_t total_blocks_number = 0; uint32_t total_descriptors_number = 0; }; ``` -------------------------------- ### Check C++11 thread_local Support in CMake Source: https://github.com/yse/easy_profiler/blob/develop/easy_profiler_core/CMakeLists.txt This snippet checks for C++11 `thread_local` support based on the compiler ID (GNU, Clang, AppleClang) and its version, specifically for non-Windows systems. If the compiler version is too old to support `thread_local`, it sets `NO_CXX11_THREAD_LOCAL_SUPPORT` to `TRUE` and issues a warning about potential memory leaks or application crashes when using implicit thread registration without this feature. ```CMake if (NOT WIN32) if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8") set(NO_CXX11_THREAD_LOCAL_SUPPORT TRUE) endif () elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.3") set(NO_CXX11_THREAD_LOCAL_SUPPORT TRUE) endif () elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0") set(NO_CXX11_THREAD_LOCAL_SUPPORT TRUE) endif () endif () # TODO: Check thread_local keyword support for other compilers for Unix if (NO_CXX11_THREAD_LOCAL_SUPPORT) message(WARNING " Your compiler does not support C++11 thread_local feature.") message(WARNING " Without C++11 thread_local feature you may face to possible memory leak or application crash if using implicit thread registration and using EASY_THREAD instead of EASY_THREAD_SCOPE.") endif () endif () ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.