summaryrefslogtreecommitdiffstats
path: root/include/core
diff options
context:
space:
mode:
authorMarcelo Fernandez <marcelofg55@gmail.com>2018-08-20 12:18:12 -0300
committerMarcelo Fernandez <marcelofg55@gmail.com>2018-11-27 09:45:56 -0300
commit209dd56cb0241a9acda3d33dc59857ad7e5f3cdb (patch)
treeb1af89d309255e736fb6f210aeb585c2908b8487 /include/core
parentf4476351f00485e45a18d3613e41899388482dee (diff)
downloadredot-cpp-209dd56cb0241a9acda3d33dc59857ad7e5f3cdb.tar.gz
Profiling support
Diffstat (limited to 'include/core')
-rw-r--r--include/core/GodotGlobal.hpp2
-rw-r--r--include/core/GodotProfiling.hpp34
2 files changed, 36 insertions, 0 deletions
diff --git a/include/core/GodotGlobal.hpp b/include/core/GodotGlobal.hpp
index a1c62f2..71b3cf6 100644
--- a/include/core/GodotGlobal.hpp
+++ b/include/core/GodotGlobal.hpp
@@ -25,6 +25,8 @@ public:
static void nativescript_init(void *handle);
static void nativescript_terminate(void *handle);
+ static void gdnative_profiling_add_data(const char *p_signature, uint64_t p_time);
+
template <class... Args>
static void print(const String &fmt, Args... values) {
print(fmt.format(Array::make(values...)));
diff --git a/include/core/GodotProfiling.hpp b/include/core/GodotProfiling.hpp
new file mode 100644
index 0000000..0862d0b
--- /dev/null
+++ b/include/core/GodotProfiling.hpp
@@ -0,0 +1,34 @@
+#ifndef GODOT_PROFILING_HPP
+#define GODOT_PROFILING_HPP
+
+#include "OS.hpp"
+
+
+namespace godot {
+
+class FunctionProfiling {
+ char signature[1024];
+ uint64_t ticks;
+
+public:
+ FunctionProfiling(const char *p_function, const int p_line) {
+ snprintf(signature, 1024, "::%d::%s", p_line, p_function);
+ ticks = OS::get_singleton()->get_ticks_usec();
+ }
+ ~FunctionProfiling() {
+ uint64_t t = OS::get_singleton()->get_ticks_usec() - ticks;
+ if (t > 0) {
+ Godot::gdnative_profiling_add_data(signature, t);
+ }
+ }
+};
+
+}
+
+#ifdef DEBUG_ENABLED
+#define GODOT_PROFILING_FUNCTION FunctionProfiling __function_profiling(__FUNCTION__, __LINE__);
+#else
+#define GODOT_PROFILING_FUNCTION
+#endif
+
+#endif