Path: blob/master/editor/debugger/editor_visual_profiler.h
9903 views
/**************************************************************************/1/* editor_visual_profiler.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 "scene/gui/box_container.h"33#include "scene/gui/button.h"34#include "scene/gui/check_box.h"35#include "scene/gui/label.h"36#include "scene/gui/option_button.h"37#include "scene/gui/spin_box.h"38#include "scene/gui/split_container.h"39#include "scene/gui/texture_rect.h"40#include "scene/gui/tree.h"4142class ImageTexture;4344class EditorVisualProfiler : public VBoxContainer {45GDCLASS(EditorVisualProfiler, VBoxContainer);4647public:48struct Metric {49bool valid = false;5051uint64_t frame_number = 0;5253struct Area {54String name;55Color color_cache;56StringName fullpath_cache;57float cpu_time = 0;58float gpu_time = 0;59};6061Vector<Area> areas;62};6364enum DisplayTimeMode {65DISPLAY_FRAME_TIME,66DISPLAY_FRAME_PERCENT,67};6869private:70Button *activate = nullptr;71Button *clear_button = nullptr;7273TextureRect *graph = nullptr;74Ref<ImageTexture> graph_texture;75Vector<uint8_t> graph_image;76Tree *variables = nullptr;77HSplitContainer *h_split = nullptr;78CheckBox *frame_relative = nullptr;79CheckBox *linked = nullptr;8081OptionButton *display_mode = nullptr;8283SpinBox *cursor_metric_edit = nullptr;8485Vector<Metric> frame_metrics;86int last_metric = -1;8788int hover_metric = -1;8990StringName selected_area;9192bool updating_frame = false;9394float graph_height_cpu = 1.0f;95float graph_height_gpu = 1.0f;9697float graph_limit = 1000.0f / 60;9899String cpu_name;100String gpu_name;101102bool seeking = false;103104Timer *frame_delay = nullptr;105Timer *plot_delay = nullptr;106107void _update_button_text();108109void _update_frame(bool p_focus_selected = false);110111void _activate_pressed();112void _clear_pressed();113void _autostart_toggled(bool p_toggled_on);114115String _get_time_as_text(float p_time);116117//void _make_metric_ptrs(Metric &m);118void _item_selected();119120void _update_plot();121122void _graph_tex_mouse_exit();123124void _graph_tex_draw();125void _graph_tex_input(const Ref<InputEvent> &p_ev);126127int _get_cursor_index() const;128129Color _get_color_from_signature(const StringName &p_signature) const;130131void _cursor_metric_changed(double);132133void _combo_changed(int);134135protected:136void _notification(int p_what);137static void _bind_methods();138139public:140void set_hardware_info(const String &p_cpu_name, const String &p_gpu_name);141void add_frame_metric(const Metric &p_metric);142void set_enabled(bool p_enable);143void set_profiling(bool p_profiling);144bool is_profiling();145bool is_seeking() { return seeking; }146void disable_seeking();147148void clear();149150Vector<Vector<String>> get_data_as_csv() const;151152EditorVisualProfiler();153};154155156