Path: blob/master/servers/debugger/servers_debugger.h
10278 views
/**************************************************************************/1/* servers_debugger.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "servers/rendering_server.h"3334class ServersDebugger {35public:36// Memory usage37struct ResourceInfo {38String path;39String format;40String type;41RID id;42int vram = 0;43bool operator<(const ResourceInfo &p_img) const { return vram == p_img.vram ? id < p_img.id : vram > p_img.vram; }44};4546struct ResourceUsage {47List<ResourceInfo> infos;4849Array serialize();50bool deserialize(const Array &p_arr);51};5253// Script Profiler54struct ScriptFunctionSignature {55StringName name;56int id = -1;5758Array serialize();59bool deserialize(const Array &p_arr);60};6162struct ScriptFunctionInfo {63StringName name;64int sig_id = -1;65int call_count = 0;66double self_time = 0;67double total_time = 0;68double internal_time = 0;69};7071// Servers profiler72struct ServerFunctionInfo {73StringName name;74double time = 0;75};7677struct ServerInfo {78StringName name;79List<ServerFunctionInfo> functions;80};8182struct ServersProfilerFrame {83int frame_number = 0;84double frame_time = 0;85double process_time = 0;86double physics_time = 0;87double physics_frame_time = 0;88double script_time = 0;89List<ServerInfo> servers;90Vector<ScriptFunctionInfo> script_functions;9192Array serialize();93bool deserialize(const Array &p_arr);94};9596// Visual Profiler97struct VisualProfilerFrame {98uint64_t frame_number = 0;99Vector<RS::FrameProfileArea> areas;100101Array serialize();102bool deserialize(const Array &p_arr);103};104105private:106class ScriptsProfiler;107class ServersProfiler;108class VisualProfiler;109110double last_draw_time = 0.0;111Ref<ServersProfiler> servers_profiler;112Ref<VisualProfiler> visual_profiler;113114static ServersDebugger *singleton;115116static Error _capture(void *p_user, const String &p_cmd, const Array &p_data, bool &r_captured);117118void _send_resource_usage();119String _get_resource_type_from_path(const String &p_path);120121ServersDebugger();122123public:124static void initialize();125static void deinitialize();126127~ServersDebugger();128};129130131