|
| 1 | +/**************************************************************************/ |
| 2 | +/* profiling.h */ |
| 3 | +/**************************************************************************/ |
| 4 | +/* This file is part of: */ |
| 5 | +/* GODOT ENGINE */ |
| 6 | +/* https://godotengine.org */ |
| 7 | +/**************************************************************************/ |
| 8 | +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | +/* */ |
| 11 | +/* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | +/* a copy of this software and associated documentation files (the */ |
| 13 | +/* "Software"), to deal in the Software without restriction, including */ |
| 14 | +/* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | +/* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | +/* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | +/* the following conditions: */ |
| 18 | +/* */ |
| 19 | +/* The above copyright notice and this permission notice shall be */ |
| 20 | +/* included in all copies or substantial portions of the Software. */ |
| 21 | +/* */ |
| 22 | +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | +/**************************************************************************/ |
| 30 | + |
| 31 | +#pragma once |
| 32 | + |
| 33 | +#include "core/typedefs.h" |
| 34 | +#include "profiling.gen.h" |
| 35 | + |
| 36 | +#if defined(GODOT_USE_TRACY) |
| 37 | +// Use the tracy profiler. |
| 38 | + |
| 39 | +#define TRACY_ENABLE |
| 40 | +#include <tracy/Tracy.hpp> |
| 41 | + |
| 42 | +#ifndef TRACY_CALLSTACK |
| 43 | +#define TRACY_CALLSTACK 0 |
| 44 | +#endif |
| 45 | + |
| 46 | +// Define tracing macros. |
| 47 | +#define GodotProfileFrameMark FrameMark |
| 48 | +#define GodotProfileZone(m_zone_name) ZoneScopedN(m_zone_name) |
| 49 | +#define GodotProfileZoneGroupedFirst(m_group_name, m_zone_name) ZoneNamedN(__godot_tracy_zone_##m_group_name, m_zone_name, true) |
| 50 | +#define GodotProfileZoneGroupedEndEarly(m_group_name, m_zone_name) __godot_tracy_zone_##m_group_name.~ScopedZone(); |
| 51 | +#define GodotProfileZoneGrouped(m_group_name, m_zone_name) \ |
| 52 | + GodotProfileZoneGroupedEndEarly(m_group_name, m_zone_name); \ |
| 53 | + static constexpr tracy::SourceLocationData TracyConcat(__tracy_source_location, TracyLine){ m_zone_name, TracyFunction, TracyFile, (uint32_t)TracyLine, 0 }; \ |
| 54 | + new (&__godot_tracy_zone_##m_group_name) tracy::ScopedZone(&TracyConcat(__tracy_source_location, TracyLine), TRACY_CALLSTACK, true) |
| 55 | + |
| 56 | +void godot_init_profiler(); |
| 57 | + |
| 58 | +#elif defined(GODOT_USE_PERFETTO) |
| 59 | +// Use the perfetto profiler. |
| 60 | + |
| 61 | +#include <perfetto.h> |
| 62 | + |
| 63 | +PERFETTO_DEFINE_CATEGORIES( |
| 64 | + perfetto::Category("godot") |
| 65 | + .SetDescription("All Godot Events"), ); |
| 66 | + |
| 67 | +// See PERFETTO_INTERNAL_SCOPED_EVENT_FINALIZER |
| 68 | +struct PerfettoGroupedEventEnder { |
| 69 | + _FORCE_INLINE_ void _end_now() { |
| 70 | + TRACE_EVENT_END("godot"); |
| 71 | + } |
| 72 | + |
| 73 | + _FORCE_INLINE_ ~PerfettoGroupedEventEnder() { |
| 74 | + _end_now(); |
| 75 | + } |
| 76 | +}; |
| 77 | + |
| 78 | +#define GodotProfileFrameMark // TODO |
| 79 | +#define GodotProfileZone(m_zone_name) TRACE_EVENT("godot", m_zone_name); |
| 80 | +#define GodotProfileZoneGroupedFirst(m_group_name, m_zone_name) \ |
| 81 | + TRACE_EVENT_BEGIN("godot", m_zone_name); \ |
| 82 | + PerfettoGroupedEventEnder __godot_perfetto_zone_##m_group_name |
| 83 | +#define GodotProfileZoneGroupedEndEarly(m_group_name, m_zone_name) __godot_perfetto_zone_##m_group_name.~PerfettoGroupedEventEnder() |
| 84 | +#define GodotProfileZoneGrouped(m_group_name, m_zone_name) \ |
| 85 | + __godot_perfetto_zone_##m_group_name._end_now(); \ |
| 86 | + TRACE_EVENT_BEGIN("godot", m_zone_name); |
| 87 | + |
| 88 | +void godot_init_profiler(); |
| 89 | + |
| 90 | +#else |
| 91 | +// No profiling; all macros are stubs. |
| 92 | + |
| 93 | +void godot_init_profiler(); |
| 94 | + |
| 95 | +#define GodotProfileFrameMark |
| 96 | +#define GodotProfileZone(m_zone_name) |
| 97 | +#define GodotProfileZoneGroupedFirst(m_group_name, m_zone_name) |
| 98 | +#define GodotProfileZoneGroupedEndEarly(m_group_name, m_zone_name) |
| 99 | +#define GodotProfileZoneGrouped(m_group_name, m_zone_name) |
| 100 | + |
| 101 | +#endif |
0 commit comments