Skip to content

Commit

Permalink
Make profiling scopes a complete no-op when profiling is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Jul 17, 2023
1 parent a57f7c9 commit 66f8b96
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ OPTION(WZ_ENABLE_BASIS_UNIVERSAL "Enable Basis Universal texture support" ON)
OPTION(WZ_DEBUG_GFX_API_LEAKS "Enable debugging for graphics API leaks" ON)
OPTION(WZ_FORCE_MINIMAL_OPUSFILE "Force a minimal build of Opusfile, since WZ does not need (or want) HTTP stream support" ON)

# Dev options
OPTION(WZ_PROFILING_NVTX "Add NVTX-based profiling instrumentation to the code" OFF)

if(CMAKE_SYSTEM_NAME MATCHES "Windows" OR CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "Linux")
Expand Down Expand Up @@ -746,6 +747,12 @@ include(CheckCXXStdThread)
CHECK_CXX_STD_THREAD(HAVE_STD_THREAD)
cmake_reset_check_state()

if(WZ_PROFILING_NVTX)
set(WZ_PROFILING_INSTRUMENTATION ON)
else()
unset(WZ_PROFILING_INSTRUMENTATION)
endif()

set(WZ_BINDIR "${CMAKE_INSTALL_BINDIR}")
set(WZ_LOCALEDIR "${CMAKE_INSTALL_LOCALEDIR}")
message(STATUS "WZ_BINDIR=\"${WZ_BINDIR}\"")
Expand Down
9 changes: 6 additions & 3 deletions src/profiling.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "config.h"
#include "profiling.h"

#if defined(WZ_PROFILING_INSTRUMENTATION)

#include <cstdio>
#include <string>

Expand All @@ -10,8 +13,6 @@
#include <ittnotify.h>
#endif

#include "profiling.h"

namespace profiling
{

Expand Down Expand Up @@ -172,3 +173,5 @@ void mark(const Domain *domain, const char *object, const char *mark)
}

}

#endif // defined(WZ_PROFILING_INSTRUMENTATION)
14 changes: 11 additions & 3 deletions src/profiling.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#ifndef __INCLUDED_SRC_PROFILING_H__
#define __INCLUDED_SRC_PROFILING_H__
#pragma once

#include "lib/framework/wzglobal.h" // required for config.h

#if defined(WZ_PROFILING_INSTRUMENTATION)

#include <cstdint>

Expand Down Expand Up @@ -54,4 +57,9 @@ void mark(const Domain *domain, const char *object, const char *mark);
#define WZ_PROFILE_SCOPE(name) profiling::Scope mark_##name(&profiling::wzRootDomain, #name);
#define WZ_PROFILE_SCOPE2(object, name) profiling::Scope mark_##name(&profiling::wzRootDomain, #object, #name);

#endif // __INCLUDED_SRC_PROFILING_H__
#else // !defined(WZ_PROFILING_INSTRUMENTATION)

#define WZ_PROFILE_SCOPE(name)
#define WZ_PROFILE_SCOPE2(object, name)

#endif // defined(WZ_PROFILING_INSTRUMENTATION)

0 comments on commit 66f8b96

Please sign in to comment.