From 0bded8b046a9a304457e71409549e08eb36df41f Mon Sep 17 00:00:00 2001 From: Macoy Madson Date: Sun, 15 Nov 2020 21:18:05 -0800 Subject: [PATCH] Added Tracy profiler The module is still WIP. Some build system changes are necessary to make it sufficiently convenient --- .gitmodules | 3 +++ BuildTools.sh | 4 ++++ Build_Debug.sh | 1 + Dependencies/tracy | 1 + RunProfiler.sh | 3 +++ src/Tracy.cake | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 60 insertions(+) create mode 100755 BuildTools.sh create mode 160000 Dependencies/tracy create mode 100755 RunProfiler.sh create mode 100644 src/Tracy.cake diff --git a/.gitmodules b/.gitmodules index 5b4c965..a9e0983 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "Dependencies/ogre-next-deps"] path = Dependencies/ogre-next-deps url = https://github.com/OGRECave/ogre-next-deps +[submodule "Dependencies/tracy"] + path = Dependencies/tracy + url = https://github.com/wolfpld/tracy diff --git a/BuildTools.sh b/BuildTools.sh new file mode 100755 index 0000000..f79b8e4 --- /dev/null +++ b/BuildTools.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +# These are things not required to build, but are useful for debugging/profiling etc. +cd Dependencies/tracy/profiler/build/unix && make -j4 diff --git a/Build_Debug.sh b/Build_Debug.sh index cff9f14..f197819 100755 --- a/Build_Debug.sh +++ b/Build_Debug.sh @@ -7,3 +7,4 @@ # ./Dependencies/cakelisp/bin/cakelisp --verbose-processes src/SDL.cake ./Dependencies/cakelisp/bin/cakelisp --verbose-compile-time-build-objects test/SDLOgreApp.cake \ && echo "\n\nRUNTIME\n" && cd test && ./SDLOgreApp +# ./Dependencies/cakelisp/bin/cakelisp --verbose-compile-time-build-objects src/Tracy.cake diff --git a/Dependencies/tracy b/Dependencies/tracy new file mode 160000 index 0000000..e580dfe --- /dev/null +++ b/Dependencies/tracy @@ -0,0 +1 @@ +Subproject commit e580dfeed3f44911cf0a5ce0f584603aafa9ecde diff --git a/RunProfiler.sh b/RunProfiler.sh new file mode 100755 index 0000000..fd2bbfa --- /dev/null +++ b/RunProfiler.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +cd Dependencies/tracy/profiler/build/unix && ./Tracy-release diff --git a/src/Tracy.cake b/src/Tracy.cake new file mode 100644 index 0000000..b99a913 --- /dev/null +++ b/src/Tracy.cake @@ -0,0 +1,48 @@ +(set-cakelisp-option cakelisp-src-dir "Dependencies/cakelisp/src") + +(import &comptime-only "Macros.cake") + +(c-import "Tracy.hpp") + +;; TODO: Linux only +(c-import "unistd.h") + +(defun test-tracy-main (&return int) + (ZoneScopedN "main") + + (while (not (on-call (call (in tracy GetProfiler)) IsConnected)) + (ZoneScopedN "wait for profiler") + (sleep 1)) + + (var i int 0) + (while (< i 100000) + (ZoneScopedN "hot loop") + (sleep 1) + (incr i)) + (return 0)) + +;; TODO: Any file which includes Tracy needs these +;; For now, an easy way to build files which include necessary headers +(defmacro module-use-tracy-build-options () + (tokenize-push output + (set-module-option build-time-compiler "/usr/bin/clang++") + ;; Include cakelisp source for DynamicLoader.hpp + (set-module-option build-time-compile-arguments + "-Werror" "-Wall" "-Wextra" "-Wno-unused-parameter" "-Wno-unused-variable" + "-c" 'source-input "-o" 'object-output "-fPIC" + "-DTRACY_ENABLE" "-IDependencies/tracy")) + (return true)) + +(module-use-tracy-build-options) + +(add-cpp-build-dependency "../Dependencies/tracy/TracyClient.cpp") + +(defun-comptime tracy-link-hook (manager (& ModuleManager) + linkCommand (& ProcessCommand) + linkTimeInputs (* ProcessCommandInput) numLinkTimeInputs int + &return bool) + (command-add-string-argument "-lpthread") + (command-add-string-argument "-ldl") + (return true)) + +(add-compile-time-hook pre-link tracy-link-hook)