/**************************************************************************/1/* engine_profiler.cpp */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#include "engine_profiler.h"3132#include "core/debugger/engine_debugger.h"3334void EngineProfiler::_bind_methods() {35GDVIRTUAL_BIND(_toggle, "enable", "options");36GDVIRTUAL_BIND(_add_frame, "data");37GDVIRTUAL_BIND(_tick, "frame_time", "process_time", "physics_time", "physics_frame_time");38}3940void EngineProfiler::toggle(bool p_enable, const Array &p_array) {41GDVIRTUAL_CALL(_toggle, p_enable, p_array);42}4344void EngineProfiler::add(const Array &p_data) {45GDVIRTUAL_CALL(_add_frame, p_data);46}4748void EngineProfiler::tick(double p_frame_time, double p_process_time, double p_physics_time, double p_physics_frame_time) {49GDVIRTUAL_CALL(_tick, p_frame_time, p_process_time, p_physics_time, p_physics_frame_time);50}5152Error EngineProfiler::bind(const String &p_name) {53ERR_FAIL_COND_V(is_bound(), ERR_ALREADY_IN_USE);54EngineDebugger::Profiler prof(55this,56[](void *p_user, bool p_enable, const Array &p_opts) {57static_cast<EngineProfiler *>(p_user)->toggle(p_enable, p_opts);58},59[](void *p_user, const Array &p_data) {60static_cast<EngineProfiler *>(p_user)->add(p_data);61},62[](void *p_user, double p_frame_time, double p_process_time, double p_physics_time, double p_physics_frame_time) {63static_cast<EngineProfiler *>(p_user)->tick(p_frame_time, p_process_time, p_physics_time, p_physics_frame_time);64});65registration = p_name;66EngineDebugger::register_profiler(p_name, prof);67return OK;68}6970Error EngineProfiler::unbind() {71ERR_FAIL_COND_V(!is_bound(), ERR_UNCONFIGURED);72EngineDebugger::unregister_profiler(registration);73registration.clear();74return OK;75}7677EngineProfiler::~EngineProfiler() {78if (is_bound()) {79unbind();80}81}828384