GodotProfiling.hpp 687 B

12345678910111213141516171819202122232425262728293031323334
  1. #ifndef GODOT_PROFILING_HPP
  2. #define GODOT_PROFILING_HPP
  3. #include "OS.hpp"
  4. namespace godot {
  5. class FunctionProfiling {
  6. char signature[1024];
  7. uint64_t ticks;
  8. public:
  9. FunctionProfiling(const char *p_function, const int p_line) {
  10. snprintf(signature, 1024, "::%d::%s", p_line, p_function);
  11. ticks = OS::get_singleton()->get_ticks_usec();
  12. }
  13. ~FunctionProfiling() {
  14. uint64_t t = OS::get_singleton()->get_ticks_usec() - ticks;
  15. if (t > 0) {
  16. Godot::gdnative_profiling_add_data(signature, t);
  17. }
  18. }
  19. };
  20. }
  21. #ifdef DEBUG_ENABLED
  22. #define GODOT_PROFILING_FUNCTION FunctionProfiling __function_profiling(__FUNCTION__, __LINE__);
  23. #else
  24. #define GODOT_PROFILING_FUNCTION
  25. #endif
  26. #endif