2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* performance.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2020-01-01 11:16:22 +01:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "performance.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
|
|
|
|
#include "core/message_queue.h"
|
|
|
|
#include "core/os/os.h"
|
2019-04-17 22:46:21 +02:00
|
|
|
#include "scene/main/node.h"
|
2017-06-27 03:58:03 +02:00
|
|
|
#include "scene/main/scene_tree.h"
|
2018-07-17 03:43:47 +02:00
|
|
|
#include "servers/audio_server.h"
|
2014-09-03 04:13:40 +02:00
|
|
|
#include "servers/physics_2d_server.h"
|
|
|
|
#include "servers/physics_server.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "servers/visual_server.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Performance *Performance::singleton = NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void Performance::_bind_methods() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_monitor", "monitor"), &Performance::get_monitor);
|
|
|
|
|
2017-08-20 17:45:01 +02:00
|
|
|
BIND_ENUM_CONSTANT(TIME_FPS);
|
|
|
|
BIND_ENUM_CONSTANT(TIME_PROCESS);
|
2017-09-30 16:19:07 +02:00
|
|
|
BIND_ENUM_CONSTANT(TIME_PHYSICS_PROCESS);
|
2017-08-20 17:45:01 +02:00
|
|
|
BIND_ENUM_CONSTANT(MEMORY_STATIC);
|
|
|
|
BIND_ENUM_CONSTANT(MEMORY_DYNAMIC);
|
|
|
|
BIND_ENUM_CONSTANT(MEMORY_STATIC_MAX);
|
|
|
|
BIND_ENUM_CONSTANT(MEMORY_DYNAMIC_MAX);
|
|
|
|
BIND_ENUM_CONSTANT(MEMORY_MESSAGE_BUFFER_MAX);
|
|
|
|
BIND_ENUM_CONSTANT(OBJECT_COUNT);
|
|
|
|
BIND_ENUM_CONSTANT(OBJECT_RESOURCE_COUNT);
|
|
|
|
BIND_ENUM_CONSTANT(OBJECT_NODE_COUNT);
|
2019-04-17 22:46:21 +02:00
|
|
|
BIND_ENUM_CONSTANT(OBJECT_ORPHAN_NODE_COUNT);
|
2017-08-20 17:45:01 +02:00
|
|
|
BIND_ENUM_CONSTANT(RENDER_OBJECTS_IN_FRAME);
|
|
|
|
BIND_ENUM_CONSTANT(RENDER_VERTICES_IN_FRAME);
|
|
|
|
BIND_ENUM_CONSTANT(RENDER_MATERIAL_CHANGES_IN_FRAME);
|
|
|
|
BIND_ENUM_CONSTANT(RENDER_SHADER_CHANGES_IN_FRAME);
|
|
|
|
BIND_ENUM_CONSTANT(RENDER_SURFACE_CHANGES_IN_FRAME);
|
|
|
|
BIND_ENUM_CONSTANT(RENDER_DRAW_CALLS_IN_FRAME);
|
2020-04-16 12:46:52 +02:00
|
|
|
BIND_ENUM_CONSTANT(RENDER_2D_ITEMS_IN_FRAME);
|
|
|
|
BIND_ENUM_CONSTANT(RENDER_2D_DRAW_CALLS_IN_FRAME);
|
2017-08-20 17:45:01 +02:00
|
|
|
BIND_ENUM_CONSTANT(RENDER_VIDEO_MEM_USED);
|
|
|
|
BIND_ENUM_CONSTANT(RENDER_TEXTURE_MEM_USED);
|
|
|
|
BIND_ENUM_CONSTANT(RENDER_VERTEX_MEM_USED);
|
2017-10-21 20:58:02 +02:00
|
|
|
BIND_ENUM_CONSTANT(RENDER_USAGE_VIDEO_MEM_TOTAL);
|
2017-08-20 17:45:01 +02:00
|
|
|
BIND_ENUM_CONSTANT(PHYSICS_2D_ACTIVE_OBJECTS);
|
|
|
|
BIND_ENUM_CONSTANT(PHYSICS_2D_COLLISION_PAIRS);
|
|
|
|
BIND_ENUM_CONSTANT(PHYSICS_2D_ISLAND_COUNT);
|
|
|
|
BIND_ENUM_CONSTANT(PHYSICS_3D_ACTIVE_OBJECTS);
|
|
|
|
BIND_ENUM_CONSTANT(PHYSICS_3D_COLLISION_PAIRS);
|
|
|
|
BIND_ENUM_CONSTANT(PHYSICS_3D_ISLAND_COUNT);
|
2018-07-17 03:43:47 +02:00
|
|
|
BIND_ENUM_CONSTANT(AUDIO_OUTPUT_LATENCY);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2017-08-20 17:45:01 +02:00
|
|
|
BIND_ENUM_CONSTANT(MONITOR_MAX);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2019-04-17 22:46:21 +02:00
|
|
|
float Performance::_get_node_count() const {
|
|
|
|
MainLoop *ml = OS::get_singleton()->get_main_loop();
|
|
|
|
SceneTree *sml = Object::cast_to<SceneTree>(ml);
|
|
|
|
if (!sml)
|
|
|
|
return 0;
|
|
|
|
return sml->get_node_count();
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
String Performance::get_monitor_name(Monitor p_monitor) const {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX_V(p_monitor, MONITOR_MAX, String());
|
|
|
|
static const char *names[MONITOR_MAX] = {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
"time/fps",
|
|
|
|
"time/process",
|
2017-09-30 16:19:07 +02:00
|
|
|
"time/physics_process",
|
2014-02-10 02:10:30 +01:00
|
|
|
"memory/static",
|
|
|
|
"memory/dynamic",
|
|
|
|
"memory/static_max",
|
|
|
|
"memory/dynamic_max",
|
|
|
|
"memory/msg_buf_max",
|
|
|
|
"object/objects",
|
|
|
|
"object/resources",
|
|
|
|
"object/nodes",
|
2019-04-17 22:46:21 +02:00
|
|
|
"object/orphan_nodes",
|
2014-02-10 02:10:30 +01:00
|
|
|
"raster/objects_drawn",
|
|
|
|
"raster/vertices_drawn",
|
|
|
|
"raster/mat_changes",
|
|
|
|
"raster/shader_changes",
|
|
|
|
"raster/surface_changes",
|
|
|
|
"raster/draw_calls",
|
2020-04-16 12:46:52 +02:00
|
|
|
"2d/items",
|
|
|
|
"2d/draw_calls",
|
2014-02-10 02:10:30 +01:00
|
|
|
"video/video_mem",
|
2017-09-28 23:40:01 +02:00
|
|
|
"video/texture_mem",
|
2014-02-10 02:10:30 +01:00
|
|
|
"video/vertex_mem",
|
2014-09-03 04:13:40 +02:00
|
|
|
"video/video_mem_max",
|
|
|
|
"physics_2d/active_objects",
|
|
|
|
"physics_2d/collision_pairs",
|
|
|
|
"physics_2d/islands",
|
|
|
|
"physics_3d/active_objects",
|
|
|
|
"physics_3d/collision_pairs",
|
|
|
|
"physics_3d/islands",
|
2018-07-17 03:43:47 +02:00
|
|
|
"audio/output_latency",
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return names[p_monitor];
|
|
|
|
}
|
|
|
|
|
|
|
|
float Performance::get_monitor(Monitor p_monitor) const {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_monitor) {
|
2017-01-13 16:51:14 +01:00
|
|
|
case TIME_FPS: return Engine::get_singleton()->get_frames_per_second();
|
2014-02-10 02:10:30 +01:00
|
|
|
case TIME_PROCESS: return _process_time;
|
2017-09-30 16:19:07 +02:00
|
|
|
case TIME_PHYSICS_PROCESS: return _physics_process_time;
|
2017-01-06 14:15:44 +01:00
|
|
|
case MEMORY_STATIC: return Memory::get_mem_usage();
|
2017-01-07 22:25:37 +01:00
|
|
|
case MEMORY_DYNAMIC: return MemoryPool::total_memory;
|
2017-07-25 02:29:28 +02:00
|
|
|
case MEMORY_STATIC_MAX: return Memory::get_mem_max_usage();
|
|
|
|
case MEMORY_DYNAMIC_MAX: return MemoryPool::max_memory;
|
2014-02-10 02:10:30 +01:00
|
|
|
case MEMORY_MESSAGE_BUFFER_MAX: return MessageQueue::get_singleton()->get_max_buffer_usage();
|
|
|
|
case OBJECT_COUNT: return ObjectDB::get_object_count();
|
|
|
|
case OBJECT_RESOURCE_COUNT: return ResourceCache::get_cached_resource_count();
|
2019-04-17 22:46:21 +02:00
|
|
|
case OBJECT_NODE_COUNT: return _get_node_count();
|
|
|
|
case OBJECT_ORPHAN_NODE_COUNT: return Node::orphan_node_count;
|
2014-02-10 02:10:30 +01:00
|
|
|
case RENDER_OBJECTS_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_OBJECTS_IN_FRAME);
|
|
|
|
case RENDER_VERTICES_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_VERTICES_IN_FRAME);
|
2017-01-14 18:03:38 +01:00
|
|
|
case RENDER_MATERIAL_CHANGES_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_MATERIAL_CHANGES_IN_FRAME);
|
|
|
|
case RENDER_SHADER_CHANGES_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_SHADER_CHANGES_IN_FRAME);
|
|
|
|
case RENDER_SURFACE_CHANGES_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_SURFACE_CHANGES_IN_FRAME);
|
2014-02-10 02:10:30 +01:00
|
|
|
case RENDER_DRAW_CALLS_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_DRAW_CALLS_IN_FRAME);
|
2020-04-16 12:46:52 +02:00
|
|
|
case RENDER_2D_ITEMS_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_2D_ITEMS_IN_FRAME);
|
|
|
|
case RENDER_2D_DRAW_CALLS_IN_FRAME: return VS::get_singleton()->get_render_info(VS::INFO_2D_DRAW_CALLS_IN_FRAME);
|
2014-02-10 02:10:30 +01:00
|
|
|
case RENDER_VIDEO_MEM_USED: return VS::get_singleton()->get_render_info(VS::INFO_VIDEO_MEM_USED);
|
|
|
|
case RENDER_TEXTURE_MEM_USED: return VS::get_singleton()->get_render_info(VS::INFO_TEXTURE_MEM_USED);
|
|
|
|
case RENDER_VERTEX_MEM_USED: return VS::get_singleton()->get_render_info(VS::INFO_VERTEX_MEM_USED);
|
|
|
|
case RENDER_USAGE_VIDEO_MEM_TOTAL: return VS::get_singleton()->get_render_info(VS::INFO_USAGE_VIDEO_MEM_TOTAL);
|
2014-09-03 04:13:40 +02:00
|
|
|
case PHYSICS_2D_ACTIVE_OBJECTS: return Physics2DServer::get_singleton()->get_process_info(Physics2DServer::INFO_ACTIVE_OBJECTS);
|
|
|
|
case PHYSICS_2D_COLLISION_PAIRS: return Physics2DServer::get_singleton()->get_process_info(Physics2DServer::INFO_COLLISION_PAIRS);
|
|
|
|
case PHYSICS_2D_ISLAND_COUNT: return Physics2DServer::get_singleton()->get_process_info(Physics2DServer::INFO_ISLAND_COUNT);
|
|
|
|
case PHYSICS_3D_ACTIVE_OBJECTS: return PhysicsServer::get_singleton()->get_process_info(PhysicsServer::INFO_ACTIVE_OBJECTS);
|
|
|
|
case PHYSICS_3D_COLLISION_PAIRS: return PhysicsServer::get_singleton()->get_process_info(PhysicsServer::INFO_COLLISION_PAIRS);
|
|
|
|
case PHYSICS_3D_ISLAND_COUNT: return PhysicsServer::get_singleton()->get_process_info(PhysicsServer::INFO_ISLAND_COUNT);
|
2018-07-17 03:43:47 +02:00
|
|
|
case AUDIO_OUTPUT_LATENCY: return AudioServer::get_singleton()->get_output_latency();
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2019-04-09 17:08:36 +02:00
|
|
|
default: {
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-23 08:59:04 +02:00
|
|
|
Performance::MonitorType Performance::get_monitor_type(Monitor p_monitor) const {
|
|
|
|
ERR_FAIL_INDEX_V(p_monitor, MONITOR_MAX, MONITOR_TYPE_QUANTITY);
|
|
|
|
// ugly
|
|
|
|
static const MonitorType types[MONITOR_MAX] = {
|
|
|
|
|
|
|
|
MONITOR_TYPE_QUANTITY,
|
|
|
|
MONITOR_TYPE_TIME,
|
|
|
|
MONITOR_TYPE_TIME,
|
|
|
|
MONITOR_TYPE_MEMORY,
|
|
|
|
MONITOR_TYPE_MEMORY,
|
|
|
|
MONITOR_TYPE_MEMORY,
|
|
|
|
MONITOR_TYPE_MEMORY,
|
|
|
|
MONITOR_TYPE_MEMORY,
|
|
|
|
MONITOR_TYPE_QUANTITY,
|
|
|
|
MONITOR_TYPE_QUANTITY,
|
|
|
|
MONITOR_TYPE_QUANTITY,
|
|
|
|
MONITOR_TYPE_QUANTITY,
|
|
|
|
MONITOR_TYPE_QUANTITY,
|
|
|
|
MONITOR_TYPE_QUANTITY,
|
|
|
|
MONITOR_TYPE_QUANTITY,
|
|
|
|
MONITOR_TYPE_QUANTITY,
|
|
|
|
MONITOR_TYPE_QUANTITY,
|
2019-04-22 15:13:37 +02:00
|
|
|
MONITOR_TYPE_QUANTITY,
|
2020-04-16 12:46:52 +02:00
|
|
|
MONITOR_TYPE_QUANTITY,
|
|
|
|
MONITOR_TYPE_QUANTITY,
|
2017-10-23 08:59:04 +02:00
|
|
|
MONITOR_TYPE_MEMORY,
|
|
|
|
MONITOR_TYPE_MEMORY,
|
|
|
|
MONITOR_TYPE_MEMORY,
|
|
|
|
MONITOR_TYPE_MEMORY,
|
|
|
|
MONITOR_TYPE_QUANTITY,
|
|
|
|
MONITOR_TYPE_QUANTITY,
|
|
|
|
MONITOR_TYPE_QUANTITY,
|
|
|
|
MONITOR_TYPE_QUANTITY,
|
|
|
|
MONITOR_TYPE_QUANTITY,
|
|
|
|
MONITOR_TYPE_QUANTITY,
|
2018-07-17 03:43:47 +02:00
|
|
|
MONITOR_TYPE_TIME,
|
2017-10-23 08:59:04 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
return types[p_monitor];
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void Performance::set_process_time(float p_pt) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_process_time = p_pt;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-09-30 16:19:07 +02:00
|
|
|
void Performance::set_physics_process_time(float p_pt) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-09-30 16:19:07 +02:00
|
|
|
_physics_process_time = p_pt;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Performance::Performance() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_process_time = 0;
|
2017-09-30 16:19:07 +02:00
|
|
|
_physics_process_time = 0;
|
2017-03-05 16:44:50 +01:00
|
|
|
singleton = this;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|