From bab94a5120754d4d69d9fdbb923b1d9ea1ea0d2e Mon Sep 17 00:00:00 2001 From: Gergely Kis Date: Mon, 5 Sep 2022 23:11:09 +0200 Subject: [PATCH] Integrate Perfetto with Godot-CPP This change adds an example on how to integrate Perfetto with Godot-CPP projects. --- SConstruct | 1 + test/SConstruct | 4 ++++ test/src/init.cpp | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/SConstruct b/SConstruct index ed85d6ea..473c09f6 100644 --- a/SConstruct +++ b/SConstruct @@ -179,6 +179,7 @@ opts.Add( ) opts.Add(BoolVariable("build_library", "Build the godot-cpp library.", True)) +opts.Add(PathVariable("perfetto", "Path to the perfetto include directory in the Godot Engine source", None, PathVariable.PathIsDir)) opts.Update(env) Help(opts.GenerateHelpText(env)) diff --git a/test/SConstruct b/test/SConstruct index 9bfd43dc..94b312c4 100644 --- a/test/SConstruct +++ b/test/SConstruct @@ -6,6 +6,10 @@ env = SConscript("../SConstruct") env.Append(CPPPATH=['src/']) sources = Glob('src/*.cpp') +if env["perfetto"]: + env.Append(CPPDEFINES=["ENABLE_PERFETTO"]) + env.Append(CPPPATH=[env["perfetto"]]) + library = env.SharedLibrary( "bin/libgdexample.{}.{}.{}{}".format( env["platform"], env["target"], env["arch_suffix"], env["SHLIBSUFFIX"] diff --git a/test/src/init.cpp b/test/src/init.cpp index 97149705..f739ff70 100644 --- a/test/src/init.cpp +++ b/test/src/init.cpp @@ -31,6 +31,8 @@ #include #include +#include "godot_profiler.h" + using namespace godot; class SimpleClass : public Reference { @@ -41,15 +43,18 @@ public: /** `_init` must exist as it is called by Godot. */ void _init() { + TRACE_EVENT("app_main", "SimpleClass::_init"); _name = String("SimpleClass"); _value = 0; } void test_void_method() { + TRACE_EVENT("app_main", "SimpleClass::test_void_method"); Godot::print("This is test"); } Variant method(Variant arg) { + TRACE_EVENT("app_main", "SimpleClass::method"); Variant ret; ret = arg; @@ -57,6 +62,7 @@ public: } static void _register_methods() { + TRACE_EVENT("app_main", "_register_methods"); register_method("method", &SimpleClass::method); /**