summaryrefslogtreecommitdiffstats
path: root/include/core/GodotProfiling.hpp
blob: 92b010ed44750e7aab3f573acae24a9a30949435 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#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);
		}
	}
};

} // namespace godot

#ifdef DEBUG_ENABLED
#define GODOT_PROFILING_FUNCTION FunctionProfiling __function_profiling(__FUNCTION__, __LINE__);
#else
#define GODOT_PROFILING_FUNCTION
#endif

#endif