wolfpld / tracy

Frame profiler
https://tracy.nereid.pl/
Other
10.16k stars 679 forks source link

Unable to get per-line sampling statistics on Windows (v0.11.0) #860

Closed zach2good closed 2 months ago

zach2good commented 2 months ago

Hi there!

The instrumentation and tools for analysis are excellent, I use them a lot! I'm currently struggling to set up per-line sampling statistics on Windows, is there a step I'm missing? I can access Instrumentation and Symbols, but not Sampling.

My setup

I can only get symbols to show up if I check Show All

image

Setup example from the README.md image

I've put together a small example that demonstrates the state of my setup.

main.cpp

#define TRACY_CALLSTACK 16
#include "tracy/Tracy.hpp"

#define TracyFrameMark FrameMark
#define TracyZoneScoped ZoneScoped

#include <thread>

void function0() {
  TracyZoneScoped;
  std::this_thread::sleep_for(std::chrono::milliseconds(10));
}

void function1() {
  TracyZoneScoped;
  std::this_thread::sleep_for(std::chrono::milliseconds(10));
  function0();
}

void function2() {
  TracyZoneScoped;
  std::this_thread::sleep_for(std::chrono::milliseconds(10));
  function1();
}

void function3() {
  TracyZoneScoped;
  std::this_thread::sleep_for(std::chrono::milliseconds(10));
  function2();
}

int main() {
  for (int i = 0; i < 10; i++) {
    TracyFrameMark;
    function3();
  }
  return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.20)
project(tracy_callstack_test C CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(LINKER_LANGUAGE CXX)
set(USE_FOLDERS ON)

# Generate compile_commands.json to make it easier to work with clang based tools
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CPM_DOWNLOAD_VERSION 0.34.0)

if(CPM_SOURCE_CACHE)
  # Expand relative path. This is important if the provided path contains a tilde (~)
  get_filename_component(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE} ABSOLUTE)
  set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
  set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
  set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
  message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
  file(DOWNLOAD
       https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
       ${CPM_DOWNLOAD_LOCATION}
  )
endif()

include(${CPM_DOWNLOAD_LOCATION})

message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}")
message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
message(STATUS "CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "CMAKE_CXX_COMPILER_VERSION: ${CMAKE_CXX_COMPILER_VERSION}")
message(STATUS "CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD}")
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER)
message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
if ("${CMAKE_BUILD_TYPE_UPPER}" STREQUAL "DEBUG")
    message(STATUS "CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}")
elseif ("${CMAKE_BUILD_TYPE_UPPER}" STREQUAL "MINSIZEREL")
    message(STATUS "CMAKE_CXX_FLAGS_MINSIZEREL: ${CMAKE_CXX_FLAGS_MINSIZEREL}")
elseif ("${CMAKE_BUILD_TYPE_UPPER}" STREQUAL "RELEASE")
    message(STATUS "CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}")
elseif ("${CMAKE_BUILD_TYPE_UPPER}" STREQUAL "RELWITHDEBINFO")
    message(STATUS "CMAKE_CXX_FLAGS_RELWITHDEBINFO: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
else()
    message(FATAL_ERROR "Did not recognise CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} to print out compiler flags.")
endif()
message(STATUS "CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")

# set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Tracy version tag, without the leading 'v'
set(TRACY_VERSION 0.11.0)

# Download client library
CPMAddPackage(
    NAME TracyClient
    GITHUB_REPOSITORY wolfpld/tracy
    GIT_TAG v${TRACY_VERSION}
    OPTIONS
        "TRACY_ENABLE ON"
        "TRACY_ON_DEMAND ON"
        "TRACY_CALLSTACK ON"
        "TRACY_NO_BROADCAST ON"
        "TRACY_NO_EXIT ON"
)

# Download Win32 server executables
if(MSVC)
    message(STATUS "Downloading Tracy client")
    file(DOWNLOAD
        https://github.com/wolfpld/tracy/releases/download/v${TRACY_VERSION}/windows-${TRACY_VERSION}.zip
        ${CMAKE_SOURCE_DIR}/tracy.tar.gz
        TIMEOUT 60
    )
    execute_process(COMMAND "${CMAKE_COMMAND}" -E
            tar xvf "${CMAKE_SOURCE_DIR}/tracy.tar.gz"
            WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/
    )
endif()

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} PUBLIC TracyClient)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /INCREMENTAL")

