├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── build_tracy.zig ├── tracy-0.7.8 ├── .gitignore ├── AUTHORS ├── LICENSE ├── NEWS ├── README.md ├── TODO ├── Tracy.hpp ├── TracyC.h ├── TracyClient.cpp ├── TracyD3D11.hpp ├── TracyD3D12.hpp ├── TracyLua.hpp ├── TracyOpenCL.hpp ├── TracyOpenGL.hpp ├── TracyVulkan.hpp ├── client │ ├── TracyArmCpuTable.hpp │ ├── TracyCallstack.cpp │ ├── TracyCallstack.h │ ├── TracyCallstack.hpp │ ├── TracyDxt1.cpp │ ├── TracyDxt1.hpp │ ├── TracyFastVector.hpp │ ├── TracyLock.hpp │ ├── TracyProfiler.cpp │ ├── TracyProfiler.hpp │ ├── TracyRingBuffer.hpp │ ├── TracyScoped.hpp │ ├── TracySysTime.cpp │ ├── TracySysTime.hpp │ ├── TracySysTrace.cpp │ ├── TracySysTrace.hpp │ ├── TracySysTracePayload.hpp │ ├── TracyThread.hpp │ ├── tracy_concurrentqueue.h │ ├── tracy_rpmalloc.cpp │ └── tracy_rpmalloc.hpp ├── common │ ├── TracyAlign.hpp │ ├── TracyAlloc.hpp │ ├── TracyApi.h │ ├── TracyColor.hpp │ ├── TracyForceInline.hpp │ ├── TracyMutex.hpp │ ├── TracyProtocol.hpp │ ├── TracyQueue.hpp │ ├── TracySocket.cpp │ ├── TracySocket.hpp │ ├── TracySystem.cpp │ ├── TracySystem.hpp │ ├── src-from-vcxproj.mk │ ├── tracy_lz4.cpp │ ├── tracy_lz4.hpp │ ├── tracy_lz4hc.cpp │ ├── tracy_lz4hc.hpp │ ├── unix-release.mk │ └── unix.mk └── libbacktrace │ ├── LICENSE │ ├── alloc.cpp │ ├── backtrace.hpp │ ├── config.h │ ├── dwarf.cpp │ ├── elf.cpp │ ├── fileline.cpp │ ├── filenames.hpp │ ├── internal.hpp │ ├── macho.cpp │ ├── mmapio.cpp │ ├── posix.cpp │ ├── sort.cpp │ └── state.cpp └── tracy.zig /.gitattributes: -------------------------------------------------------------------------------- 1 | # See https://git-scm.com/docs/gitattributes 2 | # See https://help.github.com/articles/dealing-with-line-endings/ 3 | 4 | # Default behavior, if core.autocrlf is unset. 5 | * text=auto 6 | 7 | # Files to be converted to native line endings on checkout. 8 | *.cpp text 9 | *.h text 10 | 11 | # Text files to always have CRLF (dos) line endings on checkout. 12 | *.bat text eol=crlf 13 | 14 | # Text files to always have LF (unix) line endings on checkout. 15 | *.sh text eol=lf 16 | *.zig text eol=lf 17 | 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | zig-cache/ 2 | zig-out/ 3 | build_runner.zig 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Martin Wickham 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## How to use this binding 2 | 3 | 1. Copy build_tracy.zig and tracy.zig into your project. 4 | 2. In build.zig, import build_tracy.zig and call `link`. 5 | 3. If tracy should be enabled, pass the path to the folder containing TracyClient.cpp. 6 | 4. Otherwise, pass null as the path to tracy. 7 | 5. In your source, use the bindings in tracy.zig to mark zones. All of the api points continue to exist when tracy is disabled, but they are empty. 8 | 9 | For your convenience, the minimal source needed to build tracy client v0.7.8 is vendored in this repo. 10 | The tracy server and further documentation are available in the official tracy repo: 11 | 12 | https://github.com/wolfpld/tracy 13 | -------------------------------------------------------------------------------- /build_tracy.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const Builder = std.build.Builder; 3 | const LibExeObjStep = std.build.LibExeObjStep; 4 | 5 | /// Build required sources, use tracy by importing "tracy.zig" 6 | pub fn link(b: *Builder, step: *LibExeObjStep, opt_path: ?[]const u8) void { 7 | const step_options = b.addOptions(); 8 | step.addOptions("build_options", step_options); 9 | step_options.addOption(bool, "tracy_enabled", opt_path != null); 10 | 11 | if (opt_path) |path| { 12 | step.addIncludePath(path); 13 | const tracy_client_source_path = std.fs.path.join(step.builder.allocator, &.{ path, "TracyClient.cpp" }) catch unreachable; 14 | step.addCSourceFile(tracy_client_source_path, &[_][]const u8{ 15 | "-DTRACY_ENABLE", 16 | // MinGW doesn't have all the newfangled windows features, 17 | // so we need to pretend to have an older windows version. 18 | "-D_WIN32_WINNT=0x601", 19 | "-fno-sanitize=undefined", 20 | }); 21 | 22 | step.linkLibC(); 23 | step.linkSystemLibrary("c++"); 24 | 25 | if (step.target.isWindows()) { 26 | step.linkSystemLibrary("Advapi32"); 27 | step.linkSystemLibrary("User32"); 28 | step.linkSystemLibrary("Ws2_32"); 29 | step.linkSystemLibrary("DbgHelp"); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tracy-0.7.8/.gitignore: -------------------------------------------------------------------------------- 1 | .vs 2 | *.opendb 3 | *.db 4 | *.vcxproj.user 5 | x64 6 | Release 7 | Debug 8 | _build 9 | _compiler 10 | tools/* 11 | *.d 12 | *.o 13 | *.so 14 | *.swp 15 | imgui.ini 16 | test/tracy_test 17 | test/tracy_test.exe 18 | */build/unix/*-* 19 | manual/t*.aux 20 | manual/t*.log 21 | manual/t*.out 22 | manual/t*.pdf 23 | manual/t*.synctex.gz 24 | manual/t*.toc 25 | manual/t*.bbl 26 | manual/t*.blg 27 | profiler/build/win32/packages 28 | profiler/build/win32/Tracy.aps 29 | # include the vcpkg install script but not the files it produces 30 | vcpkg/* 31 | !vcpkg/install_vcpkg_dependencies.bat 32 | .deps/ 33 | .dirstamp 34 | .vscode/ 35 | 36 | /_*/** 37 | /**/__pycache__/** 38 | extra/vswhere.exe 39 | extra/tracy-build 40 | -------------------------------------------------------------------------------- /tracy-0.7.8/AUTHORS: -------------------------------------------------------------------------------- 1 | Bartosz Taudul 2 | Kamil Klimek (initial find zone implementation) 3 | Bartosz Szreder (view/worker split) 4 | Arvid Gerstmann (compatibility fixes) 5 | Rokas Kupstys (compatibility fixes, initial CI work, MingW support) 6 | Till Rathmann (DLL support) 7 | Sherief Farouk (compatibility fixes) 8 | Dedmen Miller (find zone bug fixes, improvements) 9 | Michał Cichoń (OSX call stack decoding backport) 10 | Thales Sabino (OpenCL support) 11 | Andrew Depke (Direct3D 12 support) 12 | Simonas Kazlauskas (OSX CI, external bindings) 13 | Jakub Žádník (csvexport utility) 14 | Andrey Voroshilov (multi-DLL fixes) 15 | Benoit Jacob (Android improvements) 16 | David Farrel (Direct3D 11 support) 17 | -------------------------------------------------------------------------------- /tracy-0.7.8/LICENSE: -------------------------------------------------------------------------------- 1 | Tracy Profiler (https://github.com/wolfpld/tracy) is licensed under the 2 | 3-clause BSD license. 3 | 4 | Copyright (c) 2017-2021, Bartosz Taudul 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | * Neither the name of the nor the 15 | names of its contributors may be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /tracy-0.7.8/README.md: -------------------------------------------------------------------------------- 1 | # Tracy Profiler 2 | 3 | [![Sponsor](.github/sponsor.png)](https://github.com/sponsors/wolfpld/) 4 | 5 | ### A real time, nanosecond resolution, remote telemetry, hybrid frame and sampling profiler for games and other applications. 6 | 7 | Tracy supports profiling CPU (C, C++11, Lua), GPU (OpenGL, Vulkan, OpenCL, Direct3D 11/12), memory, locks, context switches, per-frame screenshots and more. 8 | 9 | For usage **and build process** instructions, consult the user manual [at the following address](https://github.com/wolfpld/tracy/releases). 10 | 11 | ![](doc/profiler.png) 12 | 13 | ![](doc/profiler2.png) 14 | 15 | [Changelog](NEWS) 16 | 17 | [Introduction to Tracy Profiler v0.2](https://www.youtube.com/watch?v=fB5B46lbapc) 18 | [New features in Tracy Profiler v0.3](https://www.youtube.com/watch?v=3SXpDpDh2Uo) 19 | [New features in Tracy Profiler v0.4](https://www.youtube.com/watch?v=eAkgkaO8B9o) 20 | [New features in Tracy Profiler v0.5](https://www.youtube.com/watch?v=P6E7qLMmzTQ) 21 | [New features in Tracy Profiler v0.6](https://www.youtube.com/watch?v=uJkrFgriuOo) 22 | [New features in Tracy Profiler v0.7](https://www.youtube.com/watch?v=_hU7vw00MZ4) 23 | -------------------------------------------------------------------------------- /tracy-0.7.8/TODO: -------------------------------------------------------------------------------- 1 | "Would be nice to have" list for 1.0 release: 2 | ============================================= 3 | 4 | * Pack queue items tightly in the queues. 5 | * Use level-of-detail system for plots. 6 | * Use per-thread lock data structures. 7 | * Use DTrace for BSD/OSX context switch capture. 8 | -------------------------------------------------------------------------------- /tracy-0.7.8/Tracy.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __TRACY_HPP__ 2 | #define __TRACY_HPP__ 3 | 4 | #include "common/TracyColor.hpp" 5 | #include "common/TracySystem.hpp" 6 | 7 | #ifndef TRACY_ENABLE 8 | 9 | #define ZoneNamed(x,y) 10 | #define ZoneNamedN(x,y,z) 11 | #define ZoneNamedC(x,y,z) 12 | #define ZoneNamedNC(x,y,z,w) 13 | 14 | #define ZoneTransient(x,y) 15 | #define ZoneTransientN(x,y,z) 16 | 17 | #define ZoneScoped 18 | #define ZoneScopedN(x) 19 | #define ZoneScopedC(x) 20 | #define ZoneScopedNC(x,y) 21 | 22 | #define ZoneText(x,y) 23 | #define ZoneTextV(x,y,z) 24 | #define ZoneName(x,y) 25 | #define ZoneNameV(x,y,z) 26 | #define ZoneColor(x) 27 | #define ZoneColorV(x,y) 28 | #define ZoneValue(x) 29 | #define ZoneValueV(x,y) 30 | #define ZoneIsActive false 31 | #define ZoneIsActiveV(x) false 32 | 33 | #define FrameMark 34 | #define FrameMarkNamed(x) 35 | #define FrameMarkStart(x) 36 | #define FrameMarkEnd(x) 37 | 38 | #define FrameImage(x,y,z,w,a) 39 | 40 | #define TracyLockable( type, varname ) type varname; 41 | #define TracyLockableN( type, varname, desc ) type varname; 42 | #define TracySharedLockable( type, varname ) type varname; 43 | #define TracySharedLockableN( type, varname, desc ) type varname; 44 | #define LockableBase( type ) type 45 | #define SharedLockableBase( type ) type 46 | #define LockMark(x) (void)x; 47 | #define LockableName(x,y,z); 48 | 49 | #define TracyPlot(x,y) 50 | #define TracyPlotConfig(x,y) 51 | 52 | #define TracyMessage(x,y) 53 | #define TracyMessageL(x) 54 | #define TracyMessageC(x,y,z) 55 | #define TracyMessageLC(x,y) 56 | #define TracyAppInfo(x,y) 57 | 58 | #define TracyAlloc(x,y) 59 | #define TracyFree(x) 60 | #define TracySecureAlloc(x,y) 61 | #define TracySecureFree(x) 62 | 63 | #define TracyAllocN(x,y,z) 64 | #define TracyFreeN(x,y) 65 | #define TracySecureAllocN(x,y,z) 66 | #define TracySecureFreeN(x,y) 67 | 68 | #define ZoneNamedS(x,y,z) 69 | #define ZoneNamedNS(x,y,z,w) 70 | #define ZoneNamedCS(x,y,z,w) 71 | #define ZoneNamedNCS(x,y,z,w,a) 72 | 73 | #define ZoneTransientS(x,y,z) 74 | #define ZoneTransientNS(x,y,z,w) 75 | 76 | #define ZoneScopedS(x) 77 | #define ZoneScopedNS(x,y) 78 | #define ZoneScopedCS(x,y) 79 | #define ZoneScopedNCS(x,y,z) 80 | 81 | #define TracyAllocS(x,y,z) 82 | #define TracyFreeS(x,y) 83 | #define TracySecureAllocS(x,y,z) 84 | #define TracySecureFreeS(x,y) 85 | 86 | #define TracyAllocNS(x,y,z,w) 87 | #define TracyFreeNS(x,y,z) 88 | #define TracySecureAllocNS(x,y,z,w) 89 | #define TracySecureFreeNS(x,y,z) 90 | 91 | #define TracyMessageS(x,y,z) 92 | #define TracyMessageLS(x,y) 93 | #define TracyMessageCS(x,y,z,w) 94 | #define TracyMessageLCS(x,y,z) 95 | 96 | #define TracyParameterRegister(x) 97 | #define TracyParameterSetup(x,y,z,w) 98 | #define TracyIsConnected false 99 | 100 | #else 101 | 102 | #include 103 | 104 | #include "client/TracyLock.hpp" 105 | #include "client/TracyProfiler.hpp" 106 | #include "client/TracyScoped.hpp" 107 | 108 | #if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK 109 | # define ZoneNamed( varname, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active ); 110 | # define ZoneNamedN( varname, name, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active ); 111 | # define ZoneNamedC( varname, color, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active ); 112 | # define ZoneNamedNC( varname, name, color, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active ); 113 | 114 | # define ZoneTransient( varname, active ) tracy::ScopedZone varname( __LINE__, __FILE__, strlen( __FILE__ ), __FUNCTION__, strlen( __FUNCTION__ ), nullptr, 0, TRACY_CALLSTACK, active ); 115 | # define ZoneTransientN( varname, name, active ) tracy::ScopedZone varname( __LINE__, __FILE__, strlen( __FILE__ ), __FUNCTION__, strlen( __FUNCTION__ ), name, strlen( name ), TRACY_CALLSTACK, active ); 116 | #else 117 | # define ZoneNamed( varname, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), active ); 118 | # define ZoneNamedN( varname, name, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), active ); 119 | # define ZoneNamedC( varname, color, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), active ); 120 | # define ZoneNamedNC( varname, name, color, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), active ); 121 | 122 | # define ZoneTransient( varname, active ) tracy::ScopedZone varname( __LINE__, __FILE__, strlen( __FILE__ ), __FUNCTION__, strlen( __FUNCTION__ ), nullptr, 0, active ); 123 | # define ZoneTransientN( varname, name, active ) tracy::ScopedZone varname( __LINE__, __FILE__, strlen( __FILE__ ), __FUNCTION__, strlen( __FUNCTION__ ), name, strlen( name ), active ); 124 | #endif 125 | 126 | #define ZoneScoped ZoneNamed( ___tracy_scoped_zone, true ) 127 | #define ZoneScopedN( name ) ZoneNamedN( ___tracy_scoped_zone, name, true ) 128 | #define ZoneScopedC( color ) ZoneNamedC( ___tracy_scoped_zone, color, true ) 129 | #define ZoneScopedNC( name, color ) ZoneNamedNC( ___tracy_scoped_zone, name, color, true ) 130 | 131 | #define ZoneText( txt, size ) ___tracy_scoped_zone.Text( txt, size ); 132 | #define ZoneTextV( varname, txt, size ) varname.Text( txt, size ); 133 | #define ZoneName( txt, size ) ___tracy_scoped_zone.Name( txt, size ); 134 | #define ZoneNameV( varname, txt, size ) varname.Name( txt, size ); 135 | #define ZoneColor( color ) ___tracy_scoped_zone.Color( color ); 136 | #define ZoneColorV( varname, color ) varname.Color( color ); 137 | #define ZoneValue( value ) ___tracy_scoped_zone.Value( value ); 138 | #define ZoneValueV( varname, value ) varname.Value( value ); 139 | #define ZoneIsActive ___tracy_scoped_zone.IsActive() 140 | #define ZoneIsActiveV( varname ) varname.IsActive() 141 | 142 | #define FrameMark tracy::Profiler::SendFrameMark( nullptr ); 143 | #define FrameMarkNamed( name ) tracy::Profiler::SendFrameMark( name ); 144 | #define FrameMarkStart( name ) tracy::Profiler::SendFrameMark( name, tracy::QueueType::FrameMarkMsgStart ); 145 | #define FrameMarkEnd( name ) tracy::Profiler::SendFrameMark( name, tracy::QueueType::FrameMarkMsgEnd ); 146 | 147 | #define FrameImage( image, width, height, offset, flip ) tracy::Profiler::SendFrameImage( image, width, height, offset, flip ); 148 | 149 | #define TracyLockable( type, varname ) tracy::Lockable varname { [] () -> const tracy::SourceLocationData* { static constexpr tracy::SourceLocationData srcloc { nullptr, #type " " #varname, __FILE__, __LINE__, 0 }; return &srcloc; }() }; 150 | #define TracyLockableN( type, varname, desc ) tracy::Lockable varname { [] () -> const tracy::SourceLocationData* { static constexpr tracy::SourceLocationData srcloc { nullptr, desc, __FILE__, __LINE__, 0 }; return &srcloc; }() }; 151 | #define TracySharedLockable( type, varname ) tracy::SharedLockable varname { [] () -> const tracy::SourceLocationData* { static constexpr tracy::SourceLocationData srcloc { nullptr, #type " " #varname, __FILE__, __LINE__, 0 }; return &srcloc; }() }; 152 | #define TracySharedLockableN( type, varname, desc ) tracy::SharedLockable varname { [] () -> const tracy::SourceLocationData* { static constexpr tracy::SourceLocationData srcloc { nullptr, desc, __FILE__, __LINE__, 0 }; return &srcloc; }() }; 153 | #define LockableBase( type ) tracy::Lockable 154 | #define SharedLockableBase( type ) tracy::SharedLockable 155 | #define LockMark( varname ) static constexpr tracy::SourceLocationData __tracy_lock_location_##varname { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; varname.Mark( &__tracy_lock_location_##varname ); 156 | #define LockableName( varname, txt, size ) varname.CustomName( txt, size ); 157 | 158 | #define TracyPlot( name, val ) tracy::Profiler::PlotData( name, val ); 159 | #define TracyPlotConfig( name, type ) tracy::Profiler::ConfigurePlot( name, type ); 160 | 161 | #define TracyAppInfo( txt, size ) tracy::Profiler::MessageAppInfo( txt, size ); 162 | 163 | #if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK 164 | # define TracyMessage( txt, size ) tracy::Profiler::Message( txt, size, TRACY_CALLSTACK ); 165 | # define TracyMessageL( txt ) tracy::Profiler::Message( txt, TRACY_CALLSTACK ); 166 | # define TracyMessageC( txt, size, color ) tracy::Profiler::MessageColor( txt, size, color, TRACY_CALLSTACK ); 167 | # define TracyMessageLC( txt, color ) tracy::Profiler::MessageColor( txt, color, TRACY_CALLSTACK ); 168 | 169 | # define TracyAlloc( ptr, size ) tracy::Profiler::MemAllocCallstack( ptr, size, TRACY_CALLSTACK, false ); 170 | # define TracyFree( ptr ) tracy::Profiler::MemFreeCallstack( ptr, TRACY_CALLSTACK, false ); 171 | # define TracySecureAlloc( ptr, size ) tracy::Profiler::MemAllocCallstack( ptr, size, TRACY_CALLSTACK, true ); 172 | # define TracySecureFree( ptr ) tracy::Profiler::MemFreeCallstack( ptr, TRACY_CALLSTACK, true ); 173 | 174 | # define TracyAllocN( ptr, size, name ) tracy::Profiler::MemAllocCallstackNamed( ptr, size, TRACY_CALLSTACK, false, name ); 175 | # define TracyFreeN( ptr, name ) tracy::Profiler::MemFreeCallstackNamed( ptr, TRACY_CALLSTACK, false, name ); 176 | # define TracySecureAllocN( ptr, size, name ) tracy::Profiler::MemAllocCallstackNamed( ptr, size, TRACY_CALLSTACK, true, name ); 177 | # define TracySecureFreeN( ptr, name ) tracy::Profiler::MemFreeCallstackNamed( ptr, TRACY_CALLSTACK, true, name ); 178 | #else 179 | # define TracyMessage( txt, size ) tracy::Profiler::Message( txt, size, 0 ); 180 | # define TracyMessageL( txt ) tracy::Profiler::Message( txt, 0 ); 181 | # define TracyMessageC( txt, size, color ) tracy::Profiler::MessageColor( txt, size, color, 0 ); 182 | # define TracyMessageLC( txt, color ) tracy::Profiler::MessageColor( txt, color, 0 ); 183 | 184 | # define TracyAlloc( ptr, size ) tracy::Profiler::MemAlloc( ptr, size, false ); 185 | # define TracyFree( ptr ) tracy::Profiler::MemFree( ptr, false ); 186 | # define TracySecureAlloc( ptr, size ) tracy::Profiler::MemAlloc( ptr, size, true ); 187 | # define TracySecureFree( ptr ) tracy::Profiler::MemFree( ptr, true ); 188 | 189 | # define TracyAllocN( ptr, size, name ) tracy::Profiler::MemAllocNamed( ptr, size, false, name ); 190 | # define TracyFreeN( ptr, name ) tracy::Profiler::MemFreeNamed( ptr, false, name ); 191 | # define TracySecureAllocN( ptr, size, name ) tracy::Profiler::MemAllocNamed( ptr, size, true, name ); 192 | # define TracySecureFreeN( ptr, name ) tracy::Profiler::MemFreeNamed( ptr, true, name ); 193 | #endif 194 | 195 | #ifdef TRACY_HAS_CALLSTACK 196 | # define ZoneNamedS( varname, depth, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), depth, active ); 197 | # define ZoneNamedNS( varname, name, depth, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), depth, active ); 198 | # define ZoneNamedCS( varname, color, depth, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), depth, active ); 199 | # define ZoneNamedNCS( varname, name, color, depth, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), depth, active ); 200 | 201 | # define ZoneTransientS( varname, depth, active ) tracy::ScopedZone varname( __LINE__, __FILE__, strlen( __FILE__ ), __FUNCTION__, strlen( __FUNCTION__ ), nullptr, 0, depth, active ); 202 | # define ZoneTransientNS( varname, name, depth, active ) tracy::ScopedZone varname( __LINE__, __FILE__, strlen( __FILE__ ), __FUNCTION__, strlen( __FUNCTION__ ), name, strlen( name ), depth, active ); 203 | 204 | # define ZoneScopedS( depth ) ZoneNamedS( ___tracy_scoped_zone, depth, true ) 205 | # define ZoneScopedNS( name, depth ) ZoneNamedNS( ___tracy_scoped_zone, name, depth, true ) 206 | # define ZoneScopedCS( color, depth ) ZoneNamedCS( ___tracy_scoped_zone, color, depth, true ) 207 | # define ZoneScopedNCS( name, color, depth ) ZoneNamedNCS( ___tracy_scoped_zone, name, color, depth, true ) 208 | 209 | # define TracyAllocS( ptr, size, depth ) tracy::Profiler::MemAllocCallstack( ptr, size, depth, false ); 210 | # define TracyFreeS( ptr, depth ) tracy::Profiler::MemFreeCallstack( ptr, depth, false ); 211 | # define TracySecureAllocS( ptr, size, depth ) tracy::Profiler::MemAllocCallstack( ptr, size, depth, true ); 212 | # define TracySecureFreeS( ptr, depth ) tracy::Profiler::MemFreeCallstack( ptr, depth, true ); 213 | 214 | # define TracyAllocNS( ptr, size, depth, name ) tracy::Profiler::MemAllocCallstackNamed( ptr, size, depth, false, name ); 215 | # define TracyFreeNS( ptr, depth, name ) tracy::Profiler::MemFreeCallstackNamed( ptr, depth, false, name ); 216 | # define TracySecureAllocNS( ptr, size, depth, name ) tracy::Profiler::MemAllocCallstackNamed( ptr, size, depth, true, name ); 217 | # define TracySecureFreeNS( ptr, depth, name ) tracy::Profiler::MemFreeCallstackNamed( ptr, depth, true, name ); 218 | 219 | # define TracyMessageS( txt, size, depth ) tracy::Profiler::Message( txt, size, depth ); 220 | # define TracyMessageLS( txt, depth ) tracy::Profiler::Message( txt, depth ); 221 | # define TracyMessageCS( txt, size, color, depth ) tracy::Profiler::MessageColor( txt, size, color, depth ); 222 | # define TracyMessageLCS( txt, color, depth ) tracy::Profiler::MessageColor( txt, color, depth ); 223 | #else 224 | # define ZoneNamedS( varname, depth, active ) ZoneNamed( varname, active ) 225 | # define ZoneNamedNS( varname, name, depth, active ) ZoneNamedN( varname, name, active ) 226 | # define ZoneNamedCS( varname, color, depth, active ) ZoneNamedC( varname, color, active ) 227 | # define ZoneNamedNCS( varname, name, color, depth, active ) ZoneNamedNC( varname, name, color, active ) 228 | 229 | # define ZoneTransientS( varname, depth, active ) ZoneTransient( varname, active ) 230 | # define ZoneTransientNS( varname, name, depth, active ) ZoneTransientN( varname, name, active ) 231 | 232 | # define ZoneScopedS( depth ) ZoneScoped 233 | # define ZoneScopedNS( name, depth ) ZoneScopedN( name ) 234 | # define ZoneScopedCS( color, depth ) ZoneScopedC( color ) 235 | # define ZoneScopedNCS( name, color, depth ) ZoneScopedNC( name, color ) 236 | 237 | # define TracyAllocS( ptr, size, depth ) TracyAlloc( ptr, size ) 238 | # define TracyFreeS( ptr, depth ) TracyFree( ptr ) 239 | # define TracySecureAllocS( ptr, size, depth ) TracySecureAlloc( ptr, size ) 240 | # define TracySecureFreeS( ptr, depth ) TracySecureFree( ptr ) 241 | 242 | # define TracyAllocNS( ptr, size, depth, name ) TracyAlloc( ptr, size, name ) 243 | # define TracyFreeNS( ptr, depth, name ) TracyFree( ptr, name ) 244 | # define TracySecureAllocNS( ptr, size, depth, name ) TracySecureAlloc( ptr, size, name ) 245 | # define TracySecureFreeNS( ptr, depth, name ) TracySecureFree( ptr, name ) 246 | 247 | # define TracyMessageS( txt, size, depth ) TracyMessage( txt, size ) 248 | # define TracyMessageLS( txt, depth ) TracyMessageL( txt ) 249 | # define TracyMessageCS( txt, size, color, depth ) TracyMessageC( txt, size, color ) 250 | # define TracyMessageLCS( txt, color, depth ) TracyMessageLC( txt, color ) 251 | #endif 252 | 253 | #define TracyParameterRegister( cb ) tracy::Profiler::ParameterRegister( cb ); 254 | #define TracyParameterSetup( idx, name, isBool, val ) tracy::Profiler::ParameterSetup( idx, name, isBool, val ); 255 | #define TracyIsConnected tracy::GetProfiler().IsConnected() 256 | 257 | #endif 258 | 259 | #endif 260 | -------------------------------------------------------------------------------- /tracy-0.7.8/TracyC.h: -------------------------------------------------------------------------------- 1 | #ifndef __TRACYC_HPP__ 2 | #define __TRACYC_HPP__ 3 | 4 | #include 5 | #include 6 | 7 | #include "client/TracyCallstack.h" 8 | #include "common/TracyApi.h" 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | TRACY_API void ___tracy_set_thread_name( const char* name ); 15 | 16 | #define TracyCSetThreadName( name ) ___tracy_set_thread_name( name ); 17 | 18 | 19 | #ifndef TRACY_ENABLE 20 | 21 | typedef const void* TracyCZoneCtx; 22 | 23 | #define TracyCZone(c,x) 24 | #define TracyCZoneN(c,x,y) 25 | #define TracyCZoneC(c,x,y) 26 | #define TracyCZoneNC(c,x,y,z) 27 | #define TracyCZoneEnd(c) 28 | #define TracyCZoneText(c,x,y) 29 | #define TracyCZoneName(c,x,y) 30 | #define TracyCZoneColor(c,x) 31 | #define TracyCZoneValue(c,x) 32 | 33 | #define TracyCAlloc(x,y) 34 | #define TracyCFree(x) 35 | #define TracyCSecureAlloc(x,y) 36 | #define TracyCSecureFree(x) 37 | 38 | #define TracyCAllocN(x,y,z) 39 | #define TracyCFreeN(x,y) 40 | #define TracyCSecureAllocN(x,y,z) 41 | #define TracyCSecureFreeN(x,y) 42 | 43 | #define TracyCFrameMark 44 | #define TracyCFrameMarkNamed(x) 45 | #define TracyCFrameMarkStart(x) 46 | #define TracyCFrameMarkEnd(x) 47 | #define TracyCFrameImage(x,y,z,w,a) 48 | 49 | #define TracyCPlot(x,y) 50 | #define TracyCMessage(x,y) 51 | #define TracyCMessageL(x) 52 | #define TracyCMessageC(x,y,z) 53 | #define TracyCMessageLC(x,y) 54 | #define TracyCAppInfo(x,y) 55 | 56 | #define TracyCZoneS(x,y,z) 57 | #define TracyCZoneNS(x,y,z,w) 58 | #define TracyCZoneCS(x,y,z,w) 59 | #define TracyCZoneNCS(x,y,z,w,a) 60 | 61 | #define TracyCAllocS(x,y,z) 62 | #define TracyCFreeS(x,y) 63 | #define TracyCSecureAllocS(x,y,z) 64 | #define TracyCSecureFreeS(x,y) 65 | 66 | #define TracyCAllocNS(x,y,z,w) 67 | #define TracyCFreeNS(x,y,z) 68 | #define TracyCSecureAllocNS(x,y,z,w) 69 | #define TracyCSecureFreeNS(x,y,z) 70 | 71 | #define TracyCMessageS(x,y,z) 72 | #define TracyCMessageLS(x,y) 73 | #define TracyCMessageCS(x,y,z,w) 74 | #define TracyCMessageLCS(x,y,z) 75 | 76 | #else 77 | 78 | #ifndef TracyConcat 79 | # define TracyConcat(x,y) TracyConcatIndirect(x,y) 80 | #endif 81 | #ifndef TracyConcatIndirect 82 | # define TracyConcatIndirect(x,y) x##y 83 | #endif 84 | 85 | struct ___tracy_source_location_data 86 | { 87 | const char* name; 88 | const char* function; 89 | const char* file; 90 | uint32_t line; 91 | uint32_t color; 92 | }; 93 | 94 | struct ___tracy_c_zone_context 95 | { 96 | uint32_t id; 97 | int active; 98 | }; 99 | 100 | // Some containers don't support storing const types. 101 | // This struct, as visible to user, is immutable, so treat it as if const was declared here. 102 | typedef /*const*/ struct ___tracy_c_zone_context TracyCZoneCtx; 103 | 104 | TRACY_API void ___tracy_init_thread(void); 105 | TRACY_API uint64_t ___tracy_alloc_srcloc( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz ); 106 | TRACY_API uint64_t ___tracy_alloc_srcloc_name( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const char* name, size_t nameSz ); 107 | 108 | TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin( const struct ___tracy_source_location_data* srcloc, int active ); 109 | TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_callstack( const struct ___tracy_source_location_data* srcloc, int depth, int active ); 110 | TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc( uint64_t srcloc, int active ); 111 | TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc_callstack( uint64_t srcloc, int depth, int active ); 112 | TRACY_API void ___tracy_emit_zone_end( TracyCZoneCtx ctx ); 113 | TRACY_API void ___tracy_emit_zone_text( TracyCZoneCtx ctx, const char* txt, size_t size ); 114 | TRACY_API void ___tracy_emit_zone_name( TracyCZoneCtx ctx, const char* txt, size_t size ); 115 | TRACY_API void ___tracy_emit_zone_color( TracyCZoneCtx ctx, uint32_t color ); 116 | TRACY_API void ___tracy_emit_zone_value( TracyCZoneCtx ctx, uint64_t value ); 117 | 118 | #if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK 119 | # define TracyCZone( ctx, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { NULL, __func__, __FILE__, (uint32_t)__LINE__, 0 }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active ); 120 | # define TracyCZoneN( ctx, name, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { name, __func__, __FILE__, (uint32_t)__LINE__, 0 }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active ); 121 | # define TracyCZoneC( ctx, color, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { NULL, __func__, __FILE__, (uint32_t)__LINE__, color }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active ); 122 | # define TracyCZoneNC( ctx, name, color, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { name, __func__, __FILE__, (uint32_t)__LINE__, color }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active ); 123 | #else 124 | # define TracyCZone( ctx, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { NULL, __func__, __FILE__, (uint32_t)__LINE__, 0 }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin( &TracyConcat(__tracy_source_location,__LINE__), active ); 125 | # define TracyCZoneN( ctx, name, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { name, __func__, __FILE__, (uint32_t)__LINE__, 0 }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin( &TracyConcat(__tracy_source_location,__LINE__), active ); 126 | # define TracyCZoneC( ctx, color, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { NULL, __func__, __FILE__, (uint32_t)__LINE__, color }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin( &TracyConcat(__tracy_source_location,__LINE__), active ); 127 | # define TracyCZoneNC( ctx, name, color, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { name, __func__, __FILE__, (uint32_t)__LINE__, color }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin( &TracyConcat(__tracy_source_location,__LINE__), active ); 128 | #endif 129 | 130 | #define TracyCZoneEnd( ctx ) ___tracy_emit_zone_end( ctx ); 131 | 132 | #define TracyCZoneText( ctx, txt, size ) ___tracy_emit_zone_text( ctx, txt, size ); 133 | #define TracyCZoneName( ctx, txt, size ) ___tracy_emit_zone_name( ctx, txt, size ); 134 | #define TracyCZoneColor( ctx, color ) ___tracy_emit_zone_color( ctx, color ); 135 | #define TracyCZoneValue( ctx, value ) ___tracy_emit_zone_value( ctx, value ); 136 | 137 | 138 | TRACY_API void ___tracy_emit_memory_alloc( const void* ptr, size_t size, int secure ); 139 | TRACY_API void ___tracy_emit_memory_alloc_callstack( const void* ptr, size_t size, int depth, int secure ); 140 | TRACY_API void ___tracy_emit_memory_free( const void* ptr, int secure ); 141 | TRACY_API void ___tracy_emit_memory_free_callstack( const void* ptr, int depth, int secure ); 142 | TRACY_API void ___tracy_emit_memory_alloc_named( const void* ptr, size_t size, int secure, const char* name ); 143 | TRACY_API void ___tracy_emit_memory_alloc_callstack_named( const void* ptr, size_t size, int depth, int secure, const char* name ); 144 | TRACY_API void ___tracy_emit_memory_free_named( const void* ptr, int secure, const char* name ); 145 | TRACY_API void ___tracy_emit_memory_free_callstack_named( const void* ptr, int depth, int secure, const char* name ); 146 | 147 | TRACY_API void ___tracy_emit_message( const char* txt, size_t size, int callstack ); 148 | TRACY_API void ___tracy_emit_messageL( const char* txt, int callstack ); 149 | TRACY_API void ___tracy_emit_messageC( const char* txt, size_t size, uint32_t color, int callstack ); 150 | TRACY_API void ___tracy_emit_messageLC( const char* txt, uint32_t color, int callstack ); 151 | 152 | #if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK 153 | # define TracyCAlloc( ptr, size ) ___tracy_emit_memory_alloc_callstack( ptr, size, TRACY_CALLSTACK, 0 ) 154 | # define TracyCFree( ptr ) ___tracy_emit_memory_free_callstack( ptr, TRACY_CALLSTACK, 0 ) 155 | # define TracyCSecureAlloc( ptr, size ) ___tracy_emit_memory_alloc_callstack( ptr, size, TRACY_CALLSTACK, 1 ) 156 | # define TracyCSecureFree( ptr ) ___tracy_emit_memory_free_callstack( ptr, TRACY_CALLSTACK, 1 ) 157 | 158 | # define TracyCAllocN( ptr, size, name ) ___tracy_emit_memory_alloc_callstack_named( ptr, size, TRACY_CALLSTACK, 0, name ) 159 | # define TracyCFreeN( ptr, name ) ___tracy_emit_memory_free_callstack_named( ptr, TRACY_CALLSTACK, 0, name ) 160 | # define TracyCSecureAllocN( ptr, size, name ) ___tracy_emit_memory_alloc_callstack_named( ptr, size, TRACY_CALLSTACK, 1, name ) 161 | # define TracyCSecureFreeN( ptr, name ) ___tracy_emit_memory_free_callstack_named( ptr, TRACY_CALLSTACK, 1, name ) 162 | 163 | # define TracyCMessage( txt, size ) ___tracy_emit_message( txt, size, TRACY_CALLSTACK ); 164 | # define TracyCMessageL( txt ) ___tracy_emit_messageL( txt, TRACY_CALLSTACK ); 165 | # define TracyCMessageC( txt, size, color ) ___tracy_emit_messageC( txt, size, color, TRACY_CALLSTACK ); 166 | # define TracyCMessageLC( txt, color ) ___tracy_emit_messageLC( txt, color, TRACY_CALLSTACK ); 167 | #else 168 | # define TracyCAlloc( ptr, size ) ___tracy_emit_memory_alloc( ptr, size, 0 ); 169 | # define TracyCFree( ptr ) ___tracy_emit_memory_free( ptr, 0 ); 170 | # define TracyCSecureAlloc( ptr, size ) ___tracy_emit_memory_alloc( ptr, size, 1 ); 171 | # define TracyCSecureFree( ptr ) ___tracy_emit_memory_free( ptr, 1 ); 172 | 173 | # define TracyCAllocN( ptr, size, name ) ___tracy_emit_memory_alloc_named( ptr, size, 0, name ); 174 | # define TracyCFreeN( ptr, name ) ___tracy_emit_memory_free_named( ptr, 0, name ); 175 | # define TracyCSecureAllocN( ptr, size, name ) ___tracy_emit_memory_alloc_named( ptr, size, 1, name ); 176 | # define TracyCSecureFreeN( ptr, name ) ___tracy_emit_memory_free_named( ptr, 1, name ); 177 | 178 | # define TracyCMessage( txt, size ) ___tracy_emit_message( txt, size, 0 ); 179 | # define TracyCMessageL( txt ) ___tracy_emit_messageL( txt, 0 ); 180 | # define TracyCMessageC( txt, size, color ) ___tracy_emit_messageC( txt, size, color, 0 ); 181 | # define TracyCMessageLC( txt, color ) ___tracy_emit_messageLC( txt, color, 0 ); 182 | #endif 183 | 184 | 185 | TRACY_API void ___tracy_emit_frame_mark( const char* name ); 186 | TRACY_API void ___tracy_emit_frame_mark_start( const char* name ); 187 | TRACY_API void ___tracy_emit_frame_mark_end( const char* name ); 188 | TRACY_API void ___tracy_emit_frame_image( const void* image, uint16_t w, uint16_t h, uint8_t offset, int flip ); 189 | 190 | #define TracyCFrameMark ___tracy_emit_frame_mark( 0 ); 191 | #define TracyCFrameMarkNamed( name ) ___tracy_emit_frame_mark( name ); 192 | #define TracyCFrameMarkStart( name ) ___tracy_emit_frame_mark_start( name ); 193 | #define TracyCFrameMarkEnd( name ) ___tracy_emit_frame_mark_end( name ); 194 | #define TracyCFrameImage( image, width, height, offset, flip ) ___tracy_emit_frame_image( image, width, height, offset, flip ); 195 | 196 | 197 | TRACY_API void ___tracy_emit_plot( const char* name, double val ); 198 | TRACY_API void ___tracy_emit_message_appinfo( const char* txt, size_t size ); 199 | 200 | #define TracyCPlot( name, val ) ___tracy_emit_plot( name, val ); 201 | #define TracyCAppInfo( txt, color ) ___tracy_emit_message_appinfo( txt, color ); 202 | 203 | 204 | #ifdef TRACY_HAS_CALLSTACK 205 | # define TracyCZoneS( ctx, depth, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { NULL, __func__, __FILE__, (uint32_t)__LINE__, 0 }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), depth, active ); 206 | # define TracyCZoneNS( ctx, name, depth, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { name, __func__, __FILE__, (uint32_t)__LINE__, 0 }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), depth, active ); 207 | # define TracyCZoneCS( ctx, color, depth, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { NULL, __func__, __FILE__, (uint32_t)__LINE__, color }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), depth, active ); 208 | # define TracyCZoneNCS( ctx, name, color, depth, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { name, __func__, __FILE__, (uint32_t)__LINE__, color }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), depth, active ); 209 | 210 | # define TracyCAllocS( ptr, size, depth ) ___tracy_emit_memory_alloc_callstack( ptr, size, depth, 0 ) 211 | # define TracyCFreeS( ptr, depth ) ___tracy_emit_memory_free_callstack( ptr, depth, 0 ) 212 | # define TracyCSecureAllocS( ptr, size, depth ) ___tracy_emit_memory_alloc_callstack( ptr, size, depth, 1 ) 213 | # define TracyCSecureFreeS( ptr, depth ) ___tracy_emit_memory_free_callstack( ptr, depth, 1 ) 214 | 215 | # define TracyCAllocNS( ptr, size, depth, name ) ___tracy_emit_memory_alloc_callstack_named( ptr, size, depth, 0, name ) 216 | # define TracyCFreeNS( ptr, depth, name ) ___tracy_emit_memory_free_callstack_named( ptr, depth, 0, name ) 217 | # define TracyCSecureAllocNS( ptr, size, depth, name ) ___tracy_emit_memory_alloc_callstack_named( ptr, size, depth, 1, name ) 218 | # define TracyCSecureFreeNS( ptr, depth, name ) ___tracy_emit_memory_free_callstack_named( ptr, depth, 1, name ) 219 | 220 | # define TracyCMessageS( txt, size, depth ) ___tracy_emit_message( txt, size, depth ); 221 | # define TracyCMessageLS( txt, depth ) ___tracy_emit_messageL( txt, depth ); 222 | # define TracyCMessageCS( txt, size, color, depth ) ___tracy_emit_messageC( txt, size, color, depth ); 223 | # define TracyCMessageLCS( txt, color, depth ) ___tracy_emit_messageLC( txt, color, depth ); 224 | #else 225 | # define TracyCZoneS( ctx, depth, active ) TracyCZone( ctx, active ) 226 | # define TracyCZoneNS( ctx, name, depth, active ) TracyCZoneN( ctx, name, active ) 227 | # define TracyCZoneCS( ctx, color, depth, active ) TracyCZoneC( ctx, color, active ) 228 | # define TracyCZoneNCS( ctx, name, color, depth, active ) TracyCZoneNC( ctx, name, color, active ) 229 | 230 | # define TracyCAllocS( ptr, size, depth ) TracyCAlloc( ptr, size ) 231 | # define TracyCFreeS( ptr, depth ) TracyCFree( ptr ) 232 | # define TracyCSecureAllocS( ptr, size, depth ) TracyCSecureAlloc( ptr, size ) 233 | # define TracyCSecureFreeS( ptr, depth ) TracyCSecureFree( ptr ) 234 | 235 | # define TracyCAllocNS( ptr, size, depth, name ) TracyCAllocN( ptr, size, name ) 236 | # define TracyCFreeNS( ptr, depth, name ) TracyCFreeN( ptr, name ) 237 | # define TracyCSecureAllocNS( ptr, size, depth, name ) TracyCSecureAllocN( ptr, size, name ) 238 | # define TracyCSecureFreeNS( ptr, depth, name ) TracyCSecureFreeN( ptr, name ) 239 | 240 | # define TracyCMessageS( txt, size, depth ) TracyCMessage( txt, size ) 241 | # define TracyCMessageLS( txt, depth ) TracyCMessageL( txt ) 242 | # define TracyCMessageCS( txt, size, color, depth ) TracyCMessageC( txt, size, color ) 243 | # define TracyCMessageLCS( txt, color, depth ) TracyCMessageLC( txt, color ) 244 | #endif 245 | 246 | #endif 247 | 248 | #ifdef __cplusplus 249 | } 250 | #endif 251 | 252 | #endif 253 | -------------------------------------------------------------------------------- /tracy-0.7.8/TracyClient.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Tracy profiler 3 | // ---------------- 4 | // 5 | // For fast integration, compile and 6 | // link with this source file (and none 7 | // other) in your executable (or in the 8 | // main DLL / shared object on multi-DLL 9 | // projects). 10 | // 11 | 12 | // Define TRACY_ENABLE to enable profiler. 13 | 14 | #include "common/TracySystem.cpp" 15 | 16 | #ifdef TRACY_ENABLE 17 | 18 | #ifdef _MSC_VER 19 | # pragma warning(push, 0) 20 | #endif 21 | 22 | #include "common/tracy_lz4.cpp" 23 | #include "client/TracyProfiler.cpp" 24 | #include "client/TracyCallstack.cpp" 25 | #include "client/TracySysTime.cpp" 26 | #include "client/TracySysTrace.cpp" 27 | #include "common/TracySocket.cpp" 28 | #include "client/tracy_rpmalloc.cpp" 29 | #include "client/TracyDxt1.cpp" 30 | 31 | #if TRACY_HAS_CALLSTACK == 2 || TRACY_HAS_CALLSTACK == 3 || TRACY_HAS_CALLSTACK == 4 || TRACY_HAS_CALLSTACK == 6 32 | # include "libbacktrace/alloc.cpp" 33 | # include "libbacktrace/dwarf.cpp" 34 | # include "libbacktrace/fileline.cpp" 35 | # include "libbacktrace/mmapio.cpp" 36 | # include "libbacktrace/posix.cpp" 37 | # include "libbacktrace/sort.cpp" 38 | # include "libbacktrace/state.cpp" 39 | # if TRACY_HAS_CALLSTACK == 4 40 | # include "libbacktrace/macho.cpp" 41 | # else 42 | # include "libbacktrace/elf.cpp" 43 | # endif 44 | #endif 45 | 46 | #ifdef _MSC_VER 47 | # pragma comment(lib, "ws2_32.lib") 48 | # pragma comment(lib, "dbghelp.lib") 49 | # pragma comment(lib, "advapi32.lib") 50 | # pragma comment(lib, "user32.lib") 51 | # pragma warning(pop) 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /tracy-0.7.8/TracyLua.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __TRACYLUA_HPP__ 2 | #define __TRACYLUA_HPP__ 3 | 4 | // Include this file after you include lua headers. 5 | 6 | #ifndef TRACY_ENABLE 7 | 8 | #include 9 | 10 | namespace tracy 11 | { 12 | 13 | namespace detail 14 | { 15 | static inline int noop( lua_State* L ) { return 0; } 16 | } 17 | 18 | static inline void LuaRegister( lua_State* L ) 19 | { 20 | lua_newtable( L ); 21 | lua_pushcfunction( L, detail::noop ); 22 | lua_setfield( L, -2, "ZoneBegin" ); 23 | lua_pushcfunction( L, detail::noop ); 24 | lua_setfield( L, -2, "ZoneBeginN" ); 25 | lua_pushcfunction( L, detail::noop ); 26 | lua_setfield( L, -2, "ZoneBeginS" ); 27 | lua_pushcfunction( L, detail::noop ); 28 | lua_setfield( L, -2, "ZoneBeginNS" ); 29 | lua_pushcfunction( L, detail::noop ); 30 | lua_setfield( L, -2, "ZoneEnd" ); 31 | lua_pushcfunction( L, detail::noop ); 32 | lua_setfield( L, -2, "ZoneText" ); 33 | lua_pushcfunction( L, detail::noop ); 34 | lua_setfield( L, -2, "ZoneName" ); 35 | lua_pushcfunction( L, detail::noop ); 36 | lua_setfield( L, -2, "Message" ); 37 | lua_setglobal( L, "tracy" ); 38 | } 39 | 40 | static inline char* FindEnd( char* ptr ) 41 | { 42 | unsigned int cnt = 1; 43 | while( cnt != 0 ) 44 | { 45 | if( *ptr == '(' ) cnt++; 46 | else if( *ptr == ')' ) cnt--; 47 | ptr++; 48 | } 49 | return ptr; 50 | } 51 | 52 | static inline void LuaRemove( char* script ) 53 | { 54 | while( *script ) 55 | { 56 | if( strncmp( script, "tracy.", 6 ) == 0 ) 57 | { 58 | if( strncmp( script + 6, "Zone", 4 ) == 0 ) 59 | { 60 | if( strncmp( script + 10, "End()", 5 ) == 0 ) 61 | { 62 | memset( script, ' ', 15 ); 63 | script += 15; 64 | } 65 | else if( strncmp( script + 10, "Begin()", 7 ) == 0 ) 66 | { 67 | memset( script, ' ', 17 ); 68 | script += 17; 69 | } 70 | else if( strncmp( script + 10, "Text(", 5 ) == 0 ) 71 | { 72 | auto end = FindEnd( script + 15 ); 73 | memset( script, ' ', end - script ); 74 | script = end; 75 | } 76 | else if( strncmp( script + 10, "Name(", 5 ) == 0 ) 77 | { 78 | auto end = FindEnd( script + 15 ); 79 | memset( script, ' ', end - script ); 80 | script = end; 81 | } 82 | else if( strncmp( script + 10, "BeginN(", 7 ) == 0 ) 83 | { 84 | auto end = FindEnd( script + 17 ); 85 | memset( script, ' ', end - script ); 86 | script = end; 87 | } 88 | else if( strncmp( script + 10, "BeginS(", 7 ) == 0 ) 89 | { 90 | auto end = FindEnd( script + 17 ); 91 | memset( script, ' ', end - script ); 92 | script = end; 93 | } 94 | else if( strncmp( script + 10, "BeginNS(", 8 ) == 0 ) 95 | { 96 | auto end = FindEnd( script + 18 ); 97 | memset( script, ' ', end - script ); 98 | script = end; 99 | } 100 | else 101 | { 102 | script += 10; 103 | } 104 | } 105 | else if( strncmp( script + 6, "Message(", 8 ) == 0 ) 106 | { 107 | auto end = FindEnd( script + 14 ); 108 | memset( script, ' ', end - script ); 109 | script = end; 110 | } 111 | else 112 | { 113 | script += 6; 114 | } 115 | } 116 | else 117 | { 118 | script++; 119 | } 120 | } 121 | } 122 | 123 | } 124 | 125 | #else 126 | 127 | #include 128 | #include 129 | 130 | #include "common/TracyColor.hpp" 131 | #include "common/TracyAlign.hpp" 132 | #include "common/TracyForceInline.hpp" 133 | #include "common/TracySystem.hpp" 134 | #include "client/TracyProfiler.hpp" 135 | 136 | namespace tracy 137 | { 138 | 139 | #ifdef TRACY_ON_DEMAND 140 | TRACY_API LuaZoneState& GetLuaZoneState(); 141 | #endif 142 | 143 | namespace detail 144 | { 145 | 146 | #ifdef TRACY_HAS_CALLSTACK 147 | static tracy_force_inline void SendLuaCallstack( lua_State* L, uint32_t depth ) 148 | { 149 | assert( depth <= 64 ); 150 | lua_Debug dbg[64]; 151 | const char* func[64]; 152 | uint32_t fsz[64]; 153 | uint32_t ssz[64]; 154 | 155 | uint8_t cnt; 156 | uint16_t spaceNeeded = sizeof( cnt ); 157 | for( cnt=0; cnt::max() ); 177 | memcpy( dst, fsz+i, 2 ); dst += 2; 178 | memcpy( dst, func[i], fsz[i] ); dst += fsz[i]; 179 | assert( ssz[i] <= std::numeric_limits::max() ); 180 | memcpy( dst, ssz+i, 2 ); dst += 2; 181 | memcpy( dst, dbg[i].source, ssz[i] ), dst += ssz[i]; 182 | } 183 | assert( dst - ptr == spaceNeeded + 2 ); 184 | 185 | TracyLfqPrepare( QueueType::CallstackAlloc ); 186 | MemWrite( &item->callstackAllocFat.ptr, (uint64_t)ptr ); 187 | MemWrite( &item->callstackAllocFat.nativePtr, (uint64_t)Callstack( depth ) ); 188 | TracyLfqCommit; 189 | } 190 | 191 | static inline int LuaZoneBeginS( lua_State* L ) 192 | { 193 | #ifdef TRACY_ON_DEMAND 194 | const auto zoneCnt = GetLuaZoneState().counter++; 195 | if( zoneCnt != 0 && !GetLuaZoneState().active ) return 0; 196 | GetLuaZoneState().active = GetProfiler().IsConnected(); 197 | if( !GetLuaZoneState().active ) return 0; 198 | #endif 199 | 200 | #ifdef TRACY_CALLSTACK 201 | const uint32_t depth = TRACY_CALLSTACK; 202 | #else 203 | const auto depth = uint32_t( lua_tointeger( L, 1 ) ); 204 | #endif 205 | SendLuaCallstack( L, depth ); 206 | 207 | TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLocCallstack ); 208 | lua_Debug dbg; 209 | lua_getstack( L, 1, &dbg ); 210 | lua_getinfo( L, "Snl", &dbg ); 211 | const auto srcloc = Profiler::AllocSourceLocation( dbg.currentline, dbg.source, dbg.name ? dbg.name : dbg.short_src ); 212 | MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); 213 | MemWrite( &item->zoneBegin.srcloc, srcloc ); 214 | TracyLfqCommit; 215 | 216 | return 0; 217 | } 218 | 219 | static inline int LuaZoneBeginNS( lua_State* L ) 220 | { 221 | #ifdef TRACY_ON_DEMAND 222 | const auto zoneCnt = GetLuaZoneState().counter++; 223 | if( zoneCnt != 0 && !GetLuaZoneState().active ) return 0; 224 | GetLuaZoneState().active = GetProfiler().IsConnected(); 225 | if( !GetLuaZoneState().active ) return 0; 226 | #endif 227 | 228 | #ifdef TRACY_CALLSTACK 229 | const uint32_t depth = TRACY_CALLSTACK; 230 | #else 231 | const auto depth = uint32_t( lua_tointeger( L, 2 ) ); 232 | #endif 233 | SendLuaCallstack( L, depth ); 234 | 235 | TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLocCallstack ); 236 | lua_Debug dbg; 237 | lua_getstack( L, 1, &dbg ); 238 | lua_getinfo( L, "Snl", &dbg ); 239 | size_t nsz; 240 | const auto name = lua_tolstring( L, 1, &nsz ); 241 | const auto srcloc = Profiler::AllocSourceLocation( dbg.currentline, dbg.source, dbg.name ? dbg.name : dbg.short_src, name, nsz ); 242 | MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); 243 | MemWrite( &item->zoneBegin.srcloc, srcloc ); 244 | TracyLfqCommit; 245 | 246 | return 0; 247 | } 248 | #endif 249 | 250 | static inline int LuaZoneBegin( lua_State* L ) 251 | { 252 | #if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK 253 | return LuaZoneBeginS( L ); 254 | #else 255 | #ifdef TRACY_ON_DEMAND 256 | const auto zoneCnt = GetLuaZoneState().counter++; 257 | if( zoneCnt != 0 && !GetLuaZoneState().active ) return 0; 258 | GetLuaZoneState().active = GetProfiler().IsConnected(); 259 | if( !GetLuaZoneState().active ) return 0; 260 | #endif 261 | 262 | TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLoc ); 263 | lua_Debug dbg; 264 | lua_getstack( L, 1, &dbg ); 265 | lua_getinfo( L, "Snl", &dbg ); 266 | const auto srcloc = Profiler::AllocSourceLocation( dbg.currentline, dbg.source, dbg.name ? dbg.name : dbg.short_src ); 267 | MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); 268 | MemWrite( &item->zoneBegin.srcloc, srcloc ); 269 | TracyLfqCommit; 270 | return 0; 271 | #endif 272 | } 273 | 274 | static inline int LuaZoneBeginN( lua_State* L ) 275 | { 276 | #if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK 277 | return LuaZoneBeginNS( L ); 278 | #else 279 | #ifdef TRACY_ON_DEMAND 280 | const auto zoneCnt = GetLuaZoneState().counter++; 281 | if( zoneCnt != 0 && !GetLuaZoneState().active ) return 0; 282 | GetLuaZoneState().active = GetProfiler().IsConnected(); 283 | if( !GetLuaZoneState().active ) return 0; 284 | #endif 285 | 286 | TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLoc ); 287 | lua_Debug dbg; 288 | lua_getstack( L, 1, &dbg ); 289 | lua_getinfo( L, "Snl", &dbg ); 290 | size_t nsz; 291 | const auto name = lua_tolstring( L, 1, &nsz ); 292 | const auto srcloc = Profiler::AllocSourceLocation( dbg.currentline, dbg.source, dbg.name ? dbg.name : dbg.short_src, name, nsz ); 293 | MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); 294 | MemWrite( &item->zoneBegin.srcloc, srcloc ); 295 | TracyLfqCommit; 296 | return 0; 297 | #endif 298 | } 299 | 300 | static inline int LuaZoneEnd( lua_State* L ) 301 | { 302 | #ifdef TRACY_ON_DEMAND 303 | assert( GetLuaZoneState().counter != 0 ); 304 | GetLuaZoneState().counter--; 305 | if( !GetLuaZoneState().active ) return 0; 306 | if( !GetProfiler().IsConnected() ) 307 | { 308 | GetLuaZoneState().active = false; 309 | return 0; 310 | } 311 | #endif 312 | 313 | TracyLfqPrepare( QueueType::ZoneEnd ); 314 | MemWrite( &item->zoneEnd.time, Profiler::GetTime() ); 315 | TracyLfqCommit; 316 | return 0; 317 | } 318 | 319 | static inline int LuaZoneText( lua_State* L ) 320 | { 321 | #ifdef TRACY_ON_DEMAND 322 | if( !GetLuaZoneState().active ) return 0; 323 | if( !GetProfiler().IsConnected() ) 324 | { 325 | GetLuaZoneState().active = false; 326 | return 0; 327 | } 328 | #endif 329 | 330 | auto txt = lua_tostring( L, 1 ); 331 | const auto size = strlen( txt ); 332 | assert( size < std::numeric_limits::max() ); 333 | 334 | auto ptr = (char*)tracy_malloc( size ); 335 | memcpy( ptr, txt, size ); 336 | TracyLfqPrepare( QueueType::ZoneText ); 337 | MemWrite( &item->zoneTextFat.text, (uint64_t)ptr ); 338 | MemWrite( &item->zoneTextFat.size, (uint16_t)size ); 339 | TracyLfqCommit; 340 | return 0; 341 | } 342 | 343 | static inline int LuaZoneName( lua_State* L ) 344 | { 345 | #ifdef TRACY_ON_DEMAND 346 | if( !GetLuaZoneState().active ) return 0; 347 | if( !GetProfiler().IsConnected() ) 348 | { 349 | GetLuaZoneState().active = false; 350 | return 0; 351 | } 352 | #endif 353 | 354 | auto txt = lua_tostring( L, 1 ); 355 | const auto size = strlen( txt ); 356 | assert( size < std::numeric_limits::max() ); 357 | 358 | auto ptr = (char*)tracy_malloc( size ); 359 | memcpy( ptr, txt, size ); 360 | TracyLfqPrepare( QueueType::ZoneName ); 361 | MemWrite( &item->zoneTextFat.text, (uint64_t)ptr ); 362 | MemWrite( &item->zoneTextFat.size, (uint16_t)size ); 363 | TracyLfqCommit; 364 | return 0; 365 | } 366 | 367 | static inline int LuaMessage( lua_State* L ) 368 | { 369 | #ifdef TRACY_ON_DEMAND 370 | if( !GetProfiler().IsConnected() ) return 0; 371 | #endif 372 | 373 | auto txt = lua_tostring( L, 1 ); 374 | const auto size = strlen( txt ); 375 | assert( size < std::numeric_limits::max() ); 376 | 377 | TracyLfqPrepare( QueueType::Message ); 378 | auto ptr = (char*)tracy_malloc( size ); 379 | memcpy( ptr, txt, size ); 380 | MemWrite( &item->messageFat.time, Profiler::GetTime() ); 381 | MemWrite( &item->messageFat.text, (uint64_t)ptr ); 382 | MemWrite( &item->messageFat.size, (uint16_t)size ); 383 | TracyLfqCommit; 384 | return 0; 385 | } 386 | 387 | } 388 | 389 | static inline void LuaRegister( lua_State* L ) 390 | { 391 | lua_newtable( L ); 392 | lua_pushcfunction( L, detail::LuaZoneBegin ); 393 | lua_setfield( L, -2, "ZoneBegin" ); 394 | lua_pushcfunction( L, detail::LuaZoneBeginN ); 395 | lua_setfield( L, -2, "ZoneBeginN" ); 396 | #ifdef TRACY_HAS_CALLSTACK 397 | lua_pushcfunction( L, detail::LuaZoneBeginS ); 398 | lua_setfield( L, -2, "ZoneBeginS" ); 399 | lua_pushcfunction( L, detail::LuaZoneBeginNS ); 400 | lua_setfield( L, -2, "ZoneBeginNS" ); 401 | #else 402 | lua_pushcfunction( L, detail::LuaZoneBegin ); 403 | lua_setfield( L, -2, "ZoneBeginS" ); 404 | lua_pushcfunction( L, detail::LuaZoneBeginN ); 405 | lua_setfield( L, -2, "ZoneBeginNS" ); 406 | #endif 407 | lua_pushcfunction( L, detail::LuaZoneEnd ); 408 | lua_setfield( L, -2, "ZoneEnd" ); 409 | lua_pushcfunction( L, detail::LuaZoneText ); 410 | lua_setfield( L, -2, "ZoneText" ); 411 | lua_pushcfunction( L, detail::LuaZoneName ); 412 | lua_setfield( L, -2, "ZoneName" ); 413 | lua_pushcfunction( L, detail::LuaMessage ); 414 | lua_setfield( L, -2, "Message" ); 415 | lua_setglobal( L, "tracy" ); 416 | } 417 | 418 | static inline void LuaRemove( char* script ) {} 419 | 420 | } 421 | 422 | #endif 423 | 424 | #endif 425 | -------------------------------------------------------------------------------- /tracy-0.7.8/TracyOpenCL.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __TRACYOPENCL_HPP__ 2 | #define __TRACYOPENCL_HPP__ 3 | 4 | #if !defined TRACY_ENABLE 5 | 6 | #define TracyCLContext(c, x) nullptr 7 | #define TracyCLDestroy(c) 8 | #define TracyCLContextName(c, x, y) 9 | 10 | #define TracyCLNamedZone(c, x, y, z) 11 | #define TracyCLNamedZoneC(c, x, y, z, w) 12 | #define TracyCLZone(c, x) 13 | #define TracyCLZoneC(c, x, y) 14 | 15 | #define TracyCLNamedZoneS(c, x, y, z, w) 16 | #define TracyCLNamedZoneCS(c, x, y, z, w, v) 17 | #define TracyCLZoneS(c, x, y) 18 | #define TracyCLZoneCS(c, x, y, z) 19 | 20 | #define TracyCLNamedZoneSetEvent(x, e) 21 | #define TracyCLZoneSetEvent(e) 22 | 23 | #define TracyCLCollect(c) 24 | 25 | namespace tracy 26 | { 27 | class OpenCLCtxScope {}; 28 | } 29 | 30 | using TracyCLCtx = void*; 31 | 32 | #else 33 | 34 | #include 35 | 36 | #include 37 | #include 38 | 39 | #include "Tracy.hpp" 40 | #include "client/TracyCallstack.hpp" 41 | #include "client/TracyProfiler.hpp" 42 | #include "common/TracyAlloc.hpp" 43 | 44 | namespace tracy { 45 | 46 | enum class EventPhase : uint8_t 47 | { 48 | Begin, 49 | End 50 | }; 51 | 52 | struct EventInfo 53 | { 54 | cl_event event; 55 | EventPhase phase; 56 | }; 57 | 58 | class OpenCLCtx 59 | { 60 | public: 61 | enum { QueryCount = 64 * 1024 }; 62 | 63 | OpenCLCtx(cl_context context, cl_device_id device) 64 | : m_contextId(GetGpuCtxCounter().fetch_add(1, std::memory_order_relaxed)) 65 | , m_head(0) 66 | , m_tail(0) 67 | { 68 | int64_t tcpu, tgpu; 69 | assert(m_contextId != 255); 70 | 71 | cl_int err = CL_SUCCESS; 72 | cl_command_queue queue = clCreateCommandQueue(context, device, CL_QUEUE_PROFILING_ENABLE, &err); 73 | assert(err == CL_SUCCESS); 74 | uint32_t dummyValue = 42; 75 | cl_mem dummyBuffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, sizeof(uint32_t), nullptr, &err); 76 | assert(err == CL_SUCCESS); 77 | cl_event writeBufferEvent; 78 | err = clEnqueueWriteBuffer(queue, dummyBuffer, CL_FALSE, 0, sizeof(uint32_t), &dummyValue, 0, nullptr, &writeBufferEvent); 79 | assert(err == CL_SUCCESS); 80 | err = clWaitForEvents(1, &writeBufferEvent); 81 | 82 | tcpu = Profiler::GetTime(); 83 | 84 | assert(err == CL_SUCCESS); 85 | cl_int eventStatus; 86 | err = clGetEventInfo(writeBufferEvent, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof(cl_int), &eventStatus, nullptr); 87 | assert(err == CL_SUCCESS); 88 | assert(eventStatus == CL_COMPLETE); 89 | err = clGetEventProfilingInfo(writeBufferEvent, CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &tgpu, nullptr); 90 | assert(err == CL_SUCCESS); 91 | err = clReleaseEvent(writeBufferEvent); 92 | assert(err == CL_SUCCESS); 93 | err = clReleaseMemObject(dummyBuffer); 94 | assert(err == CL_SUCCESS); 95 | err = clReleaseCommandQueue(queue); 96 | assert(err == CL_SUCCESS); 97 | 98 | auto item = Profiler::QueueSerial(); 99 | MemWrite(&item->hdr.type, QueueType::GpuNewContext); 100 | MemWrite(&item->gpuNewContext.cpuTime, tcpu); 101 | MemWrite(&item->gpuNewContext.gpuTime, tgpu); 102 | memset(&item->gpuNewContext.thread, 0, sizeof(item->gpuNewContext.thread)); 103 | MemWrite(&item->gpuNewContext.period, 1.0f); 104 | MemWrite(&item->gpuNewContext.type, GpuContextType::OpenCL); 105 | MemWrite(&item->gpuNewContext.context, (uint8_t) m_contextId); 106 | MemWrite(&item->gpuNewContext.flags, (uint8_t)0); 107 | #ifdef TRACY_ON_DEMAND 108 | GetProfiler().DeferItem(*item); 109 | #endif 110 | Profiler::QueueSerialFinish(); 111 | } 112 | 113 | void Name( const char* name, uint16_t len ) 114 | { 115 | auto ptr = (char*)tracy_malloc( len ); 116 | memcpy( ptr, name, len ); 117 | 118 | auto item = Profiler::QueueSerial(); 119 | MemWrite( &item->hdr.type, QueueType::GpuContextName ); 120 | MemWrite( &item->gpuContextNameFat.context, (uint8_t)m_contextId ); 121 | MemWrite( &item->gpuContextNameFat.ptr, (uint64_t)ptr ); 122 | MemWrite( &item->gpuContextNameFat.size, len ); 123 | #ifdef TRACY_ON_DEMAND 124 | GetProfiler().DeferItem( *item ); 125 | #endif 126 | Profiler::QueueSerialFinish(); 127 | } 128 | 129 | void Collect() 130 | { 131 | ZoneScopedC(Color::Red4); 132 | 133 | if (m_tail == m_head) return; 134 | 135 | #ifdef TRACY_ON_DEMAND 136 | if (!GetProfiler().IsConnected()) 137 | { 138 | m_head = m_tail = 0; 139 | } 140 | #endif 141 | 142 | while (m_tail != m_head) 143 | { 144 | EventInfo eventInfo = m_query[m_tail]; 145 | cl_event event = eventInfo.event; 146 | cl_int eventStatus; 147 | cl_int err = clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof(cl_int), &eventStatus, nullptr); 148 | assert(err == CL_SUCCESS); 149 | if (eventStatus != CL_COMPLETE) return; 150 | 151 | cl_int eventInfoQuery = (eventInfo.phase == EventPhase::Begin) 152 | ? CL_PROFILING_COMMAND_START 153 | : CL_PROFILING_COMMAND_END; 154 | 155 | cl_ulong eventTimeStamp = 0; 156 | err = clGetEventProfilingInfo(event, eventInfoQuery, sizeof(cl_ulong), &eventTimeStamp, nullptr); 157 | assert(err == CL_SUCCESS); 158 | assert(eventTimeStamp != 0); 159 | 160 | auto item = Profiler::QueueSerial(); 161 | MemWrite(&item->hdr.type, QueueType::GpuTime); 162 | MemWrite(&item->gpuTime.gpuTime, (int64_t)eventTimeStamp); 163 | MemWrite(&item->gpuTime.queryId, (uint16_t)m_tail); 164 | MemWrite(&item->gpuTime.context, m_contextId); 165 | Profiler::QueueSerialFinish(); 166 | 167 | if (eventInfo.phase == EventPhase::End) 168 | { 169 | // Done with the event, so release it 170 | err = clReleaseEvent(event); 171 | assert(err == CL_SUCCESS); 172 | } 173 | 174 | m_tail = (m_tail + 1) % QueryCount; 175 | } 176 | } 177 | 178 | tracy_force_inline uint8_t GetId() const 179 | { 180 | return m_contextId; 181 | } 182 | 183 | tracy_force_inline unsigned int NextQueryId(EventInfo eventInfo) 184 | { 185 | const auto id = m_head; 186 | m_head = (m_head + 1) % QueryCount; 187 | assert(m_head != m_tail); 188 | m_query[id] = eventInfo; 189 | return id; 190 | } 191 | 192 | tracy_force_inline EventInfo& GetQuery(unsigned int id) 193 | { 194 | assert(id < QueryCount); 195 | return m_query[id]; 196 | } 197 | 198 | private: 199 | 200 | unsigned int m_contextId; 201 | 202 | EventInfo m_query[QueryCount]; 203 | unsigned int m_head; 204 | unsigned int m_tail; 205 | 206 | }; 207 | 208 | class OpenCLCtxScope { 209 | public: 210 | tracy_force_inline OpenCLCtxScope(OpenCLCtx* ctx, const SourceLocationData* srcLoc, bool is_active) 211 | #ifdef TRACY_ON_DEMAND 212 | : m_active(is_active&& GetProfiler().IsConnected()) 213 | #else 214 | : m_active(is_active) 215 | #endif 216 | , m_ctx(ctx) 217 | , m_event(nullptr) 218 | { 219 | if (!m_active) return; 220 | 221 | m_beginQueryId = ctx->NextQueryId(EventInfo{ nullptr, EventPhase::Begin }); 222 | 223 | auto item = Profiler::QueueSerial(); 224 | MemWrite(&item->hdr.type, QueueType::GpuZoneBeginSerial); 225 | MemWrite(&item->gpuZoneBegin.cpuTime, Profiler::GetTime()); 226 | MemWrite(&item->gpuZoneBegin.srcloc, (uint64_t)srcLoc); 227 | MemWrite(&item->gpuZoneBegin.thread, GetThreadHandle()); 228 | MemWrite(&item->gpuZoneBegin.queryId, (uint16_t)m_beginQueryId); 229 | MemWrite(&item->gpuZoneBegin.context, ctx->GetId()); 230 | Profiler::QueueSerialFinish(); 231 | } 232 | 233 | tracy_force_inline OpenCLCtxScope(OpenCLCtx* ctx, const SourceLocationData* srcLoc, int depth, bool is_active) 234 | #ifdef TRACY_ON_DEMAND 235 | : m_active(is_active&& GetProfiler().IsConnected()) 236 | #else 237 | : m_active(is_active) 238 | #endif 239 | , m_ctx(ctx) 240 | , m_event(nullptr) 241 | { 242 | if (!m_active) return; 243 | 244 | m_beginQueryId = ctx->NextQueryId(EventInfo{ nullptr, EventPhase::Begin }); 245 | 246 | GetProfiler().SendCallstack(depth); 247 | 248 | auto item = Profiler::QueueSerial(); 249 | MemWrite(&item->hdr.type, QueueType::GpuZoneBeginCallstackSerial); 250 | MemWrite(&item->gpuZoneBegin.cpuTime, Profiler::GetTime()); 251 | MemWrite(&item->gpuZoneBegin.srcloc, (uint64_t)srcLoc); 252 | MemWrite(&item->gpuZoneBegin.thread, GetThreadHandle()); 253 | MemWrite(&item->gpuZoneBegin.queryId, (uint16_t)m_beginQueryId); 254 | MemWrite(&item->gpuZoneBegin.context, ctx->GetId()); 255 | Profiler::QueueSerialFinish(); 256 | } 257 | 258 | tracy_force_inline void SetEvent(cl_event event) 259 | { 260 | if (!m_active) return; 261 | m_event = event; 262 | cl_int err = clRetainEvent(m_event); 263 | assert(err == CL_SUCCESS); 264 | m_ctx->GetQuery(m_beginQueryId).event = m_event; 265 | } 266 | 267 | tracy_force_inline ~OpenCLCtxScope() 268 | { 269 | if (!m_active) return; 270 | const auto queryId = m_ctx->NextQueryId(EventInfo{ m_event, EventPhase::End }); 271 | 272 | auto item = Profiler::QueueSerial(); 273 | MemWrite(&item->hdr.type, QueueType::GpuZoneEndSerial); 274 | MemWrite(&item->gpuZoneEnd.cpuTime, Profiler::GetTime()); 275 | MemWrite(&item->gpuZoneEnd.thread, GetThreadHandle()); 276 | MemWrite(&item->gpuZoneEnd.queryId, (uint16_t)queryId); 277 | MemWrite(&item->gpuZoneEnd.context, m_ctx->GetId()); 278 | Profiler::QueueSerialFinish(); 279 | } 280 | 281 | const bool m_active; 282 | OpenCLCtx* m_ctx; 283 | cl_event m_event; 284 | unsigned int m_beginQueryId; 285 | }; 286 | 287 | static inline OpenCLCtx* CreateCLContext(cl_context context, cl_device_id device) 288 | { 289 | InitRPMallocThread(); 290 | auto ctx = (OpenCLCtx*)tracy_malloc(sizeof(OpenCLCtx)); 291 | new (ctx) OpenCLCtx(context, device); 292 | return ctx; 293 | } 294 | 295 | static inline void DestroyCLContext(OpenCLCtx* ctx) 296 | { 297 | ctx->~OpenCLCtx(); 298 | tracy_free(ctx); 299 | } 300 | 301 | } // namespace tracy 302 | 303 | using TracyCLCtx = tracy::OpenCLCtx*; 304 | 305 | #define TracyCLContext(context, device) tracy::CreateCLContext(context, device); 306 | #define TracyCLDestroy(ctx) tracy::DestroyCLContext(ctx); 307 | #define TracyCLContextName(context, name, size) ctx->Name(name, size); 308 | #if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK 309 | # define TracyCLNamedZone(ctx, varname, name, active) static constexpr tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::OpenCLCtxScope varname(ctx, &TracyConcat(__tracy_gpu_source_location,__LINE__), TRACY_CALLSTACK, active ); 310 | # define TracyCLNamedZoneC(ctx, varname, name, color, active) static constexpr tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::OpenCLCtxScope varname(ctx, &TracyConcat(__tracy_gpu_source_location,__LINE__), TRACY_CALLSTACK, active ); 311 | # define TracyCLZone(ctx, name) TracyCLNamedZoneS(ctx, __tracy_gpu_zone, name, TRACY_CALLSTACK, true) 312 | # define TracyCLZoneC(ctx, name, color) TracyCLNamedZoneCS(ctx, __tracy_gpu_zone, name, color, TRACY_CALLSTACK, true) 313 | #else 314 | # define TracyCLNamedZone(ctx, varname, name, active) static constexpr tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__){ name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::OpenCLCtxScope varname(ctx, &TracyConcat(__tracy_gpu_source_location,__LINE__), active); 315 | # define TracyCLNamedZoneC(ctx, varname, name, color, active) static constexpr tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__){ name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::OpenCLCtxScope varname(ctx, &TracyConcat(__tracy_gpu_source_location,__LINE__), active); 316 | # define TracyCLZone(ctx, name) TracyCLNamedZone(ctx, __tracy_gpu_zone, name, true) 317 | # define TracyCLZoneC(ctx, name, color) TracyCLNamedZoneC(ctx, __tracy_gpu_zone, name, color, true ) 318 | #endif 319 | 320 | #ifdef TRACY_HAS_CALLSTACK 321 | # define TracyCLNamedZoneS(ctx, varname, name, depth, active) static constexpr tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__){ name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::OpenCLCtxScope varname(ctx, &TracyConcat(__tracy_gpu_source_location,__LINE__), depth, active); 322 | # define TracyCLNamedZoneCS(ctx, varname, name, color, depth, active) static constexpr tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__){ name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::OpenCLCtxScope varname(ctx, &TracyConcat(__tracy_gpu_source_location,__LINE__), depth, active); 323 | # define TracyCLZoneS(ctx, name, depth) TracyCLNamedZoneS(ctx, __tracy_gpu_zone, name, depth, true) 324 | # define TracyCLZoneCS(ctx, name, color, depth) TracyCLNamedZoneCS(ctx, __tracy_gpu_zone, name, color, depth, true) 325 | #else 326 | # define TracyCLNamedZoneS(ctx, varname, name, depth, active) TracyCLNamedZone(ctx, varname, name, active) 327 | # define TracyCLNamedZoneCS(ctx, varname, name, color, depth, active) TracyCLNamedZoneC(ctx, varname, name, color, active) 328 | # define TracyCLZoneS(ctx, name, depth) TracyCLZone(ctx, name) 329 | # define TracyCLZoneCS(ctx, name, color, depth) TracyCLZoneC(ctx, name, color) 330 | #endif 331 | 332 | #define TracyCLNamedZoneSetEvent(varname, event) varname.SetEvent(event) 333 | #define TracyCLZoneSetEvent(event) __tracy_gpu_zone.SetEvent(event) 334 | 335 | #define TracyCLCollect(ctx) ctx->Collect() 336 | 337 | #endif 338 | 339 | #endif 340 | -------------------------------------------------------------------------------- /tracy-0.7.8/TracyOpenGL.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __TRACYOPENGL_HPP__ 2 | #define __TRACYOPENGL_HPP__ 3 | 4 | #if !defined GL_TIMESTAMP && !defined GL_TIMESTAMP_EXT 5 | # error "You must include OpenGL 3.2 headers before including TracyOpenGL.hpp" 6 | #endif 7 | 8 | #if !defined TRACY_ENABLE || defined __APPLE__ 9 | 10 | #define TracyGpuContext 11 | #define TracyGpuContextName(x,y) 12 | #define TracyGpuNamedZone(x,y,z) 13 | #define TracyGpuNamedZoneC(x,y,z,w) 14 | #define TracyGpuZone(x) 15 | #define TracyGpuZoneC(x,y) 16 | #define TracyGpuZoneTransient(x,y,z) 17 | #define TracyGpuCollect 18 | 19 | #define TracyGpuNamedZoneS(x,y,z,w) 20 | #define TracyGpuNamedZoneCS(x,y,z,w,a) 21 | #define TracyGpuZoneS(x,y) 22 | #define TracyGpuZoneCS(x,y,z) 23 | #define TracyGpuZoneTransientS(x,y,z,w) 24 | 25 | namespace tracy 26 | { 27 | struct SourceLocationData; 28 | class GpuCtxScope 29 | { 30 | public: 31 | GpuCtxScope( const SourceLocationData*, bool ) {} 32 | GpuCtxScope( const SourceLocationData*, int, bool ) {} 33 | }; 34 | } 35 | 36 | #else 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | #include "Tracy.hpp" 43 | #include "client/TracyProfiler.hpp" 44 | #include "client/TracyCallstack.hpp" 45 | #include "common/TracyAlign.hpp" 46 | #include "common/TracyAlloc.hpp" 47 | 48 | #if !defined GL_TIMESTAMP && defined GL_TIMESTAMP_EXT 49 | # define GL_TIMESTAMP GL_TIMESTAMP_EXT 50 | # define GL_QUERY_COUNTER_BITS GL_QUERY_COUNTER_BITS_EXT 51 | # define glGetQueryObjectiv glGetQueryObjectivEXT 52 | # define glGetQueryObjectui64v glGetQueryObjectui64vEXT 53 | # define glQueryCounter glQueryCounterEXT 54 | #endif 55 | 56 | #define TracyGpuContext tracy::InitRPMallocThread(); tracy::GetGpuCtx().ptr = (tracy::GpuCtx*)tracy::tracy_malloc( sizeof( tracy::GpuCtx ) ); new(tracy::GetGpuCtx().ptr) tracy::GpuCtx; 57 | #define TracyGpuContextName( name, size ) tracy::GetGpuCtx().ptr->Name( name, size ); 58 | #if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK 59 | # define TracyGpuNamedZone( varname, name, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::GpuCtxScope varname( &TracyConcat(__tracy_gpu_source_location,__LINE__), TRACY_CALLSTACK, active ); 60 | # define TracyGpuNamedZoneC( varname, name, color, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::GpuCtxScope varname( &TracyConcat(__tracy_gpu_source_location,__LINE__), TRACY_CALLSTACK, active ); 61 | # define TracyGpuZone( name ) TracyGpuNamedZoneS( ___tracy_gpu_zone, name, TRACY_CALLSTACK, true ) 62 | # define TracyGpuZoneC( name, color ) TracyGpuNamedZoneCS( ___tracy_gpu_zone, name, color, TRACY_CALLSTACK, true ) 63 | # define TracyGpuZoneTransient( varname, name, active ) tracy::GpuCtxScope varname( __LINE__, __FILE__, strlen( __FILE__ ), __FUNCTION__, strlen( __FUNCTION__ ), name, strlen( name ), TRACY_CALLSTACK, active ); 64 | #else 65 | # define TracyGpuNamedZone( varname, name, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::GpuCtxScope varname( &TracyConcat(__tracy_gpu_source_location,__LINE__), active ); 66 | # define TracyGpuNamedZoneC( varname, name, color, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::GpuCtxScope varname( &TracyConcat(__tracy_gpu_source_location,__LINE__), active ); 67 | # define TracyGpuZone( name ) TracyGpuNamedZone( ___tracy_gpu_zone, name, true ) 68 | # define TracyGpuZoneC( name, color ) TracyGpuNamedZoneC( ___tracy_gpu_zone, name, color, true ) 69 | # define TracyGpuZoneTransient( varname, name, active ) tracy::GpuCtxScope varname( __LINE__, __FILE__, strlen( __FILE__ ), __FUNCTION__, strlen( __FUNCTION__ ), name, strlen( name ), active ); 70 | #endif 71 | #define TracyGpuCollect tracy::GetGpuCtx().ptr->Collect(); 72 | 73 | #ifdef TRACY_HAS_CALLSTACK 74 | # define TracyGpuNamedZoneS( varname, name, depth, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::GpuCtxScope varname( &TracyConcat(__tracy_gpu_source_location,__LINE__), depth, active ); 75 | # define TracyGpuNamedZoneCS( varname, name, color, depth, active ) static constexpr tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::GpuCtxScope varname( &TracyConcat(__tracy_gpu_source_location,__LINE__), depth, active ); 76 | # define TracyGpuZoneS( name, depth ) TracyGpuNamedZoneS( ___tracy_gpu_zone, name, depth, true ) 77 | # define TracyGpuZoneCS( name, color, depth ) TracyGpuNamedZoneCS( ___tracy_gpu_zone, name, color, depth, true ) 78 | # define TracyGpuZoneTransientS( varname, name, depth, active ) tracy::GpuCtxScope varname( __LINE__, __FILE__, strlen( __FILE__ ), __FUNCTION__, strlen( __FUNCTION__ ), name, strlen( name ), depth, active ); 79 | #else 80 | # define TracyGpuNamedZoneS( varname, name, depth, active ) TracyGpuNamedZone( varname, name, active ) 81 | # define TracyGpuNamedZoneCS( varname, name, color, depth, active ) TracyGpuNamedZoneC( varname, name, color, active ) 82 | # define TracyGpuZoneS( name, depth ) TracyGpuZone( name ) 83 | # define TracyGpuZoneCS( name, color, depth ) TracyGpuZoneC( name, color ) 84 | # define TracyGpuZoneTransientS( varname, name, depth, active ) TracyGpuZoneTransient( varname, name, active ) 85 | #endif 86 | 87 | namespace tracy 88 | { 89 | 90 | class GpuCtx 91 | { 92 | friend class GpuCtxScope; 93 | 94 | enum { QueryCount = 64 * 1024 }; 95 | 96 | public: 97 | GpuCtx() 98 | : m_context( GetGpuCtxCounter().fetch_add( 1, std::memory_order_relaxed ) ) 99 | , m_head( 0 ) 100 | , m_tail( 0 ) 101 | { 102 | assert( m_context != 255 ); 103 | 104 | glGenQueries( QueryCount, m_query ); 105 | 106 | int64_t tgpu; 107 | glGetInteger64v( GL_TIMESTAMP, &tgpu ); 108 | int64_t tcpu = Profiler::GetTime(); 109 | 110 | GLint bits; 111 | glGetQueryiv( GL_TIMESTAMP, GL_QUERY_COUNTER_BITS, &bits ); 112 | 113 | const float period = 1.f; 114 | const auto thread = GetThreadHandle(); 115 | TracyLfqPrepare( QueueType::GpuNewContext ); 116 | MemWrite( &item->gpuNewContext.cpuTime, tcpu ); 117 | MemWrite( &item->gpuNewContext.gpuTime, tgpu ); 118 | MemWrite( &item->gpuNewContext.thread, thread ); 119 | MemWrite( &item->gpuNewContext.period, period ); 120 | MemWrite( &item->gpuNewContext.context, m_context ); 121 | MemWrite( &item->gpuNewContext.flags, uint8_t( 0 ) ); 122 | MemWrite( &item->gpuNewContext.type, GpuContextType::OpenGl ); 123 | 124 | #ifdef TRACY_ON_DEMAND 125 | GetProfiler().DeferItem( *item ); 126 | #endif 127 | 128 | TracyLfqCommit; 129 | } 130 | 131 | void Name( const char* name, uint16_t len ) 132 | { 133 | auto ptr = (char*)tracy_malloc( len ); 134 | memcpy( ptr, name, len ); 135 | 136 | TracyLfqPrepare( QueueType::GpuContextName ); 137 | MemWrite( &item->gpuContextNameFat.context, m_context ); 138 | MemWrite( &item->gpuContextNameFat.ptr, (uint64_t)ptr ); 139 | MemWrite( &item->gpuContextNameFat.size, len ); 140 | #ifdef TRACY_ON_DEMAND 141 | GetProfiler().DeferItem( *item ); 142 | #endif 143 | TracyLfqCommit; 144 | } 145 | 146 | void Collect() 147 | { 148 | ZoneScopedC( Color::Red4 ); 149 | 150 | if( m_tail == m_head ) return; 151 | 152 | #ifdef TRACY_ON_DEMAND 153 | if( !GetProfiler().IsConnected() ) 154 | { 155 | m_head = m_tail = 0; 156 | return; 157 | } 158 | #endif 159 | 160 | while( m_tail != m_head ) 161 | { 162 | GLint available; 163 | glGetQueryObjectiv( m_query[m_tail], GL_QUERY_RESULT_AVAILABLE, &available ); 164 | if( !available ) return; 165 | 166 | uint64_t time; 167 | glGetQueryObjectui64v( m_query[m_tail], GL_QUERY_RESULT, &time ); 168 | 169 | TracyLfqPrepare( QueueType::GpuTime ); 170 | MemWrite( &item->gpuTime.gpuTime, (int64_t)time ); 171 | MemWrite( &item->gpuTime.queryId, (uint16_t)m_tail ); 172 | MemWrite( &item->gpuTime.context, m_context ); 173 | TracyLfqCommit; 174 | 175 | m_tail = ( m_tail + 1 ) % QueryCount; 176 | } 177 | } 178 | 179 | private: 180 | tracy_force_inline unsigned int NextQueryId() 181 | { 182 | const auto id = m_head; 183 | m_head = ( m_head + 1 ) % QueryCount; 184 | assert( m_head != m_tail ); 185 | return id; 186 | } 187 | 188 | tracy_force_inline unsigned int TranslateOpenGlQueryId( unsigned int id ) 189 | { 190 | return m_query[id]; 191 | } 192 | 193 | tracy_force_inline uint8_t GetId() const 194 | { 195 | return m_context; 196 | } 197 | 198 | unsigned int m_query[QueryCount]; 199 | uint8_t m_context; 200 | 201 | unsigned int m_head; 202 | unsigned int m_tail; 203 | }; 204 | 205 | class GpuCtxScope 206 | { 207 | public: 208 | tracy_force_inline GpuCtxScope( const SourceLocationData* srcloc, bool is_active ) 209 | #ifdef TRACY_ON_DEMAND 210 | : m_active( is_active && GetProfiler().IsConnected() ) 211 | #else 212 | : m_active( is_active ) 213 | #endif 214 | { 215 | if( !m_active ) return; 216 | 217 | const auto queryId = GetGpuCtx().ptr->NextQueryId(); 218 | glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP ); 219 | 220 | TracyLfqPrepare( QueueType::GpuZoneBegin ); 221 | MemWrite( &item->gpuZoneBegin.cpuTime, Profiler::GetTime() ); 222 | memset( &item->gpuZoneBegin.thread, 0, sizeof( item->gpuZoneBegin.thread ) ); 223 | MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) ); 224 | MemWrite( &item->gpuZoneBegin.context, GetGpuCtx().ptr->GetId() ); 225 | MemWrite( &item->gpuZoneBegin.srcloc, (uint64_t)srcloc ); 226 | TracyLfqCommit; 227 | } 228 | 229 | tracy_force_inline GpuCtxScope( const SourceLocationData* srcloc, int depth, bool is_active ) 230 | #ifdef TRACY_ON_DEMAND 231 | : m_active( is_active && GetProfiler().IsConnected() ) 232 | #else 233 | : m_active( is_active ) 234 | #endif 235 | { 236 | if( !m_active ) return; 237 | 238 | const auto queryId = GetGpuCtx().ptr->NextQueryId(); 239 | glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP ); 240 | 241 | GetProfiler().SendCallstack( depth ); 242 | 243 | const auto thread = GetThreadHandle(); 244 | TracyLfqPrepare( QueueType::GpuZoneBeginCallstack ); 245 | MemWrite( &item->gpuZoneBegin.cpuTime, Profiler::GetTime() ); 246 | MemWrite( &item->gpuZoneBegin.thread, thread ); 247 | MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) ); 248 | MemWrite( &item->gpuZoneBegin.context, GetGpuCtx().ptr->GetId() ); 249 | MemWrite( &item->gpuZoneBegin.srcloc, (uint64_t)srcloc ); 250 | TracyLfqCommit; 251 | } 252 | 253 | tracy_force_inline GpuCtxScope( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const char* name, size_t nameSz, bool is_active ) 254 | #ifdef TRACY_ON_DEMAND 255 | : m_active( is_active && GetProfiler().IsConnected() ) 256 | #else 257 | : m_active( is_active ) 258 | #endif 259 | { 260 | if( !m_active ) return; 261 | 262 | const auto queryId = GetGpuCtx().ptr->NextQueryId(); 263 | glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP ); 264 | 265 | TracyLfqPrepare( QueueType::GpuZoneBeginAllocSrcLoc ); 266 | const auto srcloc = Profiler::AllocSourceLocation( line, source, sourceSz, function, functionSz, name, nameSz ); 267 | MemWrite( &item->gpuZoneBegin.cpuTime, Profiler::GetTime() ); 268 | memset( &item->gpuZoneBegin.thread, 0, sizeof( item->gpuZoneBegin.thread ) ); 269 | MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) ); 270 | MemWrite( &item->gpuZoneBegin.context, GetGpuCtx().ptr->GetId() ); 271 | MemWrite( &item->gpuZoneBegin.srcloc, (uint64_t)srcloc ); 272 | TracyLfqCommit; 273 | } 274 | 275 | tracy_force_inline GpuCtxScope( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const char* name, size_t nameSz, int depth, bool is_active ) 276 | #ifdef TRACY_ON_DEMAND 277 | : m_active( is_active && GetProfiler().IsConnected() ) 278 | #else 279 | : m_active( is_active ) 280 | #endif 281 | { 282 | if( !m_active ) return; 283 | 284 | const auto queryId = GetGpuCtx().ptr->NextQueryId(); 285 | glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP ); 286 | 287 | GetProfiler().SendCallstack( depth ); 288 | 289 | const auto thread = GetThreadHandle(); 290 | TracyLfqPrepare( QueueType::GpuZoneBeginAllocSrcLocCallstack ); 291 | const auto srcloc = Profiler::AllocSourceLocation( line, source, sourceSz, function, functionSz, name, nameSz ); 292 | MemWrite( &item->gpuZoneBegin.cpuTime, Profiler::GetTime() ); 293 | MemWrite( &item->gpuZoneBegin.thread, thread ); 294 | MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) ); 295 | MemWrite( &item->gpuZoneBegin.context, GetGpuCtx().ptr->GetId() ); 296 | MemWrite( &item->gpuZoneBegin.srcloc, (uint64_t)srcloc ); 297 | TracyLfqCommit; 298 | } 299 | 300 | tracy_force_inline ~GpuCtxScope() 301 | { 302 | if( !m_active ) return; 303 | 304 | const auto queryId = GetGpuCtx().ptr->NextQueryId(); 305 | glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP ); 306 | 307 | TracyLfqPrepare( QueueType::GpuZoneEnd ); 308 | MemWrite( &item->gpuZoneEnd.cpuTime, Profiler::GetTime() ); 309 | memset( &item->gpuZoneEnd.thread, 0, sizeof( item->gpuZoneEnd.thread ) ); 310 | MemWrite( &item->gpuZoneEnd.queryId, uint16_t( queryId ) ); 311 | MemWrite( &item->gpuZoneEnd.context, GetGpuCtx().ptr->GetId() ); 312 | TracyLfqCommit; 313 | } 314 | 315 | private: 316 | const bool m_active; 317 | }; 318 | 319 | } 320 | 321 | #endif 322 | 323 | #endif 324 | -------------------------------------------------------------------------------- /tracy-0.7.8/client/TracyArmCpuTable.hpp: -------------------------------------------------------------------------------- 1 | namespace tracy 2 | { 3 | 4 | #if defined __linux__ && defined __ARM_ARCH 5 | 6 | static const char* DecodeArmImplementer( uint32_t v ) 7 | { 8 | static char buf[16]; 9 | switch( v ) 10 | { 11 | case 0x41: return "ARM"; 12 | case 0x42: return "Broadcom"; 13 | case 0x43: return "Cavium"; 14 | case 0x44: return "DEC"; 15 | case 0x46: return "Fujitsu"; 16 | case 0x48: return "HiSilicon"; 17 | case 0x49: return "Infineon"; 18 | case 0x4d: return "Motorola"; 19 | case 0x4e: return "Nvidia"; 20 | case 0x50: return "Applied Micro"; 21 | case 0x51: return "Qualcomm"; 22 | case 0x53: return "Samsung"; 23 | case 0x54: return "Texas Instruments"; 24 | case 0x56: return "Marvell"; 25 | case 0x61: return "Apple"; 26 | case 0x66: return "Faraday"; 27 | case 0x68: return "HXT"; 28 | case 0x69: return "Intel"; 29 | case 0xc0: return "Ampere Computing"; 30 | default: break; 31 | } 32 | sprintf( buf, "0x%x", v ); 33 | return buf; 34 | } 35 | 36 | static const char* DecodeArmPart( uint32_t impl, uint32_t part ) 37 | { 38 | static char buf[16]; 39 | switch( impl ) 40 | { 41 | case 0x41: 42 | switch( part ) 43 | { 44 | case 0x810: return "810"; 45 | case 0x920: return "920"; 46 | case 0x922: return "922"; 47 | case 0x926: return "926"; 48 | case 0x940: return "940"; 49 | case 0x946: return "946"; 50 | case 0x966: return "966"; 51 | case 0xa20: return "1020"; 52 | case 0xa22: return "1022"; 53 | case 0xa26: return "1026"; 54 | case 0xb02: return "11 MPCore"; 55 | case 0xb36: return "1136"; 56 | case 0xb56: return "1156"; 57 | case 0xb76: return "1176"; 58 | case 0xc05: return " Cortex-A5"; 59 | case 0xc07: return " Cortex-A7"; 60 | case 0xc08: return " Cortex-A8"; 61 | case 0xc09: return " Cortex-A9"; 62 | case 0xc0c: return " Cortex-A12"; 63 | case 0xc0d: return " Rockchip RK3288"; 64 | case 0xc0f: return " Cortex-A15"; 65 | case 0xc0e: return " Cortex-A17"; 66 | case 0xc14: return " Cortex-R4"; 67 | case 0xc15: return " Cortex-R5"; 68 | case 0xc17: return " Cortex-R7"; 69 | case 0xc18: return " Cortex-R8"; 70 | case 0xc20: return " Cortex-M0"; 71 | case 0xc21: return " Cortex-M1"; 72 | case 0xc23: return " Cortex-M3"; 73 | case 0xc24: return " Cortex-M4"; 74 | case 0xc27: return " Cortex-M7"; 75 | case 0xc60: return " Cortex-M0+"; 76 | case 0xd00: return " AArch64 simulator"; 77 | case 0xd01: return " Cortex-A32"; 78 | case 0xd02: return " Cortex-A34"; 79 | case 0xd03: return " Cortex-A53"; 80 | case 0xd04: return " Cortex-A35"; 81 | case 0xd05: return " Cortex-A55"; 82 | case 0xd06: return " Cortex-A65"; 83 | case 0xd07: return " Cortex-A57"; 84 | case 0xd08: return " Cortex-A72"; 85 | case 0xd09: return " Cortex-A73"; 86 | case 0xd0a: return " Cortex-A75"; 87 | case 0xd0b: return " Cortex-A76"; 88 | case 0xd0c: return " Neoverse N1"; 89 | case 0xd0d: return " Cortex-A77"; 90 | case 0xd0e: return " Cortex-A76AE"; 91 | case 0xd0f: return " AEMv8"; 92 | case 0xd13: return " Cortex-R52"; 93 | case 0xd20: return " Cortex-M23"; 94 | case 0xd21: return " Cortex-M33"; 95 | case 0xd40: return " Zeus"; 96 | case 0xd41: return " Cortex-A78"; 97 | case 0xd43: return " Cortex-A65AE"; 98 | case 0xd44: return " Cortex-X1"; 99 | case 0xd4a: return " Neoverse E1"; 100 | default: break; 101 | } 102 | case 0x42: 103 | switch( part ) 104 | { 105 | case 0xf: return " Brahma B15"; 106 | case 0x100: return " Brahma B53"; 107 | case 0x516: return " ThunderX2"; 108 | default: break; 109 | } 110 | case 0x43: 111 | switch( part ) 112 | { 113 | case 0xa0: return " ThunderX"; 114 | case 0xa1: return " ThunderX 88XX"; 115 | case 0xa2: return " ThunderX 81XX"; 116 | case 0xa3: return " ThunderX 83XX"; 117 | case 0xaf: return " ThunderX2 99xx"; 118 | case 0xb0: return " OcteonTX2"; 119 | case 0xb1: return " OcteonTX2 T98"; 120 | case 0xb2: return " OcteonTX2 T96"; 121 | case 0xb3: return " OcteonTX2 F95"; 122 | case 0xb4: return " OcteonTX2 F95N"; 123 | case 0xb5: return " OcteonTX2 F95MM"; 124 | case 0xb8: return " ThunderX3 T110"; 125 | default: break; 126 | } 127 | case 0x44: 128 | switch( part ) 129 | { 130 | case 0xa10: return " SA110"; 131 | case 0xa11: return " SA1100"; 132 | default: break; 133 | } 134 | case 0x46: 135 | switch( part ) 136 | { 137 | case 0x1: return " A64FX"; 138 | default: break; 139 | } 140 | case 0x48: 141 | switch( part ) 142 | { 143 | case 0xd01: return " TSV100"; 144 | case 0xd40: return " Kirin 980"; 145 | default: break; 146 | } 147 | case 0x4e: 148 | switch( part ) 149 | { 150 | case 0x0: return " Denver"; 151 | case 0x3: return " Denver 2"; 152 | case 0x4: return " Carmel"; 153 | default: break; 154 | } 155 | case 0x50: 156 | switch( part ) 157 | { 158 | case 0x0: return " X-Gene"; 159 | default: break; 160 | } 161 | case 0x51: 162 | switch( part ) 163 | { 164 | case 0xf: return " Scorpion"; 165 | case 0x2d: return " Scorpion"; 166 | case 0x4d: return " Krait"; 167 | case 0x6f: return " Krait"; 168 | case 0x200: return " Kryo"; 169 | case 0x201: return " Kryo Silver (Snapdragon 821)"; 170 | case 0x205: return " Kryo Gold"; 171 | case 0x211: return " Kryo Silver (Snapdragon 820)"; 172 | case 0x800: return " Kryo 260 / 280 Gold"; 173 | case 0x801: return " Kryo 260 / 280 Silver"; 174 | case 0x802: return " Kryo 385 Gold"; 175 | case 0x803: return " Kryo 385 Silver"; 176 | case 0x804: return " Kryo 485 Gold"; 177 | case 0xc00: return " Falkor"; 178 | case 0xc01: return " Saphira"; 179 | default: break; 180 | } 181 | case 0x53: 182 | switch( part ) 183 | { 184 | case 0x1: return " Exynos M1/M2"; 185 | case 0x2: return " Exynos M3"; 186 | default: break; 187 | } 188 | case 0x56: 189 | switch( part ) 190 | { 191 | case 0x131: return " Feroceon 88FR131"; 192 | case 0x581: return " PJ4 / PJ4B"; 193 | case 0x584: return " PJ4B-MP / PJ4C"; 194 | default: break; 195 | } 196 | case 0x61: 197 | switch( part ) 198 | { 199 | case 0x1: return " Cyclone"; 200 | case 0x2: return " Typhoon"; 201 | case 0x3: return " Typhoon/Capri"; 202 | case 0x4: return " Twister"; 203 | case 0x5: return " Twister/Elba/Malta"; 204 | case 0x6: return " Hurricane"; 205 | case 0x7: return " Hurricane/Myst"; 206 | default: break; 207 | } 208 | case 0x66: 209 | switch( part ) 210 | { 211 | case 0x526: return " FA526"; 212 | case 0x626: return " FA626"; 213 | default: break; 214 | } 215 | case 0x68: 216 | switch( part ) 217 | { 218 | case 0x0: return " Phecda"; 219 | default: break; 220 | } 221 | default: break; 222 | } 223 | sprintf( buf, " 0x%x", part ); 224 | return buf; 225 | } 226 | 227 | #elif defined __APPLE__ && TARGET_OS_IPHONE == 1 228 | 229 | static const char* DecodeIosDevice( const char* id ) 230 | { 231 | static const char* DeviceTable[] = { 232 | "i386", "32-bit simulator", 233 | "x86_64", "64-bit simulator", 234 | "iPhone1,1", "iPhone", 235 | "iPhone1,2", "iPhone 3G", 236 | "iPhone2,1", "iPhone 3GS", 237 | "iPhone3,1", "iPhone 4 (GSM)", 238 | "iPhone3,2", "iPhone 4 (GSM)", 239 | "iPhone3,3", "iPhone 4 (CDMA)", 240 | "iPhone4,1", "iPhone 4S", 241 | "iPhone5,1", "iPhone 5 (A1428)", 242 | "iPhone5,2", "iPhone 5 (A1429)", 243 | "iPhone5,3", "iPhone 5c (A1456/A1532)", 244 | "iPhone5,4", "iPhone 5c (A1507/A1516/1526/A1529)", 245 | "iPhone6,1", "iPhone 5s (A1433/A1533)", 246 | "iPhone6,2", "iPhone 5s (A1457/A1518/A1528/A1530)", 247 | "iPhone7,1", "iPhone 6 Plus", 248 | "iPhone7,2", "iPhone 6", 249 | "iPhone8,1", "iPhone 6S", 250 | "iPhone8,2", "iPhone 6S Plus", 251 | "iPhone8,4", "iPhone SE", 252 | "iPhone9,1", "iPhone 7 (CDMA)", 253 | "iPhone9,2", "iPhone 7 Plus (CDMA)", 254 | "iPhone9,3", "iPhone 7 (GSM)", 255 | "iPhone9,4", "iPhone 7 Plus (GSM)", 256 | "iPhone10,1", "iPhone 8 (CDMA)", 257 | "iPhone10,2", "iPhone 8 Plus (CDMA)", 258 | "iPhone10,3", "iPhone X (CDMA)", 259 | "iPhone10,4", "iPhone 8 (GSM)", 260 | "iPhone10,5", "iPhone 8 Plus (GSM)", 261 | "iPhone10,6", "iPhone X (GSM)", 262 | "iPhone11,2", "iPhone XS", 263 | "iPhone11,4", "iPhone XS Max", 264 | "iPhone11,6", "iPhone XS Max China", 265 | "iPhone11,8", "iPhone XR", 266 | "iPhone12,1", "iPhone 11", 267 | "iPhone12,3", "iPhone 11 Pro", 268 | "iPhone12,5", "iPhone 11 Pro Max", 269 | "iPhone12,8", "iPhone SE 2nd Gen", 270 | "iPad1,1", "iPad (A1219/A1337)", 271 | "iPad2,1", "iPad 2 (A1395)", 272 | "iPad2,2", "iPad 2 (A1396)", 273 | "iPad2,3", "iPad 2 (A1397)", 274 | "iPad2,4", "iPad 2 (A1395)", 275 | "iPad2,5", "iPad Mini (A1432)", 276 | "iPad2,6", "iPad Mini (A1454)", 277 | "iPad2,7", "iPad Mini (A1455)", 278 | "iPad3,1", "iPad 3 (A1416)", 279 | "iPad3,2", "iPad 3 (A1403)", 280 | "iPad3,3", "iPad 3 (A1430)", 281 | "iPad3,4", "iPad 4 (A1458)", 282 | "iPad3,5", "iPad 4 (A1459)", 283 | "iPad3,6", "iPad 4 (A1460)", 284 | "iPad4,1", "iPad Air (A1474)", 285 | "iPad4,2", "iPad Air (A1475)", 286 | "iPad4,3", "iPad Air (A1476)", 287 | "iPad4,4", "iPad Mini 2 (A1489)", 288 | "iPad4,5", "iPad Mini 2 (A1490)", 289 | "iPad4,6", "iPad Mini 2 (A1491)", 290 | "iPad4,7", "iPad Mini 3 (A1599)", 291 | "iPad4,8", "iPad Mini 3 (A1600)", 292 | "iPad4,9", "iPad Mini 3 (A1601)", 293 | "iPad5,1", "iPad Mini 4 (A1538)", 294 | "iPad5,2", "iPad Mini 4 (A1550)", 295 | "iPad5,3", "iPad Air 2 (A1566)", 296 | "iPad5,4", "iPad Air 2 (A1567)", 297 | "iPad6,3", "iPad Pro 9.7\" (A1673)", 298 | "iPad6,4", "iPad Pro 9.7\" (A1674)", 299 | "iPad6,5", "iPad Pro 9.7\" (A1675)", 300 | "iPad6,7", "iPad Pro 12.9\" (A1584)", 301 | "iPad6,8", "iPad Pro 12.9\" (A1652)", 302 | "iPad6,11", "iPad 5th gen (A1822)", 303 | "iPad6,12", "iPad 5th gen (A1823)", 304 | "iPad7,1", "iPad Pro 12.9\" 2nd gen (A1670)", 305 | "iPad7,2", "iPad Pro 12.9\" 2nd gen (A1671/A1821)", 306 | "iPad7,3", "iPad Pro 10.5\" (A1701)", 307 | "iPad7,4", "iPad Pro 10.5\" (A1709)", 308 | "iPad7,5", "iPad 6th gen (A1893)", 309 | "iPad7,6", "iPad 6th gen (A1954)", 310 | "iPad7,11", "iPad 7th gen 10.2\" (Wifi)", 311 | "iPad7,12", "iPad 7th gen 10.2\" (Wifi+Cellular)", 312 | "iPad8,1", "iPad Pro 11\" (A1980)", 313 | "iPad8,2", "iPad Pro 11\" (A1980)", 314 | "iPad8,3", "iPad Pro 11\" (A1934/A1979/A2013)", 315 | "iPad8,4", "iPad Pro 11\" (A1934/A1979/A2013)", 316 | "iPad8,5", "iPad Pro 12.9\" 3rd gen (A1876)", 317 | "iPad8,6", "iPad Pro 12.9\" 3rd gen (A1876)", 318 | "iPad8,7", "iPad Pro 12.9\" 3rd gen (A1895/A1983/A2014)", 319 | "iPad8,8", "iPad Pro 12.9\" 3rd gen (A1895/A1983/A2014)", 320 | "iPad8,9", "iPad Pro 11\" 2nd gen (Wifi)", 321 | "iPad8,10", "iPad Pro 11\" 2nd gen (Wifi+Cellular)", 322 | "iPad8,11", "iPad Pro 12.9\" 4th gen (Wifi)", 323 | "iPad8,12", "iPad Pro 12.9\" 4th gen (Wifi+Cellular)", 324 | "iPad11,1", "iPad Mini 5th gen (A2133)", 325 | "iPad11,2", "iPad Mini 5th gen (A2124/A2125/A2126)", 326 | "iPad11,3", "iPad Air 3rd gen (A2152)", 327 | "iPad11,4", "iPad Air 3rd gen (A2123/A2153/A2154)", 328 | "iPod1,1", "iPod Touch", 329 | "iPod2,1", "iPod Touch 2nd gen", 330 | "iPod3,1", "iPod Touch 3rd gen", 331 | "iPod4,1", "iPod Touch 4th gen", 332 | "iPod5,1", "iPod Touch 5th gen", 333 | "iPod7,1", "iPod Touch 6th gen", 334 | "iPod9,1", "iPod Touch 7th gen", 335 | nullptr 336 | }; 337 | 338 | auto ptr = DeviceTable; 339 | while( *ptr ) 340 | { 341 | if( strcmp( ptr[0], id ) == 0 ) return ptr[1]; 342 | ptr += 2; 343 | } 344 | return id; 345 | } 346 | 347 | #endif 348 | 349 | } 350 | -------------------------------------------------------------------------------- /tracy-0.7.8/client/TracyCallstack.h: -------------------------------------------------------------------------------- 1 | #ifndef __TRACYCALLSTACK_H__ 2 | #define __TRACYCALLSTACK_H__ 3 | 4 | #if !defined _WIN32 && !defined __CYGWIN__ 5 | # include 6 | #endif 7 | 8 | #if defined _WIN32 || defined __CYGWIN__ 9 | # define TRACY_HAS_CALLSTACK 1 10 | #elif defined __ANDROID__ 11 | # if !defined __arm__ || __ANDROID_API__ >= 21 12 | # define TRACY_HAS_CALLSTACK 2 13 | # else 14 | # define TRACY_HAS_CALLSTACK 5 15 | # endif 16 | #elif defined __linux 17 | # if defined _GNU_SOURCE && defined __GLIBC__ 18 | # define TRACY_HAS_CALLSTACK 3 19 | # else 20 | # define TRACY_HAS_CALLSTACK 2 21 | # endif 22 | #elif defined __APPLE__ 23 | # define TRACY_HAS_CALLSTACK 4 24 | #elif defined BSD 25 | # define TRACY_HAS_CALLSTACK 6 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /tracy-0.7.8/client/TracyCallstack.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __TRACYCALLSTACK_HPP__ 2 | #define __TRACYCALLSTACK_HPP__ 3 | 4 | #include "../common/TracyApi.h" 5 | #include "TracyCallstack.h" 6 | 7 | #if TRACY_HAS_CALLSTACK == 2 || TRACY_HAS_CALLSTACK == 5 8 | # include 9 | #elif TRACY_HAS_CALLSTACK >= 3 10 | # include 11 | #endif 12 | 13 | 14 | #ifdef TRACY_HAS_CALLSTACK 15 | 16 | #include 17 | #include 18 | 19 | #include "../common/TracyAlloc.hpp" 20 | #include "../common/TracyForceInline.hpp" 21 | 22 | namespace tracy 23 | { 24 | 25 | struct CallstackSymbolData 26 | { 27 | const char* file; 28 | uint32_t line; 29 | bool needFree; 30 | }; 31 | 32 | struct CallstackEntry 33 | { 34 | const char* name; 35 | const char* file; 36 | uint32_t line; 37 | uint32_t symLen; 38 | uint64_t symAddr; 39 | }; 40 | 41 | struct CallstackEntryData 42 | { 43 | const CallstackEntry* data; 44 | uint8_t size; 45 | const char* imageName; 46 | }; 47 | 48 | CallstackSymbolData DecodeSymbolAddress( uint64_t ptr ); 49 | CallstackSymbolData DecodeCodeAddress( uint64_t ptr ); 50 | const char* DecodeCallstackPtrFast( uint64_t ptr ); 51 | CallstackEntryData DecodeCallstackPtr( uint64_t ptr ); 52 | void InitCallstack(); 53 | 54 | #if TRACY_HAS_CALLSTACK == 1 55 | 56 | TRACY_API uintptr_t* CallTrace( int depth ); 57 | 58 | static tracy_force_inline void* Callstack( int depth ) 59 | { 60 | assert( depth >= 1 && depth < 63 ); 61 | return CallTrace( depth ); 62 | } 63 | 64 | #elif TRACY_HAS_CALLSTACK == 2 || TRACY_HAS_CALLSTACK == 5 65 | 66 | struct BacktraceState 67 | { 68 | void** current; 69 | void** end; 70 | }; 71 | 72 | static _Unwind_Reason_Code tracy_unwind_callback( struct _Unwind_Context* ctx, void* arg ) 73 | { 74 | auto state = (BacktraceState*)arg; 75 | uintptr_t pc = _Unwind_GetIP( ctx ); 76 | if( pc ) 77 | { 78 | if( state->current == state->end ) return _URC_END_OF_STACK; 79 | *state->current++ = (void*)pc; 80 | } 81 | return _URC_NO_REASON; 82 | } 83 | 84 | static tracy_force_inline void* Callstack( int depth ) 85 | { 86 | assert( depth >= 1 && depth < 63 ); 87 | 88 | auto trace = (uintptr_t*)tracy_malloc( ( 1 + depth ) * sizeof( uintptr_t ) ); 89 | BacktraceState state = { (void**)(trace+1), (void**)(trace+1+depth) }; 90 | _Unwind_Backtrace( tracy_unwind_callback, &state ); 91 | 92 | *trace = (uintptr_t*)state.current - trace + 1; 93 | 94 | return trace; 95 | } 96 | 97 | #elif TRACY_HAS_CALLSTACK == 3 || TRACY_HAS_CALLSTACK == 4 || TRACY_HAS_CALLSTACK == 6 98 | 99 | static tracy_force_inline void* Callstack( int depth ) 100 | { 101 | assert( depth >= 1 ); 102 | 103 | auto trace = (uintptr_t*)tracy_malloc( ( 1 + (size_t)depth ) * sizeof( uintptr_t ) ); 104 | const auto num = (size_t)backtrace( (void**)(trace+1), depth ); 105 | *trace = num; 106 | 107 | return trace; 108 | } 109 | 110 | #endif 111 | 112 | } 113 | 114 | #endif 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /tracy-0.7.8/client/TracyDxt1.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __TRACYDXT1_HPP__ 2 | #define __TRACYDXT1_HPP__ 3 | 4 | namespace tracy 5 | { 6 | 7 | void CompressImageDxt1( const char* src, char* dst, int w, int h ); 8 | 9 | } 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /tracy-0.7.8/client/TracyFastVector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __TRACYFASTVECTOR_HPP__ 2 | #define __TRACYFASTVECTOR_HPP__ 3 | 4 | #include 5 | #include 6 | 7 | #include "../common/TracyAlloc.hpp" 8 | #include "../common/TracyForceInline.hpp" 9 | 10 | namespace tracy 11 | { 12 | 13 | template 14 | class FastVector 15 | { 16 | public: 17 | using iterator = T*; 18 | using const_iterator = const T*; 19 | 20 | FastVector( size_t capacity ) 21 | : m_ptr( (T*)tracy_malloc( sizeof( T ) * capacity ) ) 22 | , m_write( m_ptr ) 23 | , m_end( m_ptr + capacity ) 24 | { 25 | assert( capacity != 0 ); 26 | } 27 | 28 | FastVector( const FastVector& ) = delete; 29 | FastVector( FastVector&& ) = delete; 30 | 31 | ~FastVector() 32 | { 33 | tracy_free( m_ptr ); 34 | } 35 | 36 | FastVector& operator=( const FastVector& ) = delete; 37 | FastVector& operator=( FastVector&& ) = delete; 38 | 39 | bool empty() const { return m_ptr == m_write; } 40 | size_t size() const { return m_write - m_ptr; } 41 | 42 | T* data() { return m_ptr; } 43 | const T* data() const { return m_ptr; }; 44 | 45 | T* begin() { return m_ptr; } 46 | const T* begin() const { return m_ptr; } 47 | T* end() { return m_write; } 48 | const T* end() const { return m_write; } 49 | 50 | T& front() { assert( !empty() ); return m_ptr[0]; } 51 | const T& front() const { assert( !empty() ); return m_ptr[0]; } 52 | 53 | T& back() { assert( !empty() ); return m_write[-1]; } 54 | const T& back() const { assert( !empty() ); return m_write[-1]; } 55 | 56 | T& operator[]( size_t idx ) { return m_ptr[idx]; } 57 | const T& operator[]( size_t idx ) const { return m_ptr[idx]; } 58 | 59 | T* push_next() 60 | { 61 | if( m_write == m_end ) AllocMore(); 62 | return m_write++; 63 | } 64 | 65 | T* prepare_next() 66 | { 67 | if( m_write == m_end ) AllocMore(); 68 | return m_write; 69 | } 70 | 71 | void commit_next() 72 | { 73 | m_write++; 74 | } 75 | 76 | void clear() 77 | { 78 | m_write = m_ptr; 79 | } 80 | 81 | void swap( FastVector& vec ) 82 | { 83 | const auto ptr1 = m_ptr; 84 | const auto ptr2 = vec.m_ptr; 85 | const auto write1 = m_write; 86 | const auto write2 = vec.m_write; 87 | const auto end1 = m_end; 88 | const auto end2 = vec.m_end; 89 | 90 | m_ptr = ptr2; 91 | vec.m_ptr = ptr1; 92 | m_write = write2; 93 | vec.m_write = write1; 94 | m_end = end2; 95 | vec.m_end = end1; 96 | } 97 | 98 | private: 99 | tracy_no_inline void AllocMore() 100 | { 101 | const auto cap = size_t( m_end - m_ptr ) * 2; 102 | const auto size = size_t( m_write - m_ptr ); 103 | T* ptr = (T*)tracy_malloc( sizeof( T ) * cap ); 104 | memcpy( ptr, m_ptr, size * sizeof( T ) ); 105 | tracy_free( m_ptr ); 106 | m_ptr = ptr; 107 | m_write = m_ptr + size; 108 | m_end = m_ptr + cap; 109 | } 110 | 111 | T* m_ptr; 112 | T* m_write; 113 | T* m_end; 114 | }; 115 | 116 | } 117 | 118 | #endif 119 | -------------------------------------------------------------------------------- /tracy-0.7.8/client/TracyRingBuffer.hpp: -------------------------------------------------------------------------------- 1 | namespace tracy 2 | { 3 | 4 | template 5 | class RingBuffer 6 | { 7 | public: 8 | RingBuffer( int fd ) 9 | : m_fd( fd ) 10 | { 11 | const auto pageSize = uint32_t( getpagesize() ); 12 | assert( Size >= pageSize ); 13 | assert( __builtin_popcount( Size ) == 1 ); 14 | m_mapSize = Size + pageSize; 15 | auto mapAddr = mmap( nullptr, m_mapSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 ); 16 | if( !mapAddr ) 17 | { 18 | m_fd = 0; 19 | close( fd ); 20 | return; 21 | } 22 | m_metadata = (perf_event_mmap_page*)mapAddr; 23 | assert( m_metadata->data_offset == pageSize ); 24 | m_buffer = ((char*)mapAddr) + pageSize; 25 | } 26 | 27 | ~RingBuffer() 28 | { 29 | if( m_metadata ) munmap( m_metadata, m_mapSize ); 30 | if( m_fd ) close( m_fd ); 31 | } 32 | 33 | RingBuffer( const RingBuffer& ) = delete; 34 | RingBuffer& operator=( const RingBuffer& ) = delete; 35 | 36 | RingBuffer( RingBuffer&& other ) 37 | { 38 | memcpy( (char*)&other, (char*)this, sizeof( RingBuffer ) ); 39 | m_metadata = nullptr; 40 | m_fd = 0; 41 | } 42 | 43 | RingBuffer& operator=( RingBuffer&& other ) 44 | { 45 | memcpy( (char*)&other, (char*)this, sizeof( RingBuffer ) ); 46 | m_metadata = nullptr; 47 | m_fd = 0; 48 | return *this; 49 | } 50 | 51 | bool IsValid() const { return m_metadata != nullptr; } 52 | 53 | void Enable() 54 | { 55 | ioctl( m_fd, PERF_EVENT_IOC_ENABLE, 0 ); 56 | } 57 | 58 | bool HasData() const 59 | { 60 | const auto head = LoadHead(); 61 | return head > m_metadata->data_tail; 62 | } 63 | 64 | void Read( void* dst, uint64_t offset, uint64_t cnt ) 65 | { 66 | auto src = ( m_metadata->data_tail + offset ) % Size; 67 | if( src + cnt <= Size ) 68 | { 69 | memcpy( dst, m_buffer + src, cnt ); 70 | } 71 | else 72 | { 73 | const auto s0 = Size - src; 74 | memcpy( dst, m_buffer + src, s0 ); 75 | memcpy( (char*)dst + s0, m_buffer, cnt - s0 ); 76 | } 77 | } 78 | 79 | void Advance( uint64_t cnt ) 80 | { 81 | StoreTail( m_metadata->data_tail + cnt ); 82 | } 83 | 84 | bool CheckTscCaps() const 85 | { 86 | return m_metadata->cap_user_time_zero; 87 | } 88 | 89 | int64_t ConvertTimeToTsc( int64_t timestamp ) const 90 | { 91 | assert( m_metadata->cap_user_time_zero ); 92 | const auto time = timestamp - m_metadata->time_zero; 93 | const auto quot = time / m_metadata->time_mult; 94 | const auto rem = time % m_metadata->time_mult; 95 | return ( quot << m_metadata->time_shift ) + ( rem << m_metadata->time_shift ) / m_metadata->time_mult; 96 | } 97 | 98 | private: 99 | uint64_t LoadHead() const 100 | { 101 | return std::atomic_load_explicit( (const volatile std::atomic*)&m_metadata->data_head, std::memory_order_acquire ); 102 | } 103 | 104 | void StoreTail( uint64_t tail ) 105 | { 106 | std::atomic_store_explicit( (volatile std::atomic*)&m_metadata->data_tail, tail, std::memory_order_release ); 107 | } 108 | 109 | perf_event_mmap_page* m_metadata; 110 | char* m_buffer; 111 | 112 | size_t m_mapSize; 113 | int m_fd; 114 | }; 115 | 116 | } 117 | -------------------------------------------------------------------------------- /tracy-0.7.8/client/TracyScoped.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __TRACYSCOPED_HPP__ 2 | #define __TRACYSCOPED_HPP__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "../common/TracySystem.hpp" 9 | #include "../common/TracyAlign.hpp" 10 | #include "../common/TracyAlloc.hpp" 11 | #include "TracyProfiler.hpp" 12 | 13 | namespace tracy 14 | { 15 | 16 | class ScopedZone 17 | { 18 | public: 19 | ScopedZone( const ScopedZone& ) = delete; 20 | ScopedZone( ScopedZone&& ) = delete; 21 | ScopedZone& operator=( const ScopedZone& ) = delete; 22 | ScopedZone& operator=( ScopedZone&& ) = delete; 23 | 24 | tracy_force_inline ScopedZone( const SourceLocationData* srcloc, bool is_active = true ) 25 | #ifdef TRACY_ON_DEMAND 26 | : m_active( is_active && GetProfiler().IsConnected() ) 27 | #else 28 | : m_active( is_active ) 29 | #endif 30 | { 31 | if( !m_active ) return; 32 | #ifdef TRACY_ON_DEMAND 33 | m_connectionId = GetProfiler().ConnectionId(); 34 | #endif 35 | TracyLfqPrepare( QueueType::ZoneBegin ); 36 | MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); 37 | MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc ); 38 | TracyLfqCommit; 39 | } 40 | 41 | tracy_force_inline ScopedZone( const SourceLocationData* srcloc, int depth, bool is_active = true ) 42 | #ifdef TRACY_ON_DEMAND 43 | : m_active( is_active && GetProfiler().IsConnected() ) 44 | #else 45 | : m_active( is_active ) 46 | #endif 47 | { 48 | if( !m_active ) return; 49 | #ifdef TRACY_ON_DEMAND 50 | m_connectionId = GetProfiler().ConnectionId(); 51 | #endif 52 | GetProfiler().SendCallstack( depth ); 53 | 54 | TracyLfqPrepare( QueueType::ZoneBeginCallstack ); 55 | MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); 56 | MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc ); 57 | TracyLfqCommit; 58 | } 59 | 60 | tracy_force_inline ScopedZone( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const char* name, size_t nameSz, bool is_active = true ) 61 | #ifdef TRACY_ON_DEMAND 62 | : m_active( is_active && GetProfiler().IsConnected() ) 63 | #else 64 | : m_active( is_active ) 65 | #endif 66 | { 67 | if( !m_active ) return; 68 | #ifdef TRACY_ON_DEMAND 69 | m_connectionId = GetProfiler().ConnectionId(); 70 | #endif 71 | TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLoc ); 72 | const auto srcloc = Profiler::AllocSourceLocation( line, source, sourceSz, function, functionSz, name, nameSz ); 73 | MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); 74 | MemWrite( &item->zoneBegin.srcloc, srcloc ); 75 | TracyLfqCommit; 76 | } 77 | 78 | tracy_force_inline ScopedZone( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const char* name, size_t nameSz, int depth, bool is_active = true ) 79 | #ifdef TRACY_ON_DEMAND 80 | : m_active( is_active && GetProfiler().IsConnected() ) 81 | #else 82 | : m_active( is_active ) 83 | #endif 84 | { 85 | if( !m_active ) return; 86 | #ifdef TRACY_ON_DEMAND 87 | m_connectionId = GetProfiler().ConnectionId(); 88 | #endif 89 | GetProfiler().SendCallstack( depth ); 90 | 91 | TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLocCallstack ); 92 | const auto srcloc = Profiler::AllocSourceLocation( line, source, sourceSz, function, functionSz, name, nameSz ); 93 | MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); 94 | MemWrite( &item->zoneBegin.srcloc, srcloc ); 95 | TracyLfqCommit; 96 | } 97 | 98 | tracy_force_inline ~ScopedZone() 99 | { 100 | if( !m_active ) return; 101 | #ifdef TRACY_ON_DEMAND 102 | if( GetProfiler().ConnectionId() != m_connectionId ) return; 103 | #endif 104 | TracyLfqPrepare( QueueType::ZoneEnd ); 105 | MemWrite( &item->zoneEnd.time, Profiler::GetTime() ); 106 | TracyLfqCommit; 107 | } 108 | 109 | tracy_force_inline void Text( const char* txt, size_t size ) 110 | { 111 | assert( size < std::numeric_limits::max() ); 112 | if( !m_active ) return; 113 | #ifdef TRACY_ON_DEMAND 114 | if( GetProfiler().ConnectionId() != m_connectionId ) return; 115 | #endif 116 | auto ptr = (char*)tracy_malloc( size ); 117 | memcpy( ptr, txt, size ); 118 | TracyLfqPrepare( QueueType::ZoneText ); 119 | MemWrite( &item->zoneTextFat.text, (uint64_t)ptr ); 120 | MemWrite( &item->zoneTextFat.size, (uint16_t)size ); 121 | TracyLfqCommit; 122 | } 123 | 124 | tracy_force_inline void Name( const char* txt, size_t size ) 125 | { 126 | assert( size < std::numeric_limits::max() ); 127 | if( !m_active ) return; 128 | #ifdef TRACY_ON_DEMAND 129 | if( GetProfiler().ConnectionId() != m_connectionId ) return; 130 | #endif 131 | auto ptr = (char*)tracy_malloc( size ); 132 | memcpy( ptr, txt, size ); 133 | TracyLfqPrepare( QueueType::ZoneName ); 134 | MemWrite( &item->zoneTextFat.text, (uint64_t)ptr ); 135 | MemWrite( &item->zoneTextFat.size, (uint16_t)size ); 136 | TracyLfqCommit; 137 | } 138 | 139 | tracy_force_inline void Color( uint32_t color ) 140 | { 141 | if( !m_active ) return; 142 | #ifdef TRACY_ON_DEMAND 143 | if( GetProfiler().ConnectionId() != m_connectionId ) return; 144 | #endif 145 | TracyLfqPrepare( QueueType::ZoneColor ); 146 | MemWrite( &item->zoneColor.r, uint8_t( ( color ) & 0xFF ) ); 147 | MemWrite( &item->zoneColor.g, uint8_t( ( color >> 8 ) & 0xFF ) ); 148 | MemWrite( &item->zoneColor.b, uint8_t( ( color >> 16 ) & 0xFF ) ); 149 | TracyLfqCommit; 150 | } 151 | 152 | tracy_force_inline void Value( uint64_t value ) 153 | { 154 | if( !m_active ) return; 155 | #ifdef TRACY_ON_DEMAND 156 | if( GetProfiler().ConnectionId() != m_connectionId ) return; 157 | #endif 158 | TracyLfqPrepare( QueueType::ZoneValue ); 159 | MemWrite( &item->zoneValue.value, value ); 160 | TracyLfqCommit; 161 | } 162 | 163 | tracy_force_inline bool IsActive() const { return m_active; } 164 | 165 | private: 166 | const bool m_active; 167 | 168 | #ifdef TRACY_ON_DEMAND 169 | uint64_t m_connectionId; 170 | #endif 171 | }; 172 | 173 | } 174 | 175 | #endif 176 | -------------------------------------------------------------------------------- /tracy-0.7.8/client/TracySysTime.cpp: -------------------------------------------------------------------------------- 1 | #include "TracySysTime.hpp" 2 | 3 | #ifdef TRACY_HAS_SYSTIME 4 | 5 | # if defined _WIN32 || defined __CYGWIN__ 6 | # include 7 | # elif defined __linux__ 8 | # include 9 | # include 10 | # elif defined __APPLE__ 11 | # include 12 | # include 13 | # elif defined BSD 14 | # include 15 | # include 16 | # endif 17 | 18 | namespace tracy 19 | { 20 | 21 | # if defined _WIN32 || defined __CYGWIN__ 22 | 23 | static inline uint64_t ConvertTime( const FILETIME& t ) 24 | { 25 | return ( uint64_t( t.dwHighDateTime ) << 32 ) | uint64_t( t.dwLowDateTime ); 26 | } 27 | 28 | void SysTime::ReadTimes() 29 | { 30 | FILETIME idleTime; 31 | FILETIME kernelTime; 32 | FILETIME userTime; 33 | 34 | GetSystemTimes( &idleTime, &kernelTime, &userTime ); 35 | 36 | idle = ConvertTime( idleTime ); 37 | const auto kernel = ConvertTime( kernelTime ); 38 | const auto user = ConvertTime( userTime ); 39 | used = kernel + user; 40 | } 41 | 42 | # elif defined __linux__ 43 | 44 | void SysTime::ReadTimes() 45 | { 46 | uint64_t user, nice, system; 47 | FILE* f = fopen( "/proc/stat", "r" ); 48 | if( f ) 49 | { 50 | int read = fscanf( f, "cpu %" PRIu64 " %" PRIu64 " %" PRIu64" %" PRIu64, &user, &nice, &system, &idle ); 51 | fclose( f ); 52 | if (read == 4) 53 | { 54 | used = user + nice + system; 55 | } 56 | } 57 | } 58 | 59 | # elif defined __APPLE__ 60 | 61 | void SysTime::ReadTimes() 62 | { 63 | host_cpu_load_info_data_t info; 64 | mach_msg_type_number_t cnt = HOST_CPU_LOAD_INFO_COUNT; 65 | host_statistics( mach_host_self(), HOST_CPU_LOAD_INFO, reinterpret_cast( &info ), &cnt ); 66 | used = info.cpu_ticks[CPU_STATE_USER] + info.cpu_ticks[CPU_STATE_NICE] + info.cpu_ticks[CPU_STATE_SYSTEM]; 67 | idle = info.cpu_ticks[CPU_STATE_IDLE]; 68 | } 69 | 70 | # elif defined BSD 71 | 72 | void SysTime::ReadTimes() 73 | { 74 | u_long data[5]; 75 | size_t sz = sizeof( data ); 76 | sysctlbyname( "kern.cp_time", &data, &sz, nullptr, 0 ); 77 | used = data[0] + data[1] + data[2] + data[3]; 78 | idle = data[4]; 79 | } 80 | 81 | #endif 82 | 83 | SysTime::SysTime() 84 | { 85 | ReadTimes(); 86 | } 87 | 88 | float SysTime::Get() 89 | { 90 | const auto oldUsed = used; 91 | const auto oldIdle = idle; 92 | 93 | ReadTimes(); 94 | 95 | const auto diffIdle = idle - oldIdle; 96 | const auto diffUsed = used - oldUsed; 97 | 98 | #if defined _WIN32 || defined __CYGWIN__ 99 | return diffUsed == 0 ? -1 : ( diffUsed - diffIdle ) * 100.f / diffUsed; 100 | #elif defined __linux__ || defined __APPLE__ || defined BSD 101 | const auto total = diffUsed + diffIdle; 102 | return total == 0 ? -1 : diffUsed * 100.f / total; 103 | #endif 104 | } 105 | 106 | } 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /tracy-0.7.8/client/TracySysTime.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __TRACYSYSTIME_HPP__ 2 | #define __TRACYSYSTIME_HPP__ 3 | 4 | #if defined _WIN32 || defined __CYGWIN__ || defined __linux__ || defined __APPLE__ 5 | # define TRACY_HAS_SYSTIME 6 | #else 7 | # include 8 | #endif 9 | 10 | #ifdef BSD 11 | # define TRACY_HAS_SYSTIME 12 | #endif 13 | 14 | #ifdef TRACY_HAS_SYSTIME 15 | 16 | #include 17 | 18 | namespace tracy 19 | { 20 | 21 | class SysTime 22 | { 23 | public: 24 | SysTime(); 25 | float Get(); 26 | 27 | void ReadTimes(); 28 | 29 | private: 30 | uint64_t idle, used; 31 | }; 32 | 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /tracy-0.7.8/client/TracySysTrace.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __TRACYSYSTRACE_HPP__ 2 | #define __TRACYSYSTRACE_HPP__ 3 | 4 | #if !defined TRACY_NO_SYSTEM_TRACING && ( defined _WIN32 || defined __CYGWIN__ || defined __linux__ ) 5 | # define TRACY_HAS_SYSTEM_TRACING 6 | #endif 7 | 8 | #ifdef TRACY_HAS_SYSTEM_TRACING 9 | 10 | #include 11 | 12 | namespace tracy 13 | { 14 | 15 | bool SysTraceStart( int64_t& samplingPeriod ); 16 | void SysTraceStop(); 17 | void SysTraceWorker( void* ptr ); 18 | 19 | void SysTraceSendExternalName( uint64_t thread ); 20 | 21 | } 22 | 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /tracy-0.7.8/client/TracySysTracePayload.hpp: -------------------------------------------------------------------------------- 1 | // File: 'extra/systrace/tracy_systrace.armv7' (1149 bytes) 2 | // File: 'extra/systrace/tracy_systrace.aarch64' (1650 bytes) 3 | 4 | // Exported using binary_to_compressed_c.cpp 5 | 6 | namespace tracy 7 | { 8 | 9 | static const unsigned int tracy_systrace_armv7_size = 1149; 10 | static const unsigned int tracy_systrace_armv7_data[1152/4] = 11 | { 12 | 0x464c457f, 0x00010101, 0x00000000, 0x00000000, 0x00280003, 0x00000001, 0x000001f0, 0x00000034, 0x00000000, 0x05000200, 0x00200034, 0x00280007, 13 | 0x00000000, 0x00000006, 0x00000034, 0x00000034, 0x00000034, 0x000000e0, 0x000000e0, 0x00000004, 0x00000004, 0x00000003, 0x00000114, 0x00000114, 14 | 0x00000114, 0x00000013, 0x00000013, 0x00000004, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x000003fd, 0x000003fd, 0x00000005, 15 | 0x00001000, 0x00000001, 0x000003fd, 0x000013fd, 0x000013fd, 0x00000080, 0x000000b3, 0x00000006, 0x00001000, 0x00000002, 0x00000400, 0x00001400, 16 | 0x00001400, 0x0000007d, 0x000000b0, 0x00000006, 0x00000004, 0x6474e551, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000006, 17 | 0x00000004, 0x70000001, 0x000003a4, 0x000003a4, 0x000003a4, 0x00000008, 0x00000008, 0x00000004, 0x00000004, 0x7379732f, 0x2f6d6574, 0x2f6e6962, 18 | 0x6b6e696c, 0x00007265, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000012, 0x00000016, 0x00000000, 19 | 0x00000000, 0x00000012, 0x6f6c6400, 0x006e6570, 0x4342494c, 0x62696c00, 0x732e6c64, 0x6c64006f, 0x006d7973, 0x00000001, 0x00000003, 0x00000001, 20 | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00010001, 0x0000000d, 0x00000010, 0x00000000, 0x00050d63, 0x00020000, 0x00000008, 21 | 0x00000000, 0x000014bc, 0x00000116, 0x000014c0, 0x00000216, 0xe52de004, 0xe59fe004, 0xe08fe00e, 0xe5bef008, 0x000012dc, 0xe28fc600, 0xe28cca01, 22 | 0xe5bcf2dc, 0xe28fc600, 0xe28cca01, 0xe5bcf2d4, 0xe92d4ff0, 0xe28db01c, 0xe24dd024, 0xe24dd801, 0xe59f017c, 0xe3a01001, 0xe3a08001, 0xe08f0000, 23 | 0xebfffff0, 0xe59f116c, 0xe1a04000, 0xe08f1001, 0xebffffef, 0xe59f1160, 0xe1a06000, 0xe1a00004, 0xe08f1001, 0xebffffea, 0xe59f1150, 0xe1a07000, 24 | 0xe1a00004, 0xe08f1001, 0xebffffe5, 0xe59f1140, 0xe1a05000, 0xe1a00004, 0xe08f1001, 0xebffffe0, 0xe58d0004, 0xe1a00004, 0xe59f1128, 0xe08f1001, 25 | 0xebffffdb, 0xe59f1120, 0xe1a0a000, 0xe1a00004, 0xe08f1001, 0xebffffd6, 0xe1a04000, 0xe59f010c, 0xe3a01000, 0xe3a09000, 0xe08f0000, 0xe12fff36, 26 | 0xe1a06000, 0xe3700001, 0xca000001, 0xe3a00000, 0xe12fff37, 0xe3a00009, 0xe3a01001, 0xe1cd01bc, 0xe3a00008, 0xe1cd01b4, 0xe3090680, 0xe3400098, 27 | 0xe3a02000, 0xe58d000c, 0xe28d0010, 0xe58d7000, 0xe58d6018, 0xe58d8010, 0xe58d9008, 0xe12fff35, 0xe3500000, 0xca00001d, 0xe28d7018, 0xe28d8010, 28 | 0xe28d9020, 0xe1a00007, 0xe3a01001, 0xe3a02000, 0xe12fff35, 0xe3500000, 0xda00000a, 0xe1a00006, 0xe1a01009, 0xe3a02801, 0xe12fff3a, 0xe3500001, 29 | 0xba00000e, 0xe1a02000, 0xe3a00001, 0xe1a01009, 0xe12fff34, 0xea000003, 0xe59d2004, 0xe28d0008, 0xe3a01000, 0xe12fff32, 0xe1a00008, 0xe3a01001, 30 | 0xe3a02000, 0xe12fff35, 0xe3500001, 0xbaffffe4, 0xe59d1000, 0xe3a00000, 0xe12fff31, 0xe24bd01c, 0xe8bd8ff0, 0x00000198, 0x00000190, 0x00000181, 31 | 0x00000172, 0x00000163, 0x00000159, 0x0000014a, 0x00000138, 0x7ffffe4c, 0x00000001, 0x6362696c, 0x006f732e, 0x6e65706f, 0x69786500, 0x6f700074, 32 | 0x6e006c6c, 0x736f6e61, 0x7065656c, 0x61657200, 0x72770064, 0x00657469, 0x7379732f, 0x72656b2f, 0x2f6c656e, 0x75626564, 0x72742f67, 0x6e696361, 33 | 0x72742f67, 0x5f656361, 0x65706970, 0x00000000, 0x00000003, 0x000014b0, 0x00000002, 0x00000010, 0x00000017, 0x000001b4, 0x00000014, 0x00000011, 34 | 0x00000015, 0x00000000, 0x00000006, 0x00000128, 0x0000000b, 0x00000010, 0x00000005, 0x00000158, 0x0000000a, 0x0000001c, 0x6ffffef5, 0x00000174, 35 | 0x00000001, 0x0000000d, 0x0000001e, 0x00000008, 0x6ffffffb, 0x00000001, 0x6ffffff0, 0x0000018c, 0x6ffffffe, 0x00000194, 0x6fffffff, 0x00000001, 36 | }; 37 | 38 | static const unsigned int tracy_systrace_aarch64_size = 1650; 39 | static const unsigned int tracy_systrace_aarch64_data[1652/4] = 40 | { 41 | 0x464c457f, 0x00010102, 0x00000000, 0x00000000, 0x00b70003, 0x00000001, 0x000002e0, 0x00000000, 0x00000040, 0x00000000, 0x00000000, 0x00000000, 42 | 0x00000000, 0x00380040, 0x00400006, 0x00000000, 0x00000006, 0x00000005, 0x00000040, 0x00000000, 0x00000040, 0x00000000, 0x00000040, 0x00000000, 43 | 0x00000150, 0x00000000, 0x00000150, 0x00000000, 0x00000008, 0x00000000, 0x00000003, 0x00000004, 0x00000190, 0x00000000, 0x00000190, 0x00000000, 44 | 0x00000190, 0x00000000, 0x00000015, 0x00000000, 0x00000015, 0x00000000, 0x00000001, 0x00000000, 0x00000001, 0x00000005, 0x00000000, 0x00000000, 45 | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000004e1, 0x00000000, 0x000004e1, 0x00000000, 0x00001000, 0x00000000, 0x00000001, 0x00000006, 46 | 0x000004e8, 0x00000000, 0x000014e8, 0x00000000, 0x000014e8, 0x00000000, 0x0000018a, 0x00000000, 0x00000190, 0x00000000, 0x00001000, 0x00000000, 47 | 0x00000002, 0x00000006, 0x000004e8, 0x00000000, 0x000014e8, 0x00000000, 0x000014e8, 0x00000000, 0x00000160, 0x00000000, 0x00000160, 0x00000000, 48 | 0x00000008, 0x00000000, 0x6474e551, 0x00000006, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 49 | 0x00000000, 0x00000000, 0x00000008, 0x00000000, 0x7379732f, 0x2f6d6574, 0x2f6e6962, 0x6b6e696c, 0x34367265, 0x00000000, 0x00000001, 0x00000001, 50 | 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 51 | 0x00000000, 0x00090003, 0x000002e0, 0x00000000, 0x00000000, 0x00000000, 0x00000010, 0x00000012, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 52 | 0x0000000a, 0x00000012, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x62696c00, 0x732e6c64, 0x6c64006f, 0x006d7973, 0x706f6c64, 0x4c006e65, 53 | 0x00434249, 0x00000000, 0x00000000, 0x00000000, 0x00010001, 0x00000001, 0x00000010, 0x00000000, 0x00050d63, 0x00020000, 0x00000017, 0x00000000, 54 | 0x00001668, 0x00000000, 0x00000402, 0x00000002, 0x00000000, 0x00000000, 0x00001670, 0x00000000, 0x00000402, 0x00000003, 0x00000000, 0x00000000, 55 | 0xa9bf7bf0, 0xb0000010, 0xf9433211, 0x91198210, 0xd61f0220, 0xd503201f, 0xd503201f, 0xd503201f, 0xb0000010, 0xf9433611, 0x9119a210, 0xd61f0220, 56 | 0xb0000010, 0xf9433a11, 0x9119c210, 0xd61f0220, 0xa9bb67fc, 0xa9015ff8, 0xa90257f6, 0xa9034ff4, 0xa9047bfd, 0x910103fd, 0xd14043ff, 0xd10083ff, 57 | 0x90000000, 0x91124000, 0x52800021, 0x52800039, 0x97ffffec, 0x90000001, 0x91126021, 0xaa0003f7, 0x97ffffec, 0x90000001, 0xaa0003f8, 0x91127421, 58 | 0xaa1703e0, 0x97ffffe7, 0x90000001, 0xaa0003f3, 0x91128821, 0xaa1703e0, 0x97ffffe2, 0x90000001, 0xaa0003f4, 0x91129c21, 0xaa1703e0, 0x97ffffdd, 59 | 0x90000001, 0xaa0003f5, 0x9112c421, 0xaa1703e0, 0x97ffffd8, 0x90000001, 0xaa0003f6, 0x9112d821, 0xaa1703e0, 0x97ffffd3, 0xaa0003f7, 0x90000000, 60 | 0x9112f000, 0x2a1f03e1, 0xd63f0300, 0x2a0003f8, 0x36f80060, 0x2a1f03e0, 0xd63f0260, 0x90000009, 0x3dc12120, 0x52800128, 0x79003be8, 0x52800108, 61 | 0x910043e0, 0x52800021, 0x2a1f03e2, 0xb9001bf8, 0xb90013f9, 0x79002be8, 0x3d8003e0, 0xd63f0280, 0x7100001f, 0x5400036c, 0x910063e0, 0x52800021, 62 | 0x2a1f03e2, 0xd63f0280, 0x7100001f, 0x5400018d, 0x910083e1, 0x52a00022, 0x2a1803e0, 0xd63f02c0, 0xf100041f, 0x540001eb, 0xaa0003e2, 0x910083e1, 63 | 0x52800020, 0xd63f02e0, 0x14000004, 0x910003e0, 0xaa1f03e1, 0xd63f02a0, 0x910043e0, 0x52800021, 0x2a1f03e2, 0xd63f0280, 0x7100041f, 0x54fffceb, 64 | 0x2a1f03e0, 0xd63f0260, 0x914043ff, 0x910083ff, 0xa9447bfd, 0xa9434ff4, 0xa94257f6, 0xa9415ff8, 0xa8c567fc, 0xd65f03c0, 0x00000000, 0x00000000, 65 | 0x00000000, 0x00000000, 0x00989680, 0x00000000, 0x6362696c, 0x006f732e, 0x6e65706f, 0x69786500, 0x6f700074, 0x6e006c6c, 0x736f6e61, 0x7065656c, 66 | 0x61657200, 0x72770064, 0x00657469, 0x7379732f, 0x72656b2f, 0x2f6c656e, 0x75626564, 0x72742f67, 0x6e696361, 0x72742f67, 0x5f656361, 0x65706970, 67 | 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000001, 0x00000000, 0x6ffffef5, 0x00000000, 0x000001a8, 0x00000000, 0x00000005, 0x00000000, 68 | 0x00000228, 0x00000000, 0x00000006, 0x00000000, 0x000001c8, 0x00000000, 0x0000000a, 0x00000000, 0x0000001c, 0x00000000, 0x0000000b, 0x00000000, 69 | 0x00000018, 0x00000000, 0x00000015, 0x00000000, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00001650, 0x00000000, 0x00000002, 0x00000000, 70 | 0x00000030, 0x00000000, 0x00000014, 0x00000000, 0x00000007, 0x00000000, 0x00000017, 0x00000000, 0x00000270, 0x00000000, 0x0000001e, 0x00000000, 71 | 0x00000008, 0x00000000, 0x6ffffffb, 0x00000000, 0x00000001, 0x00000000, 0x6ffffffe, 0x00000000, 0x00000250, 0x00000000, 0x6fffffff, 0x00000000, 72 | 0x00000001, 0x00000000, 0x6ffffff0, 0x00000000, 0x00000244, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 73 | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 74 | 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 75 | 0x00000000, 0x00000000, 0x000002a0, 0x00000000, 0x000002a0, 76 | }; 77 | 78 | } 79 | -------------------------------------------------------------------------------- /tracy-0.7.8/client/TracyThread.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __TRACYTHREAD_HPP__ 2 | #define __TRACYTHREAD_HPP__ 3 | 4 | #if defined _WIN32 || defined __CYGWIN__ 5 | # include 6 | #else 7 | # include 8 | #endif 9 | 10 | #ifdef TRACY_MANUAL_LIFETIME 11 | # include "tracy_rpmalloc.hpp" 12 | #endif 13 | 14 | namespace tracy 15 | { 16 | 17 | class ThreadExitHandler 18 | { 19 | public: 20 | ~ThreadExitHandler() 21 | { 22 | #ifdef TRACY_MANUAL_LIFETIME 23 | rpmalloc_thread_finalize(); 24 | #endif 25 | } 26 | }; 27 | 28 | #if defined _WIN32 || defined __CYGWIN__ 29 | 30 | class Thread 31 | { 32 | public: 33 | Thread( void(*func)( void* ptr ), void* ptr ) 34 | : m_func( func ) 35 | , m_ptr( ptr ) 36 | , m_hnd( CreateThread( nullptr, 0, Launch, this, 0, nullptr ) ) 37 | {} 38 | 39 | ~Thread() 40 | { 41 | WaitForSingleObject( m_hnd, INFINITE ); 42 | CloseHandle( m_hnd ); 43 | } 44 | 45 | HANDLE Handle() const { return m_hnd; } 46 | 47 | private: 48 | static DWORD WINAPI Launch( void* ptr ) { ((Thread*)ptr)->m_func( ((Thread*)ptr)->m_ptr ); return 0; } 49 | 50 | void(*m_func)( void* ptr ); 51 | void* m_ptr; 52 | HANDLE m_hnd; 53 | }; 54 | 55 | #else 56 | 57 | class Thread 58 | { 59 | public: 60 | Thread( void(*func)( void* ptr ), void* ptr ) 61 | : m_func( func ) 62 | , m_ptr( ptr ) 63 | { 64 | pthread_create( &m_thread, nullptr, Launch, this ); 65 | } 66 | 67 | ~Thread() 68 | { 69 | pthread_join( m_thread, nullptr ); 70 | } 71 | 72 | pthread_t Handle() const { return m_thread; } 73 | 74 | private: 75 | static void* Launch( void* ptr ) { ((Thread*)ptr)->m_func( ((Thread*)ptr)->m_ptr ); return nullptr; } 76 | void(*m_func)( void* ptr ); 77 | void* m_ptr; 78 | pthread_t m_thread; 79 | }; 80 | 81 | #endif 82 | 83 | } 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /tracy-0.7.8/client/tracy_rpmalloc.hpp: -------------------------------------------------------------------------------- 1 | /* rpmalloc.h - Memory allocator - Public Domain - 2016 Mattias Jansson 2 | * 3 | * This library provides a cross-platform lock free thread caching malloc implementation in C11. 4 | * The latest source code is always available at 5 | * 6 | * https://github.com/mjansson/rpmalloc 7 | * 8 | * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions. 9 | * 10 | */ 11 | 12 | #pragma once 13 | 14 | #include 15 | #include "../common/TracyApi.h" 16 | 17 | namespace tracy 18 | { 19 | 20 | #if defined(__clang__) || defined(__GNUC__) 21 | # define RPMALLOC_EXPORT __attribute__((visibility("default"))) 22 | # define RPMALLOC_ALLOCATOR 23 | # define RPMALLOC_ATTRIB_MALLOC __attribute__((__malloc__)) 24 | # if defined(__clang_major__) && (__clang_major__ < 4) 25 | # define RPMALLOC_ATTRIB_ALLOC_SIZE(size) 26 | # define RPMALLOC_ATTRIB_ALLOC_SIZE2(count, size) 27 | # else 28 | # define RPMALLOC_ATTRIB_ALLOC_SIZE(size) __attribute__((alloc_size(size))) 29 | # define RPMALLOC_ATTRIB_ALLOC_SIZE2(count, size) __attribute__((alloc_size(count, size))) 30 | # endif 31 | # define RPMALLOC_CDECL 32 | #elif defined(_MSC_VER) 33 | # define RPMALLOC_EXPORT 34 | # define RPMALLOC_ALLOCATOR __declspec(allocator) __declspec(restrict) 35 | # define RPMALLOC_ATTRIB_MALLOC 36 | # define RPMALLOC_ATTRIB_ALLOC_SIZE(size) 37 | # define RPMALLOC_ATTRIB_ALLOC_SIZE2(count,size) 38 | # define RPMALLOC_CDECL __cdecl 39 | #else 40 | # define RPMALLOC_EXPORT 41 | # define RPMALLOC_ALLOCATOR 42 | # define RPMALLOC_ATTRIB_MALLOC 43 | # define RPMALLOC_ATTRIB_ALLOC_SIZE(size) 44 | # define RPMALLOC_ATTRIB_ALLOC_SIZE2(count,size) 45 | # define RPMALLOC_CDECL 46 | #endif 47 | 48 | //! Define RPMALLOC_CONFIGURABLE to enable configuring sizes 49 | #ifndef RPMALLOC_CONFIGURABLE 50 | #define RPMALLOC_CONFIGURABLE 0 51 | #endif 52 | 53 | //! Flag to rpaligned_realloc to not preserve content in reallocation 54 | #define RPMALLOC_NO_PRESERVE 1 55 | 56 | typedef struct rpmalloc_global_statistics_t { 57 | //! Current amount of virtual memory mapped, all of which might not have been committed (only if ENABLE_STATISTICS=1) 58 | size_t mapped; 59 | //! Peak amount of virtual memory mapped, all of which might not have been committed (only if ENABLE_STATISTICS=1) 60 | size_t mapped_peak; 61 | //! Current amount of memory in global caches for small and medium sizes (<32KiB) 62 | size_t cached; 63 | //! Current amount of memory allocated in huge allocations, i.e larger than LARGE_SIZE_LIMIT which is 2MiB by default (only if ENABLE_STATISTICS=1) 64 | size_t huge_alloc; 65 | //! Peak amount of memory allocated in huge allocations, i.e larger than LARGE_SIZE_LIMIT which is 2MiB by default (only if ENABLE_STATISTICS=1) 66 | size_t huge_alloc_peak; 67 | //! Total amount of memory mapped since initialization (only if ENABLE_STATISTICS=1) 68 | size_t mapped_total; 69 | //! Total amount of memory unmapped since initialization (only if ENABLE_STATISTICS=1) 70 | size_t unmapped_total; 71 | } rpmalloc_global_statistics_t; 72 | 73 | typedef struct rpmalloc_thread_statistics_t { 74 | //! Current number of bytes available in thread size class caches for small and medium sizes (<32KiB) 75 | size_t sizecache; 76 | //! Current number of bytes available in thread span caches for small and medium sizes (<32KiB) 77 | size_t spancache; 78 | //! Total number of bytes transitioned from thread cache to global cache (only if ENABLE_STATISTICS=1) 79 | size_t thread_to_global; 80 | //! Total number of bytes transitioned from global cache to thread cache (only if ENABLE_STATISTICS=1) 81 | size_t global_to_thread; 82 | //! Per span count statistics (only if ENABLE_STATISTICS=1) 83 | struct { 84 | //! Currently used number of spans 85 | size_t current; 86 | //! High water mark of spans used 87 | size_t peak; 88 | //! Number of spans transitioned to global cache 89 | size_t to_global; 90 | //! Number of spans transitioned from global cache 91 | size_t from_global; 92 | //! Number of spans transitioned to thread cache 93 | size_t to_cache; 94 | //! Number of spans transitioned from thread cache 95 | size_t from_cache; 96 | //! Number of spans transitioned to reserved state 97 | size_t to_reserved; 98 | //! Number of spans transitioned from reserved state 99 | size_t from_reserved; 100 | //! Number of raw memory map calls (not hitting the reserve spans but resulting in actual OS mmap calls) 101 | size_t map_calls; 102 | } span_use[32]; 103 | //! Per size class statistics (only if ENABLE_STATISTICS=1) 104 | struct { 105 | //! Current number of allocations 106 | size_t alloc_current; 107 | //! Peak number of allocations 108 | size_t alloc_peak; 109 | //! Total number of allocations 110 | size_t alloc_total; 111 | //! Total number of frees 112 | size_t free_total; 113 | //! Number of spans transitioned to cache 114 | size_t spans_to_cache; 115 | //! Number of spans transitioned from cache 116 | size_t spans_from_cache; 117 | //! Number of spans transitioned from reserved state 118 | size_t spans_from_reserved; 119 | //! Number of raw memory map calls (not hitting the reserve spans but resulting in actual OS mmap calls) 120 | size_t map_calls; 121 | } size_use[128]; 122 | } rpmalloc_thread_statistics_t; 123 | 124 | typedef struct rpmalloc_config_t { 125 | //! Map memory pages for the given number of bytes. The returned address MUST be 126 | // aligned to the rpmalloc span size, which will always be a power of two. 127 | // Optionally the function can store an alignment offset in the offset variable 128 | // in case it performs alignment and the returned pointer is offset from the 129 | // actual start of the memory region due to this alignment. The alignment offset 130 | // will be passed to the memory unmap function. The alignment offset MUST NOT be 131 | // larger than 65535 (storable in an uint16_t), if it is you must use natural 132 | // alignment to shift it into 16 bits. If you set a memory_map function, you 133 | // must also set a memory_unmap function or else the default implementation will 134 | // be used for both. 135 | void* (*memory_map)(size_t size, size_t* offset); 136 | //! Unmap the memory pages starting at address and spanning the given number of bytes. 137 | // If release is set to non-zero, the unmap is for an entire span range as returned by 138 | // a previous call to memory_map and that the entire range should be released. The 139 | // release argument holds the size of the entire span range. If release is set to 0, 140 | // the unmap is a partial decommit of a subset of the mapped memory range. 141 | // If you set a memory_unmap function, you must also set a memory_map function or 142 | // else the default implementation will be used for both. 143 | void (*memory_unmap)(void* address, size_t size, size_t offset, size_t release); 144 | //! Size of memory pages. The page size MUST be a power of two. All memory mapping 145 | // requests to memory_map will be made with size set to a multiple of the page size. 146 | // Used if RPMALLOC_CONFIGURABLE is defined to 1, otherwise system page size is used. 147 | size_t page_size; 148 | //! Size of a span of memory blocks. MUST be a power of two, and in [4096,262144] 149 | // range (unless 0 - set to 0 to use the default span size). Used if RPMALLOC_CONFIGURABLE 150 | // is defined to 1. 151 | size_t span_size; 152 | //! Number of spans to map at each request to map new virtual memory blocks. This can 153 | // be used to minimize the system call overhead at the cost of virtual memory address 154 | // space. The extra mapped pages will not be written until actually used, so physical 155 | // committed memory should not be affected in the default implementation. Will be 156 | // aligned to a multiple of spans that match memory page size in case of huge pages. 157 | size_t span_map_count; 158 | //! Enable use of large/huge pages. If this flag is set to non-zero and page size is 159 | // zero, the allocator will try to enable huge pages and auto detect the configuration. 160 | // If this is set to non-zero and page_size is also non-zero, the allocator will 161 | // assume huge pages have been configured and enabled prior to initializing the 162 | // allocator. 163 | // For Windows, see https://docs.microsoft.com/en-us/windows/desktop/memory/large-page-support 164 | // For Linux, see https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt 165 | int enable_huge_pages; 166 | } rpmalloc_config_t; 167 | 168 | //! Initialize allocator with default configuration 169 | TRACY_API int 170 | rpmalloc_initialize(void); 171 | 172 | //! Initialize allocator with given configuration 173 | RPMALLOC_EXPORT int 174 | rpmalloc_initialize_config(const rpmalloc_config_t* config); 175 | 176 | //! Get allocator configuration 177 | RPMALLOC_EXPORT const rpmalloc_config_t* 178 | rpmalloc_config(void); 179 | 180 | //! Finalize allocator 181 | TRACY_API void 182 | rpmalloc_finalize(void); 183 | 184 | //! Initialize allocator for calling thread 185 | TRACY_API void 186 | rpmalloc_thread_initialize(void); 187 | 188 | //! Finalize allocator for calling thread 189 | TRACY_API void 190 | rpmalloc_thread_finalize(void); 191 | 192 | //! Perform deferred deallocations pending for the calling thread heap 193 | RPMALLOC_EXPORT void 194 | rpmalloc_thread_collect(void); 195 | 196 | //! Query if allocator is initialized for calling thread 197 | RPMALLOC_EXPORT int 198 | rpmalloc_is_thread_initialized(void); 199 | 200 | //! Get per-thread statistics 201 | RPMALLOC_EXPORT void 202 | rpmalloc_thread_statistics(rpmalloc_thread_statistics_t* stats); 203 | 204 | //! Get global statistics 205 | RPMALLOC_EXPORT void 206 | rpmalloc_global_statistics(rpmalloc_global_statistics_t* stats); 207 | 208 | //! Dump all statistics in human readable format to file (should be a FILE*) 209 | RPMALLOC_EXPORT void 210 | rpmalloc_dump_statistics(void* file); 211 | 212 | //! Allocate a memory block of at least the given size 213 | TRACY_API RPMALLOC_ALLOCATOR void* 214 | rpmalloc(size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(1); 215 | 216 | //! Free the given memory block 217 | TRACY_API void 218 | rpfree(void* ptr); 219 | 220 | //! Allocate a memory block of at least the given size and zero initialize it 221 | RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void* 222 | rpcalloc(size_t num, size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE2(1, 2); 223 | 224 | //! Reallocate the given block to at least the given size 225 | TRACY_API RPMALLOC_ALLOCATOR void* 226 | rprealloc(void* ptr, size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(2); 227 | 228 | //! Reallocate the given block to at least the given size and alignment, 229 | // with optional control flags (see RPMALLOC_NO_PRESERVE). 230 | // Alignment must be a power of two and a multiple of sizeof(void*), 231 | // and should ideally be less than memory page size. A caveat of rpmalloc 232 | // internals is that this must also be strictly less than the span size (default 64KiB) 233 | RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void* 234 | rpaligned_realloc(void* ptr, size_t alignment, size_t size, size_t oldsize, unsigned int flags) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(3); 235 | 236 | //! Allocate a memory block of at least the given size and alignment. 237 | // Alignment must be a power of two and a multiple of sizeof(void*), 238 | // and should ideally be less than memory page size. A caveat of rpmalloc 239 | // internals is that this must also be strictly less than the span size (default 64KiB) 240 | RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void* 241 | rpaligned_alloc(size_t alignment, size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(2); 242 | 243 | //! Allocate a memory block of at least the given size and alignment. 244 | // Alignment must be a power of two and a multiple of sizeof(void*), 245 | // and should ideally be less than memory page size. A caveat of rpmalloc 246 | // internals is that this must also be strictly less than the span size (default 64KiB) 247 | RPMALLOC_EXPORT RPMALLOC_ALLOCATOR void* 248 | rpmemalign(size_t alignment, size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(2); 249 | 250 | //! Allocate a memory block of at least the given size and alignment. 251 | // Alignment must be a power of two and a multiple of sizeof(void*), 252 | // and should ideally be less than memory page size. A caveat of rpmalloc 253 | // internals is that this must also be strictly less than the span size (default 64KiB) 254 | RPMALLOC_EXPORT int 255 | rpposix_memalign(void **memptr, size_t alignment, size_t size); 256 | 257 | //! Query the usable size of the given memory block (from given pointer to the end of block) 258 | RPMALLOC_EXPORT size_t 259 | rpmalloc_usable_size(void* ptr); 260 | 261 | } 262 | -------------------------------------------------------------------------------- /tracy-0.7.8/common/TracyAlign.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __TRACYALIGN_HPP__ 2 | #define __TRACYALIGN_HPP__ 3 | 4 | #include 5 | 6 | #include "TracyForceInline.hpp" 7 | 8 | namespace tracy 9 | { 10 | 11 | template 12 | tracy_force_inline T MemRead( const void* ptr ) 13 | { 14 | T val; 15 | memcpy( &val, ptr, sizeof( T ) ); 16 | return val; 17 | } 18 | 19 | template 20 | tracy_force_inline void MemWrite( void* ptr, T val ) 21 | { 22 | memcpy( ptr, &val, sizeof( T ) ); 23 | } 24 | 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /tracy-0.7.8/common/TracyAlloc.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __TRACYALLOC_HPP__ 2 | #define __TRACYALLOC_HPP__ 3 | 4 | #include 5 | 6 | #ifdef TRACY_ENABLE 7 | # include "../client/tracy_rpmalloc.hpp" 8 | #endif 9 | 10 | namespace tracy 11 | { 12 | 13 | static inline void* tracy_malloc( size_t size ) 14 | { 15 | #ifdef TRACY_ENABLE 16 | return rpmalloc( size ); 17 | #else 18 | return malloc( size ); 19 | #endif 20 | } 21 | 22 | static inline void tracy_free( void* ptr ) 23 | { 24 | #ifdef TRACY_ENABLE 25 | rpfree( ptr ); 26 | #else 27 | free( ptr ); 28 | #endif 29 | } 30 | 31 | static inline void* tracy_realloc( void* ptr, size_t size ) 32 | { 33 | #ifdef TRACY_ENABLE 34 | return rprealloc( ptr, size ); 35 | #else 36 | return realloc( ptr, size ); 37 | #endif 38 | } 39 | 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /tracy-0.7.8/common/TracyApi.h: -------------------------------------------------------------------------------- 1 | #ifndef __TRACYAPI_H__ 2 | #define __TRACYAPI_H__ 3 | 4 | #if defined _WIN32 || defined __CYGWIN__ 5 | # if defined TRACY_EXPORTS 6 | # define TRACY_API __declspec(dllexport) 7 | # elif defined TRACY_IMPORTS 8 | # define TRACY_API __declspec(dllimport) 9 | # else 10 | # define TRACY_API 11 | # endif 12 | #else 13 | # define TRACY_API __attribute__((visibility("default"))) 14 | #endif 15 | 16 | #endif // __TRACYAPI_H__ 17 | -------------------------------------------------------------------------------- /tracy-0.7.8/common/TracyForceInline.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __TRACYFORCEINLINE_HPP__ 2 | #define __TRACYFORCEINLINE_HPP__ 3 | 4 | #if defined(__GNUC__) 5 | # define tracy_force_inline __attribute__((always_inline)) inline 6 | #elif defined(_MSC_VER) 7 | # define tracy_force_inline __forceinline 8 | #else 9 | # define tracy_force_inline inline 10 | #endif 11 | 12 | #if defined(__GNUC__) 13 | # define tracy_no_inline __attribute__((noinline)) 14 | #elif defined(_MSC_VER) 15 | # define tracy_no_inline __declspec(noinline) 16 | #else 17 | # define tracy_no_inline 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /tracy-0.7.8/common/TracyMutex.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __TRACYMUTEX_HPP__ 2 | #define __TRACYMUTEX_HPP__ 3 | 4 | #if defined _MSC_VER 5 | 6 | # include 7 | 8 | namespace tracy 9 | { 10 | using TracyMutex = std::shared_mutex; 11 | } 12 | 13 | #else 14 | 15 | #include 16 | 17 | namespace tracy 18 | { 19 | using TracyMutex = std::mutex; 20 | } 21 | 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /tracy-0.7.8/common/TracyProtocol.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __TRACYPROTOCOL_HPP__ 2 | #define __TRACYPROTOCOL_HPP__ 3 | 4 | #include 5 | #include 6 | 7 | namespace tracy 8 | { 9 | 10 | constexpr unsigned Lz4CompressBound( unsigned isize ) { return isize + ( isize / 255 ) + 16; } 11 | 12 | enum : uint32_t { ProtocolVersion = 46 }; 13 | enum : uint16_t { BroadcastVersion = 2 }; 14 | 15 | using lz4sz_t = uint32_t; 16 | 17 | enum { TargetFrameSize = 256 * 1024 }; 18 | enum { LZ4Size = Lz4CompressBound( TargetFrameSize ) }; 19 | static_assert( LZ4Size <= std::numeric_limits::max(), "LZ4Size greater than lz4sz_t" ); 20 | static_assert( TargetFrameSize * 2 >= 64 * 1024, "Not enough space for LZ4 stream buffer" ); 21 | 22 | enum { HandshakeShibbolethSize = 8 }; 23 | static const char HandshakeShibboleth[HandshakeShibbolethSize] = { 'T', 'r', 'a', 'c', 'y', 'P', 'r', 'f' }; 24 | 25 | enum HandshakeStatus : uint8_t 26 | { 27 | HandshakePending, 28 | HandshakeWelcome, 29 | HandshakeProtocolMismatch, 30 | HandshakeNotAvailable, 31 | HandshakeDropped 32 | }; 33 | 34 | enum { WelcomeMessageProgramNameSize = 64 }; 35 | enum { WelcomeMessageHostInfoSize = 1024 }; 36 | 37 | #pragma pack( 1 ) 38 | 39 | // Must increase left query space after handling! 40 | enum ServerQuery : uint8_t 41 | { 42 | ServerQueryTerminate, 43 | ServerQueryString, 44 | ServerQueryThreadString, 45 | ServerQuerySourceLocation, 46 | ServerQueryPlotName, 47 | ServerQueryCallstackFrame, 48 | ServerQueryFrameName, 49 | ServerQueryDisconnect, 50 | ServerQueryExternalName, 51 | ServerQueryParameter, 52 | ServerQuerySymbol, 53 | ServerQuerySymbolCode, 54 | ServerQueryCodeLocation, 55 | ServerQuerySourceCode, 56 | ServerQueryDataTransfer, 57 | ServerQueryDataTransferPart 58 | }; 59 | 60 | struct ServerQueryPacket 61 | { 62 | ServerQuery type; 63 | uint64_t ptr; 64 | uint32_t extra; 65 | }; 66 | 67 | enum { ServerQueryPacketSize = sizeof( ServerQueryPacket ) }; 68 | 69 | 70 | enum CpuArchitecture : uint8_t 71 | { 72 | CpuArchUnknown, 73 | CpuArchX86, 74 | CpuArchX64, 75 | CpuArchArm32, 76 | CpuArchArm64 77 | }; 78 | 79 | 80 | struct WelcomeMessage 81 | { 82 | double timerMul; 83 | int64_t initBegin; 84 | int64_t initEnd; 85 | uint64_t delay; 86 | uint64_t resolution; 87 | uint64_t epoch; 88 | uint64_t exectime; 89 | uint64_t pid; 90 | int64_t samplingPeriod; 91 | uint8_t onDemand; 92 | uint8_t isApple; 93 | uint8_t cpuArch; 94 | uint8_t codeTransfer; 95 | char cpuManufacturer[12]; 96 | uint32_t cpuId; 97 | char programName[WelcomeMessageProgramNameSize]; 98 | char hostInfo[WelcomeMessageHostInfoSize]; 99 | }; 100 | 101 | enum { WelcomeMessageSize = sizeof( WelcomeMessage ) }; 102 | 103 | 104 | struct OnDemandPayloadMessage 105 | { 106 | uint64_t frames; 107 | uint64_t currentTime; 108 | }; 109 | 110 | enum { OnDemandPayloadMessageSize = sizeof( OnDemandPayloadMessage ) }; 111 | 112 | 113 | struct BroadcastMessage 114 | { 115 | uint16_t broadcastVersion; 116 | uint16_t listenPort; 117 | uint32_t protocolVersion; 118 | int32_t activeTime; // in seconds 119 | char programName[WelcomeMessageProgramNameSize]; 120 | }; 121 | 122 | enum { BroadcastMessageSize = sizeof( BroadcastMessage ) }; 123 | 124 | #pragma pack() 125 | 126 | } 127 | 128 | #endif 129 | -------------------------------------------------------------------------------- /tracy-0.7.8/common/TracySocket.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __TRACYSOCKET_HPP__ 2 | #define __TRACYSOCKET_HPP__ 3 | 4 | #include 5 | #include 6 | 7 | #include "TracyForceInline.hpp" 8 | 9 | struct addrinfo; 10 | struct sockaddr; 11 | 12 | namespace tracy 13 | { 14 | 15 | #ifdef _WIN32 16 | void InitWinSock(); 17 | #endif 18 | 19 | class Socket 20 | { 21 | public: 22 | Socket(); 23 | Socket( int sock ); 24 | ~Socket(); 25 | 26 | bool Connect( const char* addr, uint16_t port ); 27 | bool ConnectBlocking( const char* addr, uint16_t port ); 28 | void Close(); 29 | 30 | int Send( const void* buf, int len ); 31 | int GetSendBufSize(); 32 | 33 | int ReadUpTo( void* buf, int len, int timeout ); 34 | bool Read( void* buf, int len, int timeout ); 35 | 36 | template 37 | bool Read( void* buf, int len, int timeout, ShouldExit exitCb ) 38 | { 39 | auto cbuf = (char*)buf; 40 | while( len > 0 ) 41 | { 42 | if( exitCb() ) return false; 43 | if( !ReadImpl( cbuf, len, timeout ) ) return false; 44 | } 45 | return true; 46 | } 47 | 48 | bool ReadRaw( void* buf, int len, int timeout ); 49 | bool HasData(); 50 | bool IsValid() const; 51 | 52 | Socket( const Socket& ) = delete; 53 | Socket( Socket&& ) = delete; 54 | Socket& operator=( const Socket& ) = delete; 55 | Socket& operator=( Socket&& ) = delete; 56 | 57 | private: 58 | int RecvBuffered( void* buf, int len, int timeout ); 59 | int Recv( void* buf, int len, int timeout ); 60 | 61 | bool ReadImpl( char*& buf, int& len, int timeout ); 62 | 63 | char* m_buf; 64 | char* m_bufPtr; 65 | std::atomic m_sock; 66 | int m_bufLeft; 67 | 68 | struct addrinfo *m_res; 69 | struct addrinfo *m_ptr; 70 | int m_connSock; 71 | }; 72 | 73 | class ListenSocket 74 | { 75 | public: 76 | ListenSocket(); 77 | ~ListenSocket(); 78 | 79 | bool Listen( uint16_t port, int backlog ); 80 | Socket* Accept(); 81 | void Close(); 82 | 83 | ListenSocket( const ListenSocket& ) = delete; 84 | ListenSocket( ListenSocket&& ) = delete; 85 | ListenSocket& operator=( const ListenSocket& ) = delete; 86 | ListenSocket& operator=( ListenSocket&& ) = delete; 87 | 88 | private: 89 | int m_sock; 90 | }; 91 | 92 | class UdpBroadcast 93 | { 94 | public: 95 | UdpBroadcast(); 96 | ~UdpBroadcast(); 97 | 98 | bool Open( const char* addr, uint16_t port ); 99 | void Close(); 100 | 101 | int Send( uint16_t port, const void* data, int len ); 102 | 103 | UdpBroadcast( const UdpBroadcast& ) = delete; 104 | UdpBroadcast( UdpBroadcast&& ) = delete; 105 | UdpBroadcast& operator=( const UdpBroadcast& ) = delete; 106 | UdpBroadcast& operator=( UdpBroadcast&& ) = delete; 107 | 108 | private: 109 | int m_sock; 110 | uint32_t m_addr; 111 | }; 112 | 113 | class IpAddress 114 | { 115 | public: 116 | IpAddress(); 117 | ~IpAddress(); 118 | 119 | void Set( const struct sockaddr& addr ); 120 | 121 | uint32_t GetNumber() const { return m_number; } 122 | const char* GetText() const { return m_text; } 123 | 124 | IpAddress( const IpAddress& ) = delete; 125 | IpAddress( IpAddress&& ) = delete; 126 | IpAddress& operator=( const IpAddress& ) = delete; 127 | IpAddress& operator=( IpAddress&& ) = delete; 128 | 129 | private: 130 | uint32_t m_number; 131 | char m_text[17]; 132 | }; 133 | 134 | class UdpListen 135 | { 136 | public: 137 | UdpListen(); 138 | ~UdpListen(); 139 | 140 | bool Listen( uint16_t port ); 141 | void Close(); 142 | 143 | const char* Read( size_t& len, IpAddress& addr, int timeout ); 144 | 145 | UdpListen( const UdpListen& ) = delete; 146 | UdpListen( UdpListen&& ) = delete; 147 | UdpListen& operator=( const UdpListen& ) = delete; 148 | UdpListen& operator=( UdpListen&& ) = delete; 149 | 150 | private: 151 | int m_sock; 152 | }; 153 | 154 | } 155 | 156 | #endif 157 | -------------------------------------------------------------------------------- /tracy-0.7.8/common/TracySystem.cpp: -------------------------------------------------------------------------------- 1 | #if defined _MSC_VER || defined __CYGWIN__ || defined _WIN32 2 | # ifndef WIN32_LEAN_AND_MEAN 3 | # define WIN32_LEAN_AND_MEAN 4 | # endif 5 | # ifndef NOMINMAX 6 | # define NOMINMAX 7 | # endif 8 | #endif 9 | #ifdef _MSC_VER 10 | # pragma warning(disable:4996) 11 | #endif 12 | #if defined _WIN32 || defined __CYGWIN__ 13 | # include 14 | # include 15 | #else 16 | # include 17 | # include 18 | # include 19 | #endif 20 | 21 | #ifdef __linux__ 22 | # ifdef __ANDROID__ 23 | # include 24 | # else 25 | # include 26 | # endif 27 | # include 28 | #elif defined __FreeBSD__ 29 | # include 30 | #elif defined __NetBSD__ || defined __DragonFly__ 31 | # include 32 | #endif 33 | 34 | #ifdef __MINGW32__ 35 | # define __STDC_FORMAT_MACROS 36 | #endif 37 | #include 38 | #include 39 | #include 40 | 41 | #include "TracySystem.hpp" 42 | 43 | #if defined _WIN32 || defined __CYGWIN__ 44 | extern "C" typedef HRESULT (WINAPI *t_SetThreadDescription)( HANDLE, PCWSTR ); 45 | extern "C" typedef HRESULT (WINAPI *t_GetThreadDescription)( HANDLE, PWSTR* ); 46 | #endif 47 | 48 | #ifdef TRACY_ENABLE 49 | # include 50 | # include "TracyAlloc.hpp" 51 | #endif 52 | 53 | namespace tracy 54 | { 55 | 56 | namespace detail 57 | { 58 | 59 | TRACY_API uint64_t GetThreadHandleImpl() 60 | { 61 | #if defined _WIN32 || defined __CYGWIN__ 62 | static_assert( sizeof( decltype( GetCurrentThreadId() ) ) <= sizeof( uint64_t ), "Thread handle too big to fit in protocol" ); 63 | return uint64_t( GetCurrentThreadId() ); 64 | #elif defined __APPLE__ 65 | uint64_t id; 66 | pthread_threadid_np( pthread_self(), &id ); 67 | return id; 68 | #elif defined __ANDROID__ 69 | return (uint64_t)gettid(); 70 | #elif defined __linux__ 71 | return (uint64_t)syscall( SYS_gettid ); 72 | #elif defined __FreeBSD__ 73 | long id; 74 | thr_self( &id ); 75 | return id; 76 | #elif defined __NetBSD__ 77 | return _lwp_self(); 78 | #elif defined __DragonFly__ 79 | return lwp_gettid(); 80 | #elif defined __OpenBSD__ 81 | return getthrid(); 82 | #else 83 | static_assert( sizeof( decltype( pthread_self() ) ) <= sizeof( uint64_t ), "Thread handle too big to fit in protocol" ); 84 | return uint64_t( pthread_self() ); 85 | #endif 86 | 87 | } 88 | 89 | } 90 | 91 | #ifdef TRACY_ENABLE 92 | struct ThreadNameData 93 | { 94 | uint64_t id; 95 | const char* name; 96 | ThreadNameData* next; 97 | }; 98 | std::atomic& GetThreadNameData(); 99 | TRACY_API void InitRPMallocThread(); 100 | #endif 101 | 102 | #ifdef _MSC_VER 103 | # pragma pack( push, 8 ) 104 | struct THREADNAME_INFO 105 | { 106 | DWORD dwType; 107 | LPCSTR szName; 108 | DWORD dwThreadID; 109 | DWORD dwFlags; 110 | }; 111 | # pragma pack(pop) 112 | 113 | void ThreadNameMsvcMagic( const THREADNAME_INFO& info ) 114 | { 115 | __try 116 | { 117 | RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info ); 118 | } 119 | __except(EXCEPTION_EXECUTE_HANDLER) 120 | { 121 | } 122 | } 123 | #endif 124 | 125 | TRACY_API void SetThreadName( const char* name ) 126 | { 127 | #if defined _WIN32 || defined __CYGWIN__ 128 | static auto _SetThreadDescription = (t_SetThreadDescription)GetProcAddress( GetModuleHandleA( "kernel32.dll" ), "SetThreadDescription" ); 129 | if( _SetThreadDescription ) 130 | { 131 | wchar_t buf[256]; 132 | mbstowcs( buf, name, 256 ); 133 | _SetThreadDescription( GetCurrentThread(), buf ); 134 | } 135 | else 136 | { 137 | # if defined _MSC_VER 138 | THREADNAME_INFO info; 139 | info.dwType = 0x1000; 140 | info.szName = name; 141 | info.dwThreadID = GetCurrentThreadId(); 142 | info.dwFlags = 0; 143 | ThreadNameMsvcMagic( info ); 144 | # endif 145 | } 146 | #elif defined _GNU_SOURCE && !defined __EMSCRIPTEN__ && !defined __CYGWIN__ 147 | { 148 | const auto sz = strlen( name ); 149 | if( sz <= 15 ) 150 | { 151 | pthread_setname_np( pthread_self(), name ); 152 | } 153 | else 154 | { 155 | char buf[16]; 156 | memcpy( buf, name, 15 ); 157 | buf[15] = '\0'; 158 | pthread_setname_np( pthread_self(), buf ); 159 | } 160 | } 161 | #endif 162 | #ifdef TRACY_ENABLE 163 | { 164 | InitRPMallocThread(); 165 | const auto sz = strlen( name ); 166 | char* buf = (char*)tracy_malloc( sz+1 ); 167 | memcpy( buf, name, sz ); 168 | buf[sz] = '\0'; 169 | auto data = (ThreadNameData*)tracy_malloc( sizeof( ThreadNameData ) ); 170 | data->id = detail::GetThreadHandleImpl(); 171 | data->name = buf; 172 | data->next = GetThreadNameData().load( std::memory_order_relaxed ); 173 | while( !GetThreadNameData().compare_exchange_weak( data->next, data, std::memory_order_release, std::memory_order_relaxed ) ) {} 174 | } 175 | #endif 176 | } 177 | 178 | TRACY_API const char* GetThreadName( uint64_t id ) 179 | { 180 | static char buf[256]; 181 | #ifdef TRACY_ENABLE 182 | auto ptr = GetThreadNameData().load( std::memory_order_relaxed ); 183 | while( ptr ) 184 | { 185 | if( ptr->id == id ) 186 | { 187 | return ptr->name; 188 | } 189 | ptr = ptr->next; 190 | } 191 | #else 192 | # if defined _WIN32 || defined __CYGWIN__ 193 | static auto _GetThreadDescription = (t_GetThreadDescription)GetProcAddress( GetModuleHandleA( "kernel32.dll" ), "GetThreadDescription" ); 194 | if( _GetThreadDescription ) 195 | { 196 | auto hnd = OpenThread( THREAD_QUERY_LIMITED_INFORMATION, FALSE, (DWORD)id ); 197 | if( hnd != 0 ) 198 | { 199 | PWSTR tmp; 200 | _GetThreadDescription( hnd, &tmp ); 201 | auto ret = wcstombs( buf, tmp, 256 ); 202 | CloseHandle( hnd ); 203 | if( ret != 0 ) 204 | { 205 | return buf; 206 | } 207 | } 208 | } 209 | # elif defined __linux__ 210 | int cs, fd; 211 | char path[32]; 212 | # ifdef __ANDROID__ 213 | int tid = gettid(); 214 | # else 215 | int tid = (int) syscall( SYS_gettid ); 216 | # endif 217 | snprintf( path, sizeof( path ), "/proc/self/task/%d/comm", tid ); 218 | sprintf( buf, "%" PRIu64, id ); 219 | # ifndef __ANDROID__ 220 | pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, &cs ); 221 | # endif 222 | if ( ( fd = open( path, O_RDONLY ) ) > 0) { 223 | int len = read( fd, buf, 255 ); 224 | if( len > 0 ) 225 | { 226 | buf[len] = 0; 227 | if( len > 1 && buf[len-1] == '\n' ) 228 | { 229 | buf[len-1] = 0; 230 | } 231 | } 232 | close( fd ); 233 | } 234 | # ifndef __ANDROID__ 235 | pthread_setcancelstate( cs, 0 ); 236 | # endif 237 | return buf; 238 | # endif 239 | #endif 240 | sprintf( buf, "%" PRIu64, id ); 241 | return buf; 242 | } 243 | 244 | TRACY_API const char* GetEnvVar( const char* name ) 245 | { 246 | #if defined _WIN32 || defined __CYGWIN__ 247 | // unfortunately getenv() on Windows is just fundamentally broken. It caches the entire 248 | // environment block once on startup, then never refreshes it again. If any environment 249 | // strings are added or modified after startup of the CRT, those changes will not be 250 | // seen by getenv(). This removes the possibility of an app using this SDK from 251 | // programmatically setting any of the behaviour controlling envvars here. 252 | // 253 | // To work around this, we'll instead go directly to the Win32 environment strings APIs 254 | // to get the current value. 255 | static char buffer[1024]; 256 | DWORD const kBufferSize = DWORD(sizeof(buffer) / sizeof(buffer[0])); 257 | DWORD count = GetEnvironmentVariableA(name, buffer, kBufferSize); 258 | 259 | if( count == 0 ) 260 | return nullptr; 261 | 262 | if( count >= kBufferSize ) 263 | { 264 | char* buf = reinterpret_cast(_alloca(count + 1)); 265 | count = GetEnvironmentVariableA(name, buf, count + 1); 266 | memcpy(buffer, buf, kBufferSize); 267 | buffer[kBufferSize - 1] = 0; 268 | } 269 | 270 | return buffer; 271 | #else 272 | return getenv(name); 273 | #endif 274 | } 275 | 276 | } 277 | 278 | #ifdef __cplusplus 279 | extern "C" { 280 | #endif 281 | 282 | TRACY_API void ___tracy_set_thread_name( const char* name ) { tracy::SetThreadName( name ); } 283 | 284 | #ifdef __cplusplus 285 | } 286 | #endif 287 | -------------------------------------------------------------------------------- /tracy-0.7.8/common/TracySystem.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __TRACYSYSTEM_HPP__ 2 | #define __TRACYSYSTEM_HPP__ 3 | 4 | #include 5 | 6 | #include "TracyApi.h" 7 | 8 | namespace tracy 9 | { 10 | 11 | namespace detail 12 | { 13 | TRACY_API uint64_t GetThreadHandleImpl(); 14 | } 15 | 16 | #ifdef TRACY_ENABLE 17 | TRACY_API uint64_t GetThreadHandle(); 18 | #else 19 | static inline uint64_t GetThreadHandle() 20 | { 21 | return detail::GetThreadHandleImpl(); 22 | } 23 | #endif 24 | 25 | TRACY_API void SetThreadName( const char* name ); 26 | TRACY_API const char* GetThreadName( uint64_t id ); 27 | 28 | TRACY_API const char* GetEnvVar(const char* name); 29 | 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /tracy-0.7.8/common/src-from-vcxproj.mk: -------------------------------------------------------------------------------- 1 | # Extract the actual list of source files from a sibling Visual Studio project. 2 | 3 | # Ensure these are simply-substituted variables, without changing their values. 4 | SRC := $(SRC) 5 | SRC2 := $(SRC2) 6 | SRC3 := $(SRC3) 7 | 8 | # Paths here are relative to the directory in which make was invoked, not to 9 | # this file, so ../win32/$(PROJECT).vcxproj refers to the Visual Studio project 10 | # of whichever tool is including this makefile fragment. 11 | 12 | BASE := $(shell egrep 'ClCompile.*cpp"' ../win32/$(PROJECT).vcxproj | sed -e 's/.*\"\(.*\)\".*/\1/' | sed -e 's@\\@/@g') 13 | BASE2 := $(shell egrep 'ClCompile.*c"' ../win32/$(PROJECT).vcxproj | sed -e 's/.*\"\(.*\)\".*/\1/' | sed -e 's@\\@/@g') 14 | 15 | # The tool-specific makefile may request that certain files be omitted. 16 | SRC += $(filter-out $(FILTER),$(BASE)) 17 | SRC2 += $(filter-out $(FILTER),$(BASE2)) 18 | SRC3 += $(filter-out $(FILTER),$(BASE3)) 19 | -------------------------------------------------------------------------------- /tracy-0.7.8/common/unix-release.mk: -------------------------------------------------------------------------------- 1 | ARCH := $(shell uname -m) 2 | 3 | ifeq (0,$(shell $(CC) --version | grep clang && echo 1 || echo 0)) 4 | CFLAGS += -s 5 | else 6 | LDFLAGS := -s 7 | endif 8 | 9 | ifneq (,$(filter $(ARCH),aarch64 arm64)) 10 | CFLAGS += -mcpu=native 11 | else 12 | CFLAGS += -march=native 13 | endif 14 | -------------------------------------------------------------------------------- /tracy-0.7.8/common/unix.mk: -------------------------------------------------------------------------------- 1 | # Common code needed by most Tracy Unix Makefiles. 2 | 3 | # Ensure these are simply-substituted variables, without changing their values. 4 | LIBS := $(LIBS) 5 | 6 | # Tracy does not use TBB directly, but the implementation of parallel algorithms 7 | # in some versions of libstdc++ depends on TBB. When it does, you must 8 | # explicitly link against -ltbb. 9 | # 10 | # Some distributions have pgk-config files for TBB, others don't. 11 | ifeq (0,$(shell pkg-config --libs tbb >/dev/null 2>&1; echo $$?)) 12 | LIBS += $(shell pkg-config --libs tbb) 13 | else ifeq (0,$(shell ld -ltbb -o /dev/null 2>/dev/null; echo $$?)) 14 | LIBS += -ltbb 15 | endif 16 | 17 | OBJDIRBASE := obj/$(BUILD) 18 | OBJDIR := $(OBJDIRBASE)/o/o/o 19 | 20 | OBJ := $(addprefix $(OBJDIR)/,$(SRC:%.cpp=%.o)) 21 | OBJ2 := $(addprefix $(OBJDIR)/,$(SRC2:%.c=%.o)) 22 | OBJ3 := $(addprefix $(OBJDIR)/,$(SRC3:%.m=%.o)) 23 | 24 | all: $(IMAGE) 25 | 26 | $(OBJDIR)/%.o: %.cpp 27 | $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DEFINES) $< -o $@ 28 | 29 | $(OBJDIR)/%.d : %.cpp 30 | @echo Resolving dependencies of $< 31 | @mkdir -p $(@D) 32 | @$(CXX) -MM $(INCLUDES) $(CXXFLAGS) $(DEFINES) $< > $@.$$$$; \ 33 | sed 's,.*\.o[ :]*,$(OBJDIR)/$(<:.cpp=.o) $@ : ,g' < $@.$$$$ > $@; \ 34 | rm -f $@.$$$$ 35 | 36 | $(OBJDIR)/%.o: %.c 37 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@ 38 | 39 | $(OBJDIR)/%.d : %.c 40 | @echo Resolving dependencies of $< 41 | @mkdir -p $(@D) 42 | @$(CC) -MM $(INCLUDES) $(CFLAGS) $(DEFINES) $< > $@.$$$$; \ 43 | sed 's,.*\.o[ :]*,$(OBJDIR)/$(<:.c=.o) $@ : ,g' < $@.$$$$ > $@; \ 44 | rm -f $@.$$$$ 45 | 46 | $(OBJDIR)/%.o: %.m 47 | $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@ 48 | 49 | $(OBJDIR)/%.d : %.m 50 | @echo Resolving dependencies of $< 51 | @mkdir -p $(@D) 52 | @$(CC) -MM $(INCLUDES) $(CFLAGS) $(DEFINES) $< > $@.$$$$; \ 53 | sed 's,.*\.o[ :]*,$(OBJDIR)/$(<:.m=.o) $@ : ,g' < $@.$$$$ > $@; \ 54 | rm -f $@.$$$$ 55 | 56 | ifeq (yes,$(SHARED_LIBRARY)) 57 | $(IMAGE): $(OBJ) $(OBJ2) 58 | $(CXX) $(CXXFLAGS) $(LDFLAGS) $(DEFINES) $(OBJ) $(OBJ2) $(LIBS) -shared -o $@ 59 | else 60 | $(IMAGE): $(OBJ) $(OBJ2) $(OBJ3) 61 | $(CXX) $(CXXFLAGS) $(LDFLAGS) $(DEFINES) $(OBJ) $(OBJ2) $(OBJ3) $(LIBS) -o $@ 62 | endif 63 | 64 | ifneq "$(MAKECMDGOALS)" "clean" 65 | -include $(addprefix $(OBJDIR)/,$(SRC:.cpp=.d)) $(addprefix $(OBJDIR)/,$(SRC2:.c=.d)) $(addprefix $(OBJDIR)/,$(SRC3:.m=.d)) 66 | endif 67 | 68 | clean: 69 | rm -rf $(OBJDIRBASE) $(IMAGE)* 70 | 71 | .PHONY: clean all 72 | -------------------------------------------------------------------------------- /tracy-0.7.8/libbacktrace/LICENSE: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2012-2016 Free Software Foundation, Inc. 2 | 3 | # Redistribution and use in source and binary forms, with or without 4 | # modification, are permitted provided that the following conditions are 5 | # met: 6 | 7 | # (1) Redistributions of source code must retain the above copyright 8 | # notice, this list of conditions and the following disclaimer. 9 | 10 | # (2) Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in 12 | # the documentation and/or other materials provided with the 13 | # distribution. 14 | 15 | # (3) The name of the author may not be used to 16 | # endorse or promote products derived from this software without 17 | # specific prior written permission. 18 | 19 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 23 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 27 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 28 | # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | # POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /tracy-0.7.8/libbacktrace/alloc.cpp: -------------------------------------------------------------------------------- 1 | /* alloc.c -- Memory allocation without mmap. 2 | Copyright (C) 2012-2021 Free Software Foundation, Inc. 3 | Written by Ian Lance Taylor, Google. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | (1) Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | (2) Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | (3) The name of the author may not be used to 18 | endorse or promote products derived from this software without 19 | specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. */ 32 | 33 | #include "config.h" 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include "backtrace.hpp" 40 | #include "internal.hpp" 41 | 42 | #include "../common/TracyAlloc.hpp" 43 | 44 | namespace tracy 45 | { 46 | 47 | /* Allocation routines to use on systems that do not support anonymous 48 | mmap. This implementation just uses malloc, which means that the 49 | backtrace functions may not be safely invoked from a signal 50 | handler. */ 51 | 52 | /* Allocate memory like malloc. If ERROR_CALLBACK is NULL, don't 53 | report an error. */ 54 | 55 | void * 56 | backtrace_alloc (struct backtrace_state *state ATTRIBUTE_UNUSED, 57 | size_t size, backtrace_error_callback error_callback, 58 | void *data) 59 | { 60 | void *ret; 61 | 62 | ret = tracy_malloc (size); 63 | if (ret == NULL) 64 | { 65 | if (error_callback) 66 | error_callback (data, "malloc", errno); 67 | } 68 | return ret; 69 | } 70 | 71 | /* Free memory. */ 72 | 73 | void 74 | backtrace_free (struct backtrace_state *state ATTRIBUTE_UNUSED, 75 | void *p, size_t size ATTRIBUTE_UNUSED, 76 | backtrace_error_callback error_callback ATTRIBUTE_UNUSED, 77 | void *data ATTRIBUTE_UNUSED) 78 | { 79 | tracy_free (p); 80 | } 81 | 82 | /* Grow VEC by SIZE bytes. */ 83 | 84 | void * 85 | backtrace_vector_grow (struct backtrace_state *state ATTRIBUTE_UNUSED, 86 | size_t size, backtrace_error_callback error_callback, 87 | void *data, struct backtrace_vector *vec) 88 | { 89 | void *ret; 90 | 91 | if (size > vec->alc) 92 | { 93 | size_t alc; 94 | void *base; 95 | 96 | if (vec->size == 0) 97 | alc = 32 * size; 98 | else if (vec->size >= 4096) 99 | alc = vec->size + 4096; 100 | else 101 | alc = 2 * vec->size; 102 | 103 | if (alc < vec->size + size) 104 | alc = vec->size + size; 105 | 106 | base = tracy_realloc (vec->base, alc); 107 | if (base == NULL) 108 | { 109 | error_callback (data, "realloc", errno); 110 | return NULL; 111 | } 112 | 113 | vec->base = base; 114 | vec->alc = alc - vec->size; 115 | } 116 | 117 | ret = (char *) vec->base + vec->size; 118 | vec->size += size; 119 | vec->alc -= size; 120 | return ret; 121 | } 122 | 123 | /* Finish the current allocation on VEC. */ 124 | 125 | void * 126 | backtrace_vector_finish (struct backtrace_state *state, 127 | struct backtrace_vector *vec, 128 | backtrace_error_callback error_callback, 129 | void *data) 130 | { 131 | void *ret; 132 | 133 | /* With this allocator we call realloc in backtrace_vector_grow, 134 | which means we can't easily reuse the memory here. So just 135 | release it. */ 136 | if (!backtrace_vector_release (state, vec, error_callback, data)) 137 | return NULL; 138 | ret = vec->base; 139 | vec->base = NULL; 140 | vec->size = 0; 141 | vec->alc = 0; 142 | return ret; 143 | } 144 | 145 | /* Release any extra space allocated for VEC. */ 146 | 147 | int 148 | backtrace_vector_release (struct backtrace_state *state ATTRIBUTE_UNUSED, 149 | struct backtrace_vector *vec, 150 | backtrace_error_callback error_callback, 151 | void *data) 152 | { 153 | vec->alc = 0; 154 | 155 | if (vec->size == 0) 156 | { 157 | /* As of C17, realloc with size 0 is marked as an obsolescent feature, use 158 | free instead. */ 159 | tracy_free (vec->base); 160 | vec->base = NULL; 161 | return 1; 162 | } 163 | 164 | vec->base = tracy_realloc (vec->base, vec->size); 165 | if (vec->base == NULL) 166 | { 167 | error_callback (data, "realloc", errno); 168 | return 0; 169 | } 170 | 171 | return 1; 172 | } 173 | 174 | } 175 | -------------------------------------------------------------------------------- /tracy-0.7.8/libbacktrace/backtrace.hpp: -------------------------------------------------------------------------------- 1 | /* backtrace.h -- Public header file for stack backtrace library. 2 | Copyright (C) 2012-2021 Free Software Foundation, Inc. 3 | Written by Ian Lance Taylor, Google. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | (1) Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | (2) Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | (3) The name of the author may not be used to 18 | endorse or promote products derived from this software without 19 | specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. */ 32 | 33 | #ifndef BACKTRACE_H 34 | #define BACKTRACE_H 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | namespace tracy 41 | { 42 | 43 | /* The backtrace state. This struct is intentionally not defined in 44 | the public interface. */ 45 | 46 | struct backtrace_state; 47 | 48 | /* The type of the error callback argument to backtrace functions. 49 | This function, if not NULL, will be called for certain error cases. 50 | The DATA argument is passed to the function that calls this one. 51 | The MSG argument is an error message. The ERRNUM argument, if 52 | greater than 0, holds an errno value. The MSG buffer may become 53 | invalid after this function returns. 54 | 55 | As a special case, the ERRNUM argument will be passed as -1 if no 56 | debug info can be found for the executable, but the function 57 | requires debug info (e.g., backtrace_full, backtrace_pcinfo). The 58 | MSG in this case will be something along the lines of "no debug 59 | info". Similarly, ERRNUM will be passed as -1 if there is no 60 | symbol table, but the function requires a symbol table (e.g., 61 | backtrace_syminfo). This may be used as a signal that some other 62 | approach should be tried. */ 63 | 64 | typedef void (*backtrace_error_callback) (void *data, const char *msg, 65 | int errnum); 66 | 67 | /* Create state information for the backtrace routines. This must be 68 | called before any of the other routines, and its return value must 69 | be passed to all of the other routines. FILENAME is the path name 70 | of the executable file; if it is NULL the library will try 71 | system-specific path names. If not NULL, FILENAME must point to a 72 | permanent buffer. If THREADED is non-zero the state may be 73 | accessed by multiple threads simultaneously, and the library will 74 | use appropriate atomic operations. If THREADED is zero the state 75 | may only be accessed by one thread at a time. This returns a state 76 | pointer on success, NULL on error. If an error occurs, this will 77 | call the ERROR_CALLBACK routine. 78 | 79 | Calling this function allocates resources that cannot be freed. 80 | There is no backtrace_free_state function. The state is used to 81 | cache information that is expensive to recompute. Programs are 82 | expected to call this function at most once and to save the return 83 | value for all later calls to backtrace functions. */ 84 | 85 | extern struct backtrace_state *backtrace_create_state ( 86 | const char *filename, int threaded, 87 | backtrace_error_callback error_callback, void *data); 88 | 89 | /* The type of the callback argument to the backtrace_full function. 90 | DATA is the argument passed to backtrace_full. PC is the program 91 | counter. FILENAME is the name of the file containing PC, or NULL 92 | if not available. LINENO is the line number in FILENAME containing 93 | PC, or 0 if not available. FUNCTION is the name of the function 94 | containing PC, or NULL if not available. This should return 0 to 95 | continuing tracing. The FILENAME and FUNCTION buffers may become 96 | invalid after this function returns. */ 97 | 98 | typedef int (*backtrace_full_callback) (void *data, uintptr_t pc, uintptr_t lowaddr, 99 | const char *filename, int lineno, 100 | const char *function); 101 | 102 | /* Get a full stack backtrace. SKIP is the number of frames to skip; 103 | passing 0 will start the trace with the function calling 104 | backtrace_full. DATA is passed to the callback routine. If any 105 | call to CALLBACK returns a non-zero value, the stack backtrace 106 | stops, and backtrace returns that value; this may be used to limit 107 | the number of stack frames desired. If all calls to CALLBACK 108 | return 0, backtrace returns 0. The backtrace_full function will 109 | make at least one call to either CALLBACK or ERROR_CALLBACK. This 110 | function requires debug info for the executable. */ 111 | 112 | extern int backtrace_full (struct backtrace_state *state, int skip, 113 | backtrace_full_callback callback, 114 | backtrace_error_callback error_callback, 115 | void *data); 116 | 117 | /* The type of the callback argument to the backtrace_simple function. 118 | DATA is the argument passed to simple_backtrace. PC is the program 119 | counter. This should return 0 to continue tracing. */ 120 | 121 | typedef int (*backtrace_simple_callback) (void *data, uintptr_t pc); 122 | 123 | /* Get a simple backtrace. SKIP is the number of frames to skip, as 124 | in backtrace. DATA is passed to the callback routine. If any call 125 | to CALLBACK returns a non-zero value, the stack backtrace stops, 126 | and backtrace_simple returns that value. Otherwise 127 | backtrace_simple returns 0. The backtrace_simple function will 128 | make at least one call to either CALLBACK or ERROR_CALLBACK. This 129 | function does not require any debug info for the executable. */ 130 | 131 | extern int backtrace_simple (struct backtrace_state *state, int skip, 132 | backtrace_simple_callback callback, 133 | backtrace_error_callback error_callback, 134 | void *data); 135 | 136 | /* Print the current backtrace in a user readable format to a FILE. 137 | SKIP is the number of frames to skip, as in backtrace_full. Any 138 | error messages are printed to stderr. This function requires debug 139 | info for the executable. */ 140 | 141 | extern void backtrace_print (struct backtrace_state *state, int skip, FILE *); 142 | 143 | /* Given PC, a program counter in the current program, call the 144 | callback function with filename, line number, and function name 145 | information. This will normally call the callback function exactly 146 | once. However, if the PC happens to describe an inlined call, and 147 | the debugging information contains the necessary information, then 148 | this may call the callback function multiple times. This will make 149 | at least one call to either CALLBACK or ERROR_CALLBACK. This 150 | returns the first non-zero value returned by CALLBACK, or 0. */ 151 | 152 | extern int backtrace_pcinfo (struct backtrace_state *state, uintptr_t pc, 153 | backtrace_full_callback callback, 154 | backtrace_error_callback error_callback, 155 | void *data); 156 | 157 | /* The type of the callback argument to backtrace_syminfo. DATA and 158 | PC are the arguments passed to backtrace_syminfo. SYMNAME is the 159 | name of the symbol for the corresponding code. SYMVAL is the 160 | value and SYMSIZE is the size of the symbol. SYMNAME will be NULL 161 | if no error occurred but the symbol could not be found. */ 162 | 163 | typedef void (*backtrace_syminfo_callback) (void *data, uintptr_t pc, 164 | const char *symname, 165 | uintptr_t symval, 166 | uintptr_t symsize); 167 | 168 | /* Given ADDR, an address or program counter in the current program, 169 | call the callback information with the symbol name and value 170 | describing the function or variable in which ADDR may be found. 171 | This will call either CALLBACK or ERROR_CALLBACK exactly once. 172 | This returns 1 on success, 0 on failure. This function requires 173 | the symbol table but does not require the debug info. Note that if 174 | the symbol table is present but ADDR could not be found in the 175 | table, CALLBACK will be called with a NULL SYMNAME argument. 176 | Returns 1 on success, 0 on error. */ 177 | 178 | extern int backtrace_syminfo (struct backtrace_state *state, uintptr_t addr, 179 | backtrace_syminfo_callback callback, 180 | backtrace_error_callback error_callback, 181 | void *data); 182 | 183 | } 184 | 185 | #endif 186 | -------------------------------------------------------------------------------- /tracy-0.7.8/libbacktrace/config.h: -------------------------------------------------------------------------------- 1 | #include 2 | #if __WORDSIZE == 64 3 | # define BACKTRACE_ELF_SIZE 64 4 | #else 5 | # define BACKTRACE_ELF_SIZE 32 6 | #endif 7 | 8 | #define HAVE_DLFCN_H 1 9 | #define HAVE_FCNTL 1 10 | #define HAVE_INTTYPES_H 1 11 | #define HAVE_LSTAT 1 12 | #define HAVE_READLINK 1 13 | #define HAVE_DL_ITERATE_PHDR 1 14 | #define HAVE_ATOMIC_FUNCTIONS 1 15 | #define HAVE_DECL_STRNLEN 1 16 | 17 | #ifdef __APPLE__ 18 | # define HAVE_MACH_O_DYLD_H 1 19 | #elif defined BSD 20 | # define HAVE_KERN_PROC 1 21 | # define HAVE_KERN_PROC_ARGS 1 22 | #endif 23 | -------------------------------------------------------------------------------- /tracy-0.7.8/libbacktrace/fileline.cpp: -------------------------------------------------------------------------------- 1 | /* fileline.c -- Get file and line number information in a backtrace. 2 | Copyright (C) 2012-2021 Free Software Foundation, Inc. 3 | Written by Ian Lance Taylor, Google. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | (1) Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | (2) Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | (3) The name of the author may not be used to 18 | endorse or promote products derived from this software without 19 | specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. */ 32 | 33 | #include "config.h" 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #if defined (HAVE_KERN_PROC_ARGS) || defined (HAVE_KERN_PROC) 43 | #include 44 | #endif 45 | 46 | #ifdef HAVE_MACH_O_DYLD_H 47 | #include 48 | #endif 49 | 50 | #include "backtrace.hpp" 51 | #include "internal.hpp" 52 | 53 | #ifndef HAVE_GETEXECNAME 54 | #define getexecname() NULL 55 | #endif 56 | 57 | namespace tracy 58 | { 59 | 60 | #if !defined (HAVE_KERN_PROC_ARGS) && !defined (HAVE_KERN_PROC) 61 | 62 | #define sysctl_exec_name1(state, error_callback, data) NULL 63 | #define sysctl_exec_name2(state, error_callback, data) NULL 64 | 65 | #else /* defined (HAVE_KERN_PROC_ARGS) || |defined (HAVE_KERN_PROC) */ 66 | 67 | static char * 68 | sysctl_exec_name (struct backtrace_state *state, 69 | int mib0, int mib1, int mib2, int mib3, 70 | backtrace_error_callback error_callback, void *data) 71 | { 72 | int mib[4]; 73 | size_t len; 74 | char *name; 75 | size_t rlen; 76 | 77 | mib[0] = mib0; 78 | mib[1] = mib1; 79 | mib[2] = mib2; 80 | mib[3] = mib3; 81 | 82 | if (sysctl (mib, 4, NULL, &len, NULL, 0) < 0) 83 | return NULL; 84 | name = (char *) backtrace_alloc (state, len, error_callback, data); 85 | if (name == NULL) 86 | return NULL; 87 | rlen = len; 88 | if (sysctl (mib, 4, name, &rlen, NULL, 0) < 0) 89 | { 90 | backtrace_free (state, name, len, error_callback, data); 91 | return NULL; 92 | } 93 | return name; 94 | } 95 | 96 | #ifdef HAVE_KERN_PROC_ARGS 97 | 98 | static char * 99 | sysctl_exec_name1 (struct backtrace_state *state, 100 | backtrace_error_callback error_callback, void *data) 101 | { 102 | /* This variant is used on NetBSD. */ 103 | return sysctl_exec_name (state, CTL_KERN, KERN_PROC_ARGS, -1, 104 | KERN_PROC_PATHNAME, error_callback, data); 105 | } 106 | 107 | #else 108 | 109 | #define sysctl_exec_name1(state, error_callback, data) NULL 110 | 111 | #endif 112 | 113 | #ifdef HAVE_KERN_PROC 114 | 115 | static char * 116 | sysctl_exec_name2 (struct backtrace_state *state, 117 | backtrace_error_callback error_callback, void *data) 118 | { 119 | /* This variant is used on FreeBSD. */ 120 | return sysctl_exec_name (state, CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1, 121 | error_callback, data); 122 | } 123 | 124 | #else 125 | 126 | #define sysctl_exec_name2(state, error_callback, data) NULL 127 | 128 | #endif 129 | 130 | #endif /* defined (HAVE_KERN_PROC_ARGS) || |defined (HAVE_KERN_PROC) */ 131 | 132 | #ifdef HAVE_MACH_O_DYLD_H 133 | 134 | static char * 135 | macho_get_executable_path (struct backtrace_state *state, 136 | backtrace_error_callback error_callback, void *data) 137 | { 138 | uint32_t len; 139 | char *name; 140 | 141 | len = 0; 142 | if (_NSGetExecutablePath (NULL, &len) == 0) 143 | return NULL; 144 | name = (char *) backtrace_alloc (state, len, error_callback, data); 145 | if (name == NULL) 146 | return NULL; 147 | if (_NSGetExecutablePath (name, &len) != 0) 148 | { 149 | backtrace_free (state, name, len, error_callback, data); 150 | return NULL; 151 | } 152 | return name; 153 | } 154 | 155 | #else /* !defined (HAVE_MACH_O_DYLD_H) */ 156 | 157 | #define macho_get_executable_path(state, error_callback, data) NULL 158 | 159 | #endif /* !defined (HAVE_MACH_O_DYLD_H) */ 160 | 161 | /* Initialize the fileline information from the executable. Returns 1 162 | on success, 0 on failure. */ 163 | 164 | static int 165 | fileline_initialize (struct backtrace_state *state, 166 | backtrace_error_callback error_callback, void *data) 167 | { 168 | int failed; 169 | fileline fileline_fn; 170 | int pass; 171 | int called_error_callback; 172 | int descriptor; 173 | const char *filename; 174 | char buf[64]; 175 | 176 | if (!state->threaded) 177 | failed = state->fileline_initialization_failed; 178 | else 179 | failed = backtrace_atomic_load_int (&state->fileline_initialization_failed); 180 | 181 | if (failed) 182 | { 183 | error_callback (data, "failed to read executable information", -1); 184 | return 0; 185 | } 186 | 187 | if (!state->threaded) 188 | fileline_fn = state->fileline_fn; 189 | else 190 | fileline_fn = backtrace_atomic_load_pointer (&state->fileline_fn); 191 | if (fileline_fn != NULL) 192 | return 1; 193 | 194 | /* We have not initialized the information. Do it now. */ 195 | 196 | descriptor = -1; 197 | called_error_callback = 0; 198 | for (pass = 0; pass < 8; ++pass) 199 | { 200 | int does_not_exist; 201 | 202 | switch (pass) 203 | { 204 | case 0: 205 | filename = state->filename; 206 | break; 207 | case 1: 208 | filename = getexecname (); 209 | break; 210 | case 2: 211 | filename = "/proc/self/exe"; 212 | break; 213 | case 3: 214 | filename = "/proc/curproc/file"; 215 | break; 216 | case 4: 217 | snprintf (buf, sizeof (buf), "/proc/%ld/object/a.out", 218 | (long) getpid ()); 219 | filename = buf; 220 | break; 221 | case 5: 222 | filename = sysctl_exec_name1 (state, error_callback, data); 223 | break; 224 | case 6: 225 | filename = sysctl_exec_name2 (state, error_callback, data); 226 | break; 227 | case 7: 228 | filename = macho_get_executable_path (state, error_callback, data); 229 | break; 230 | default: 231 | abort (); 232 | } 233 | 234 | if (filename == NULL) 235 | continue; 236 | 237 | descriptor = backtrace_open (filename, error_callback, data, 238 | &does_not_exist); 239 | if (descriptor < 0 && !does_not_exist) 240 | { 241 | called_error_callback = 1; 242 | break; 243 | } 244 | if (descriptor >= 0) 245 | break; 246 | } 247 | 248 | if (descriptor < 0) 249 | { 250 | if (!called_error_callback) 251 | { 252 | if (state->filename != NULL) 253 | error_callback (data, state->filename, ENOENT); 254 | else 255 | error_callback (data, 256 | "libbacktrace could not find executable to open", 257 | 0); 258 | } 259 | failed = 1; 260 | } 261 | 262 | if (!failed) 263 | { 264 | if (!backtrace_initialize (state, filename, descriptor, error_callback, 265 | data, &fileline_fn)) 266 | failed = 1; 267 | } 268 | 269 | if (failed) 270 | { 271 | if (!state->threaded) 272 | state->fileline_initialization_failed = 1; 273 | else 274 | backtrace_atomic_store_int (&state->fileline_initialization_failed, 1); 275 | return 0; 276 | } 277 | 278 | if (!state->threaded) 279 | state->fileline_fn = fileline_fn; 280 | else 281 | { 282 | backtrace_atomic_store_pointer (&state->fileline_fn, fileline_fn); 283 | 284 | /* Note that if two threads initialize at once, one of the data 285 | sets may be leaked. */ 286 | } 287 | 288 | return 1; 289 | } 290 | 291 | /* Given a PC, find the file name, line number, and function name. */ 292 | 293 | int 294 | backtrace_pcinfo (struct backtrace_state *state, uintptr_t pc, 295 | backtrace_full_callback callback, 296 | backtrace_error_callback error_callback, void *data) 297 | { 298 | if (!fileline_initialize (state, error_callback, data)) 299 | return 0; 300 | 301 | if (state->fileline_initialization_failed) 302 | return 0; 303 | 304 | return state->fileline_fn (state, pc, callback, error_callback, data); 305 | } 306 | 307 | /* Given a PC, find the symbol for it, and its value. */ 308 | 309 | int 310 | backtrace_syminfo (struct backtrace_state *state, uintptr_t pc, 311 | backtrace_syminfo_callback callback, 312 | backtrace_error_callback error_callback, void *data) 313 | { 314 | if (!fileline_initialize (state, error_callback, data)) 315 | return 0; 316 | 317 | if (state->fileline_initialization_failed) 318 | return 0; 319 | 320 | state->syminfo_fn (state, pc, callback, error_callback, data); 321 | return 1; 322 | } 323 | 324 | /* A backtrace_syminfo_callback that can call into a 325 | backtrace_full_callback, used when we have a symbol table but no 326 | debug info. */ 327 | 328 | void 329 | backtrace_syminfo_to_full_callback (void *data, uintptr_t pc, 330 | const char *symname, 331 | uintptr_t symval ATTRIBUTE_UNUSED, 332 | uintptr_t symsize ATTRIBUTE_UNUSED) 333 | { 334 | struct backtrace_call_full *bdata = (struct backtrace_call_full *) data; 335 | 336 | bdata->ret = bdata->full_callback (bdata->full_data, pc, 0, NULL, 0, symname); 337 | } 338 | 339 | /* An error callback that corresponds to 340 | backtrace_syminfo_to_full_callback. */ 341 | 342 | void 343 | backtrace_syminfo_to_full_error_callback (void *data, const char *msg, 344 | int errnum) 345 | { 346 | struct backtrace_call_full *bdata = (struct backtrace_call_full *) data; 347 | 348 | bdata->full_error_callback (bdata->full_data, msg, errnum); 349 | } 350 | 351 | } 352 | -------------------------------------------------------------------------------- /tracy-0.7.8/libbacktrace/filenames.hpp: -------------------------------------------------------------------------------- 1 | /* btest.c -- Filename header for libbacktrace library 2 | Copyright (C) 2012-2018 Free Software Foundation, Inc. 3 | Written by Ian Lance Taylor, Google. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | (1) Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | (2) Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | (3) The name of the author may not be used to 18 | endorse or promote products derived from this software without 19 | specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. */ 32 | 33 | #ifndef GCC_VERSION 34 | # define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__) 35 | #endif 36 | 37 | #if (GCC_VERSION < 2007) 38 | # define __attribute__(x) 39 | #endif 40 | 41 | #ifndef ATTRIBUTE_UNUSED 42 | # define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) 43 | #endif 44 | 45 | #if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined (__CYGWIN__) 46 | # define IS_DIR_SEPARATOR(c) ((c) == '/' || (c) == '\\') 47 | # define HAS_DRIVE_SPEC(f) ((f)[0] != '\0' && (f)[1] == ':') 48 | # define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0]) || HAS_DRIVE_SPEC(f)) 49 | #else 50 | # define IS_DIR_SEPARATOR(c) ((c) == '/') 51 | # define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0])) 52 | #endif 53 | -------------------------------------------------------------------------------- /tracy-0.7.8/libbacktrace/internal.hpp: -------------------------------------------------------------------------------- 1 | /* internal.h -- Internal header file for stack backtrace library. 2 | Copyright (C) 2012-2021 Free Software Foundation, Inc. 3 | Written by Ian Lance Taylor, Google. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | (1) Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | (2) Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | (3) The name of the author may not be used to 18 | endorse or promote products derived from this software without 19 | specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. */ 32 | 33 | #ifndef BACKTRACE_INTERNAL_H 34 | #define BACKTRACE_INTERNAL_H 35 | 36 | /* We assume that and "backtrace.h" have already been 37 | included. */ 38 | 39 | #ifndef GCC_VERSION 40 | # define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__) 41 | #endif 42 | 43 | #if (GCC_VERSION < 2007) 44 | # define __attribute__(x) 45 | #endif 46 | 47 | #ifndef ATTRIBUTE_UNUSED 48 | # define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) 49 | #endif 50 | 51 | #ifndef ATTRIBUTE_MALLOC 52 | # if (GCC_VERSION >= 2096) 53 | # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) 54 | # else 55 | # define ATTRIBUTE_MALLOC 56 | # endif 57 | #endif 58 | 59 | #ifndef ATTRIBUTE_FALLTHROUGH 60 | # if (GCC_VERSION >= 7000) 61 | # define ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__)) 62 | # else 63 | # define ATTRIBUTE_FALLTHROUGH 64 | # endif 65 | #endif 66 | 67 | #ifndef HAVE_SYNC_FUNCTIONS 68 | 69 | /* Define out the sync functions. These should never be called if 70 | they are not available. */ 71 | 72 | #define __sync_bool_compare_and_swap(A, B, C) (abort(), 1) 73 | #define __sync_lock_test_and_set(A, B) (abort(), 0) 74 | #define __sync_lock_release(A) abort() 75 | 76 | #endif /* !defined (HAVE_SYNC_FUNCTIONS) */ 77 | 78 | #ifdef HAVE_ATOMIC_FUNCTIONS 79 | 80 | /* We have the atomic builtin functions. */ 81 | 82 | #define backtrace_atomic_load_pointer(p) \ 83 | __atomic_load_n ((p), __ATOMIC_ACQUIRE) 84 | #define backtrace_atomic_load_int(p) \ 85 | __atomic_load_n ((p), __ATOMIC_ACQUIRE) 86 | #define backtrace_atomic_store_pointer(p, v) \ 87 | __atomic_store_n ((p), (v), __ATOMIC_RELEASE) 88 | #define backtrace_atomic_store_size_t(p, v) \ 89 | __atomic_store_n ((p), (v), __ATOMIC_RELEASE) 90 | #define backtrace_atomic_store_int(p, v) \ 91 | __atomic_store_n ((p), (v), __ATOMIC_RELEASE) 92 | 93 | #else /* !defined (HAVE_ATOMIC_FUNCTIONS) */ 94 | #ifdef HAVE_SYNC_FUNCTIONS 95 | 96 | /* We have the sync functions but not the atomic functions. Define 97 | the atomic ones in terms of the sync ones. */ 98 | 99 | extern void *backtrace_atomic_load_pointer (void *); 100 | extern int backtrace_atomic_load_int (int *); 101 | extern void backtrace_atomic_store_pointer (void *, void *); 102 | extern void backtrace_atomic_store_size_t (size_t *, size_t); 103 | extern void backtrace_atomic_store_int (int *, int); 104 | 105 | #else /* !defined (HAVE_SYNC_FUNCTIONS) */ 106 | 107 | /* We have neither the sync nor the atomic functions. These will 108 | never be called. */ 109 | 110 | #define backtrace_atomic_load_pointer(p) (abort(), (void *) NULL) 111 | #define backtrace_atomic_load_int(p) (abort(), 0) 112 | #define backtrace_atomic_store_pointer(p, v) abort() 113 | #define backtrace_atomic_store_size_t(p, v) abort() 114 | #define backtrace_atomic_store_int(p, v) abort() 115 | 116 | #endif /* !defined (HAVE_SYNC_FUNCTIONS) */ 117 | #endif /* !defined (HAVE_ATOMIC_FUNCTIONS) */ 118 | 119 | namespace tracy 120 | { 121 | 122 | /* The type of the function that collects file/line information. This 123 | is like backtrace_pcinfo. */ 124 | 125 | typedef int (*fileline) (struct backtrace_state *state, uintptr_t pc, 126 | backtrace_full_callback callback, 127 | backtrace_error_callback error_callback, void *data); 128 | 129 | /* The type of the function that collects symbol information. This is 130 | like backtrace_syminfo. */ 131 | 132 | typedef void (*syminfo) (struct backtrace_state *state, uintptr_t pc, 133 | backtrace_syminfo_callback callback, 134 | backtrace_error_callback error_callback, void *data); 135 | 136 | /* What the backtrace state pointer points to. */ 137 | 138 | struct backtrace_state 139 | { 140 | /* The name of the executable. */ 141 | const char *filename; 142 | /* Non-zero if threaded. */ 143 | int threaded; 144 | /* The master lock for fileline_fn, fileline_data, syminfo_fn, 145 | syminfo_data, fileline_initialization_failed and everything the 146 | data pointers point to. */ 147 | void *lock; 148 | /* The function that returns file/line information. */ 149 | fileline fileline_fn; 150 | /* The data to pass to FILELINE_FN. */ 151 | void *fileline_data; 152 | /* The function that returns symbol information. */ 153 | syminfo syminfo_fn; 154 | /* The data to pass to SYMINFO_FN. */ 155 | void *syminfo_data; 156 | /* Whether initializing the file/line information failed. */ 157 | int fileline_initialization_failed; 158 | /* The lock for the freelist. */ 159 | int lock_alloc; 160 | /* The freelist when using mmap. */ 161 | struct backtrace_freelist_struct *freelist; 162 | }; 163 | 164 | /* Open a file for reading. Returns -1 on error. If DOES_NOT_EXIST 165 | is not NULL, *DOES_NOT_EXIST will be set to 0 normally and set to 1 166 | if the file does not exist. If the file does not exist and 167 | DOES_NOT_EXIST is not NULL, the function will return -1 and will 168 | not call ERROR_CALLBACK. On other errors, or if DOES_NOT_EXIST is 169 | NULL, the function will call ERROR_CALLBACK before returning. */ 170 | extern int backtrace_open (const char *filename, 171 | backtrace_error_callback error_callback, 172 | void *data, 173 | int *does_not_exist); 174 | 175 | /* A view of the contents of a file. This supports mmap when 176 | available. A view will remain in memory even after backtrace_close 177 | is called on the file descriptor from which the view was 178 | obtained. */ 179 | 180 | struct backtrace_view 181 | { 182 | /* The data that the caller requested. */ 183 | const void *data; 184 | /* The base of the view. */ 185 | void *base; 186 | /* The total length of the view. */ 187 | size_t len; 188 | }; 189 | 190 | /* Create a view of SIZE bytes from DESCRIPTOR at OFFSET. Store the 191 | result in *VIEW. Returns 1 on success, 0 on error. */ 192 | extern int backtrace_get_view (struct backtrace_state *state, int descriptor, 193 | off_t offset, uint64_t size, 194 | backtrace_error_callback error_callback, 195 | void *data, struct backtrace_view *view); 196 | 197 | /* Release a view created by backtrace_get_view. */ 198 | extern void backtrace_release_view (struct backtrace_state *state, 199 | struct backtrace_view *view, 200 | backtrace_error_callback error_callback, 201 | void *data); 202 | 203 | /* Close a file opened by backtrace_open. Returns 1 on success, 0 on 204 | error. */ 205 | 206 | extern int backtrace_close (int descriptor, 207 | backtrace_error_callback error_callback, 208 | void *data); 209 | 210 | /* Sort without using memory. */ 211 | 212 | extern void backtrace_qsort (void *base, size_t count, size_t size, 213 | int (*compar) (const void *, const void *)); 214 | 215 | /* Allocate memory. This is like malloc. If ERROR_CALLBACK is NULL, 216 | this does not report an error, it just returns NULL. */ 217 | 218 | extern void *backtrace_alloc (struct backtrace_state *state, size_t size, 219 | backtrace_error_callback error_callback, 220 | void *data) ATTRIBUTE_MALLOC; 221 | 222 | /* Free memory allocated by backtrace_alloc. If ERROR_CALLBACK is 223 | NULL, this does not report an error. */ 224 | 225 | extern void backtrace_free (struct backtrace_state *state, void *mem, 226 | size_t size, 227 | backtrace_error_callback error_callback, 228 | void *data); 229 | 230 | /* A growable vector of some struct. This is used for more efficient 231 | allocation when we don't know the final size of some group of data 232 | that we want to represent as an array. */ 233 | 234 | struct backtrace_vector 235 | { 236 | /* The base of the vector. */ 237 | void *base; 238 | /* The number of bytes in the vector. */ 239 | size_t size; 240 | /* The number of bytes available at the current allocation. */ 241 | size_t alc; 242 | }; 243 | 244 | /* Grow VEC by SIZE bytes. Return a pointer to the newly allocated 245 | bytes. Note that this may move the entire vector to a new memory 246 | location. Returns NULL on failure. */ 247 | 248 | extern void *backtrace_vector_grow (struct backtrace_state *state, size_t size, 249 | backtrace_error_callback error_callback, 250 | void *data, 251 | struct backtrace_vector *vec); 252 | 253 | /* Finish the current allocation on VEC. Prepare to start a new 254 | allocation. The finished allocation will never be freed. Returns 255 | a pointer to the base of the finished entries, or NULL on 256 | failure. */ 257 | 258 | extern void* backtrace_vector_finish (struct backtrace_state *state, 259 | struct backtrace_vector *vec, 260 | backtrace_error_callback error_callback, 261 | void *data); 262 | 263 | /* Release any extra space allocated for VEC. This may change 264 | VEC->base. Returns 1 on success, 0 on failure. */ 265 | 266 | extern int backtrace_vector_release (struct backtrace_state *state, 267 | struct backtrace_vector *vec, 268 | backtrace_error_callback error_callback, 269 | void *data); 270 | 271 | /* Free the space managed by VEC. This will reset VEC. */ 272 | 273 | static inline void 274 | backtrace_vector_free (struct backtrace_state *state, 275 | struct backtrace_vector *vec, 276 | backtrace_error_callback error_callback, void *data) 277 | { 278 | vec->alc += vec->size; 279 | vec->size = 0; 280 | backtrace_vector_release (state, vec, error_callback, data); 281 | } 282 | 283 | /* Read initial debug data from a descriptor, and set the 284 | fileline_data, syminfo_fn, and syminfo_data fields of STATE. 285 | Return the fileln_fn field in *FILELN_FN--this is done this way so 286 | that the synchronization code is only implemented once. This is 287 | called after the descriptor has first been opened. It will close 288 | the descriptor if it is no longer needed. Returns 1 on success, 0 289 | on error. There will be multiple implementations of this function, 290 | for different file formats. Each system will compile the 291 | appropriate one. */ 292 | 293 | extern int backtrace_initialize (struct backtrace_state *state, 294 | const char *filename, 295 | int descriptor, 296 | backtrace_error_callback error_callback, 297 | void *data, 298 | fileline *fileline_fn); 299 | 300 | /* An enum for the DWARF sections we care about. */ 301 | 302 | enum dwarf_section 303 | { 304 | DEBUG_INFO, 305 | DEBUG_LINE, 306 | DEBUG_ABBREV, 307 | DEBUG_RANGES, 308 | DEBUG_STR, 309 | DEBUG_ADDR, 310 | DEBUG_STR_OFFSETS, 311 | DEBUG_LINE_STR, 312 | DEBUG_RNGLISTS, 313 | 314 | DEBUG_MAX 315 | }; 316 | 317 | /* Data for the DWARF sections we care about. */ 318 | 319 | struct dwarf_sections 320 | { 321 | const unsigned char *data[DEBUG_MAX]; 322 | size_t size[DEBUG_MAX]; 323 | }; 324 | 325 | /* DWARF data read from a file, used for .gnu_debugaltlink. */ 326 | 327 | struct dwarf_data; 328 | 329 | /* Add file/line information for a DWARF module. */ 330 | 331 | extern int backtrace_dwarf_add (struct backtrace_state *state, 332 | uintptr_t base_address, 333 | const struct dwarf_sections *dwarf_sections, 334 | int is_bigendian, 335 | struct dwarf_data *fileline_altlink, 336 | backtrace_error_callback error_callback, 337 | void *data, fileline *fileline_fn, 338 | struct dwarf_data **fileline_entry); 339 | 340 | /* A data structure to pass to backtrace_syminfo_to_full. */ 341 | 342 | struct backtrace_call_full 343 | { 344 | backtrace_full_callback full_callback; 345 | backtrace_error_callback full_error_callback; 346 | void *full_data; 347 | int ret; 348 | }; 349 | 350 | /* A backtrace_syminfo_callback that can call into a 351 | backtrace_full_callback, used when we have a symbol table but no 352 | debug info. */ 353 | 354 | extern void backtrace_syminfo_to_full_callback (void *data, uintptr_t pc, 355 | const char *symname, 356 | uintptr_t symval, 357 | uintptr_t symsize); 358 | 359 | /* An error callback that corresponds to 360 | backtrace_syminfo_to_full_callback. */ 361 | 362 | extern void backtrace_syminfo_to_full_error_callback (void *, const char *, 363 | int); 364 | 365 | /* A test-only hook for elf_uncompress_zdebug. */ 366 | 367 | extern int backtrace_uncompress_zdebug (struct backtrace_state *, 368 | const unsigned char *compressed, 369 | size_t compressed_size, 370 | backtrace_error_callback, void *data, 371 | unsigned char **uncompressed, 372 | size_t *uncompressed_size); 373 | 374 | /* A test-only hook for elf_uncompress_lzma. */ 375 | 376 | extern int backtrace_uncompress_lzma (struct backtrace_state *, 377 | const unsigned char *compressed, 378 | size_t compressed_size, 379 | backtrace_error_callback, void *data, 380 | unsigned char **uncompressed, 381 | size_t *uncompressed_size); 382 | 383 | } 384 | 385 | #endif 386 | -------------------------------------------------------------------------------- /tracy-0.7.8/libbacktrace/mmapio.cpp: -------------------------------------------------------------------------------- 1 | /* mmapio.c -- File views using mmap. 2 | Copyright (C) 2012-2021 Free Software Foundation, Inc. 3 | Written by Ian Lance Taylor, Google. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | (1) Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | (2) Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | (3) The name of the author may not be used to 18 | endorse or promote products derived from this software without 19 | specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. */ 32 | 33 | #include "config.h" 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "backtrace.hpp" 41 | #include "internal.hpp" 42 | 43 | #ifndef HAVE_DECL_GETPAGESIZE 44 | extern int getpagesize (void); 45 | #endif 46 | 47 | #ifndef MAP_FAILED 48 | #define MAP_FAILED ((void *)-1) 49 | #endif 50 | 51 | namespace tracy 52 | { 53 | 54 | /* This file implements file views and memory allocation when mmap is 55 | available. */ 56 | 57 | /* Create a view of SIZE bytes from DESCRIPTOR at OFFSET. */ 58 | 59 | int 60 | backtrace_get_view (struct backtrace_state *state ATTRIBUTE_UNUSED, 61 | int descriptor, off_t offset, uint64_t size, 62 | backtrace_error_callback error_callback, 63 | void *data, struct backtrace_view *view) 64 | { 65 | size_t pagesize; 66 | unsigned int inpage; 67 | off_t pageoff; 68 | void *map; 69 | 70 | if ((uint64_t) (size_t) size != size) 71 | { 72 | error_callback (data, "file size too large", 0); 73 | return 0; 74 | } 75 | 76 | pagesize = getpagesize (); 77 | inpage = offset % pagesize; 78 | pageoff = offset - inpage; 79 | 80 | size += inpage; 81 | size = (size + (pagesize - 1)) & ~ (pagesize - 1); 82 | 83 | map = mmap (NULL, size, PROT_READ, MAP_PRIVATE, descriptor, pageoff); 84 | if (map == MAP_FAILED) 85 | { 86 | error_callback (data, "mmap", errno); 87 | return 0; 88 | } 89 | 90 | view->data = (char *) map + inpage; 91 | view->base = map; 92 | view->len = size; 93 | 94 | return 1; 95 | } 96 | 97 | /* Release a view read by backtrace_get_view. */ 98 | 99 | void 100 | backtrace_release_view (struct backtrace_state *state ATTRIBUTE_UNUSED, 101 | struct backtrace_view *view, 102 | backtrace_error_callback error_callback, 103 | void *data) 104 | { 105 | union { 106 | const void *cv; 107 | void *v; 108 | } cc; 109 | 110 | cc.cv = view->base; 111 | if (munmap (cc.v, view->len) < 0) 112 | error_callback (data, "munmap", errno); 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /tracy-0.7.8/libbacktrace/posix.cpp: -------------------------------------------------------------------------------- 1 | /* posix.c -- POSIX file I/O routines for the backtrace library. 2 | Copyright (C) 2012-2021 Free Software Foundation, Inc. 3 | Written by Ian Lance Taylor, Google. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | (1) Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | (2) Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | (3) The name of the author may not be used to 18 | endorse or promote products derived from this software without 19 | specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. */ 32 | 33 | #include "config.h" 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "backtrace.hpp" 42 | #include "internal.hpp" 43 | 44 | #ifndef O_BINARY 45 | #define O_BINARY 0 46 | #endif 47 | 48 | #ifndef O_CLOEXEC 49 | #define O_CLOEXEC 0 50 | #endif 51 | 52 | #ifndef FD_CLOEXEC 53 | #define FD_CLOEXEC 1 54 | #endif 55 | 56 | namespace tracy 57 | { 58 | 59 | /* Open a file for reading. */ 60 | 61 | int 62 | backtrace_open (const char *filename, backtrace_error_callback error_callback, 63 | void *data, int *does_not_exist) 64 | { 65 | int descriptor; 66 | 67 | if (does_not_exist != NULL) 68 | *does_not_exist = 0; 69 | 70 | descriptor = open (filename, (int) (O_RDONLY | O_BINARY | O_CLOEXEC)); 71 | if (descriptor < 0) 72 | { 73 | /* If DOES_NOT_EXIST is not NULL, then don't call ERROR_CALLBACK 74 | if the file does not exist. We treat lacking permission to 75 | open the file as the file not existing; this case arises when 76 | running the libgo syscall package tests as root. */ 77 | if (does_not_exist != NULL && (errno == ENOENT || errno == EACCES)) 78 | *does_not_exist = 1; 79 | else 80 | error_callback (data, filename, errno); 81 | return -1; 82 | } 83 | 84 | #ifdef HAVE_FCNTL 85 | /* Set FD_CLOEXEC just in case the kernel does not support 86 | O_CLOEXEC. It doesn't matter if this fails for some reason. 87 | FIXME: At some point it should be safe to only do this if 88 | O_CLOEXEC == 0. */ 89 | fcntl (descriptor, F_SETFD, FD_CLOEXEC); 90 | #endif 91 | 92 | return descriptor; 93 | } 94 | 95 | /* Close DESCRIPTOR. */ 96 | 97 | int 98 | backtrace_close (int descriptor, backtrace_error_callback error_callback, 99 | void *data) 100 | { 101 | if (close (descriptor) < 0) 102 | { 103 | error_callback (data, "close", errno); 104 | return 0; 105 | } 106 | return 1; 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /tracy-0.7.8/libbacktrace/sort.cpp: -------------------------------------------------------------------------------- 1 | /* sort.c -- Sort without allocating memory 2 | Copyright (C) 2012-2021 Free Software Foundation, Inc. 3 | Written by Ian Lance Taylor, Google. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | (1) Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | (2) Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | (3) The name of the author may not be used to 18 | endorse or promote products derived from this software without 19 | specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. */ 32 | 33 | #include "config.h" 34 | 35 | #include 36 | #include 37 | 38 | #include "backtrace.hpp" 39 | #include "internal.hpp" 40 | 41 | namespace tracy 42 | { 43 | 44 | /* The GNU glibc version of qsort allocates memory, which we must not 45 | do if we are invoked by a signal handler. So provide our own 46 | sort. */ 47 | 48 | static void 49 | swap (char *a, char *b, size_t size) 50 | { 51 | size_t i; 52 | 53 | for (i = 0; i < size; i++, a++, b++) 54 | { 55 | char t; 56 | 57 | t = *a; 58 | *a = *b; 59 | *b = t; 60 | } 61 | } 62 | 63 | void 64 | backtrace_qsort (void *basearg, size_t count, size_t size, 65 | int (*compar) (const void *, const void *)) 66 | { 67 | char *base = (char *) basearg; 68 | size_t i; 69 | size_t mid; 70 | 71 | tail_recurse: 72 | if (count < 2) 73 | return; 74 | 75 | /* The symbol table and DWARF tables, which is all we use this 76 | routine for, tend to be roughly sorted. Pick the middle element 77 | in the array as our pivot point, so that we are more likely to 78 | cut the array in half for each recursion step. */ 79 | swap (base, base + (count / 2) * size, size); 80 | 81 | mid = 0; 82 | for (i = 1; i < count; i++) 83 | { 84 | if ((*compar) (base, base + i * size) > 0) 85 | { 86 | ++mid; 87 | if (i != mid) 88 | swap (base + mid * size, base + i * size, size); 89 | } 90 | } 91 | 92 | if (mid > 0) 93 | swap (base, base + mid * size, size); 94 | 95 | /* Recurse with the smaller array, loop with the larger one. That 96 | ensures that our maximum stack depth is log count. */ 97 | if (2 * mid < count) 98 | { 99 | backtrace_qsort (base, mid, size, compar); 100 | base += (mid + 1) * size; 101 | count -= mid + 1; 102 | goto tail_recurse; 103 | } 104 | else 105 | { 106 | backtrace_qsort (base + (mid + 1) * size, count - (mid + 1), 107 | size, compar); 108 | count = mid; 109 | goto tail_recurse; 110 | } 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /tracy-0.7.8/libbacktrace/state.cpp: -------------------------------------------------------------------------------- 1 | /* state.c -- Create the backtrace state. 2 | Copyright (C) 2012-2021 Free Software Foundation, Inc. 3 | Written by Ian Lance Taylor, Google. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | (1) Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | (2) Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | 17 | (3) The name of the author may not be used to 18 | endorse or promote products derived from this software without 19 | specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. */ 32 | 33 | #include "config.h" 34 | 35 | #include 36 | #include 37 | 38 | #include "backtrace.hpp" 39 | #include "internal.hpp" 40 | 41 | namespace tracy 42 | { 43 | 44 | /* Create the backtrace state. This will then be passed to all the 45 | other routines. */ 46 | 47 | struct backtrace_state * 48 | backtrace_create_state (const char *filename, int threaded, 49 | backtrace_error_callback error_callback, 50 | void *data) 51 | { 52 | struct backtrace_state init_state; 53 | struct backtrace_state *state; 54 | 55 | #ifndef HAVE_SYNC_FUNCTIONS 56 | if (threaded) 57 | { 58 | error_callback (data, "backtrace library does not support threads", 0); 59 | return NULL; 60 | } 61 | #endif 62 | 63 | memset (&init_state, 0, sizeof init_state); 64 | init_state.filename = filename; 65 | init_state.threaded = threaded; 66 | 67 | state = ((struct backtrace_state *) 68 | backtrace_alloc (&init_state, sizeof *state, error_callback, data)); 69 | if (state == NULL) 70 | return NULL; 71 | *state = init_state; 72 | 73 | return state; 74 | } 75 | 76 | } 77 | --------------------------------------------------------------------------------