function(set_target_output_directory target)
    message(STATUS "Setting output directory for ${target} to ${CMAKE_SOURCE_DIR}")
    set_target_properties(${target} PROPERTIES
        VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
        RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_SOURCE_DIR}"
        RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_SOURCE_DIR}"
        RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_SOURCE_DIR}"
        RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_SOURCE_DIR}"
    )
endfunction()

set_target_output_directory(${PROJECT_NAME})

CMake setup and build output

C:\dev\tracy_test>cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
-- CMAKE_VERSION: 3.28.0-rc3
-- CMAKE_C_COMPILER: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe
-- CMAKE_CXX_COMPILER: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe
-- CMAKE_CXX_COMPILER_ID: MSVC
-- CMAKE_CXX_COMPILER_VERSION: 19.39.33523.0
-- CMAKE_CXX_STANDARD: 20
-- CMAKE_BUILD_TYPE: Debug
-- CMAKE_C_FLAGS: /DWIN32 /D_WINDOWS
-- CMAKE_CXX_FLAGS: /DWIN32 /D_WINDOWS /EHsc
-- CMAKE_CXX_FLAGS_DEBUG: /Zi /Ob0 /Od /RTC1
-- CMAKE_EXE_LINKER_FLAGS: /machine:x64
-- CPM: adding package TracyClient@0.11.0 (v0.11.0)
Parsing public/common/TracyVersion.hpp file
VERSION 0.11.0
-- TRACY_ENABLE: ON
-- TRACY_ON_DEMAND: ON
-- TRACY_CALLSTACK: ON
-- TRACY_NO_CALLSTACK: OFF
-- TRACY_NO_CALLSTACK_INLINES: OFF
-- TRACY_ONLY_LOCALHOST: OFF
-- TRACY_NO_BROADCAST: ON
-- TRACY_ONLY_IPV4: OFF
-- TRACY_NO_CODE_TRANSFER: OFF
-- TRACY_NO_CONTEXT_SWITCH: OFF
-- TRACY_NO_EXIT: ON
-- TRACY_NO_SAMPLING: OFF
-- TRACY_NO_VERIFY: OFF
-- TRACY_NO_VSYNC_CAPTURE: OFF
-- TRACY_NO_FRAME_IMAGE: OFF
-- TRACY_NO_SYSTEM_TRACING: OFF
-- TRACY_PATCHABLE_NOPSLEDS: OFF
-- TRACY_DELAYED_INIT: OFF
-- TRACY_MANUAL_LIFETIME: OFF
-- TRACY_FIBERS: OFF
-- TRACY_NO_CRASH_HANDLER: OFF
-- TRACY_TIMER_FALLBACK: OFF
-- TRACY_LIBUNWIND_BACKTRACE: OFF
-- TRACY_SYMBOL_OFFLINE_RESOLVE: OFF
-- TRACY_LIBBACKTRACE_ELF_DYNLOAD_SUPPORT: OFF
-- TRACY_DEMANGLE: OFF
-- Downloading Tracy client
x tracy-capture.exe
x tracy-csvexport.exe
x tracy-import-chrome.exe
x tracy-import-fuchsia.exe
x tracy-profiler.exe
x tracy-update.exe
-- Setting output directory for tracy_callstack_test to C:/dev/tracy_test
-- Configuring done (3.2s)
-- Generating done (0.1s)
-- Build files have been written to: C:/dev/tracy_test/build

C:\dev\tracy_test>cmake --build build --config Debug 
MSBuild version 17.9.8+b34f75857 for .NET Framework

  TracyClient.vcxproj -> C:\dev\tracy_test\build\_deps\tracyclient-build\Debug\TracyClient.lib
  tracy_callstack_test.vcxproj -> C:\dev\tracy_test\tracy_callstack_test.exe
wolfpld commented 2 months ago

The profiled application must be run with admin privileges.

zach2good commented 2 months ago

Aha! Perfect, thanks!