:BeginProfile :EndProfile
This commit is contained in:
@@ -462,4 +462,12 @@ void CMD_OpenLogs() {
|
|||||||
|
|
||||||
void CMD_Errors() {
|
void CMD_Errors() {
|
||||||
CMD_OpenLogs();
|
CMD_OpenLogs();
|
||||||
} RegisterCommand(CMD_Errors, "", "Opens the text editor logs and clear error counter");
|
} RegisterCommand(CMD_Errors, "", "Opens the text editor logs and clear error counter");
|
||||||
|
|
||||||
|
void CMD_BeginProfile() {
|
||||||
|
BeginProfiler();
|
||||||
|
} RegisterCommand(CMD_BeginProfile, "", "Start gathering profile data");
|
||||||
|
|
||||||
|
void CMD_EndProfile() {
|
||||||
|
EndProfiler();
|
||||||
|
} RegisterCommand(CMD_EndProfile, "", "Stop gathering profile data and write to disk");
|
||||||
@@ -365,24 +365,30 @@ SPALL_FN bool spall_buffer_name_process(SpallProfile *ctx, SpallBuffer *wb, cons
|
|||||||
static SpallProfile spall_ctx;
|
static SpallProfile spall_ctx;
|
||||||
static SpallBuffer spall_buffer;
|
static SpallBuffer spall_buffer;
|
||||||
uint64_t GetTimeNanos(void);
|
uint64_t GetTimeNanos(void);
|
||||||
|
bool ActivelyProfiling = false;
|
||||||
|
|
||||||
void BeginProfiler() {
|
void BeginProfiler() {
|
||||||
spall_init_file("te.spall", 1, &spall_ctx);
|
Scratch scratch;
|
||||||
|
String filename = Format(scratch, "te%llu.spall", (unsigned long long)GetTimeNanos());
|
||||||
|
spall_init_file(filename.data, 1, &spall_ctx);
|
||||||
|
|
||||||
int buffer_size = 1 * 1024 * 1024;
|
int buffer_size = 1 * 1024 * 1024;
|
||||||
unsigned char *buffer = (unsigned char *)malloc(buffer_size);
|
unsigned char *buffer = (unsigned char *)malloc(buffer_size);
|
||||||
spall_buffer = {buffer, (size_t)buffer_size};
|
spall_buffer = {buffer, (size_t)buffer_size};
|
||||||
|
|
||||||
spall_buffer_init(&spall_ctx, &spall_buffer);
|
spall_buffer_init(&spall_ctx, &spall_buffer);
|
||||||
|
ActivelyProfiling = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndProfiler() {
|
void EndProfiler() {
|
||||||
spall_buffer_quit(&spall_ctx, &spall_buffer);
|
spall_buffer_quit(&spall_ctx, &spall_buffer);
|
||||||
free(spall_buffer.data);
|
free(spall_buffer.data);
|
||||||
spall_quit(&spall_ctx);
|
spall_quit(&spall_ctx);
|
||||||
|
ActivelyProfiling = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _BeginProfileScope(const char *name, int len) {
|
void _BeginProfileScope(const char *name, int len) {
|
||||||
|
if (!ActivelyProfiling) return;
|
||||||
spall_buffer_begin(&spall_ctx, &spall_buffer,
|
spall_buffer_begin(&spall_ctx, &spall_buffer,
|
||||||
name, // name of your name
|
name, // name of your name
|
||||||
len, // name len minus the null terminator
|
len, // name len minus the null terminator
|
||||||
@@ -392,6 +398,7 @@ void _BeginProfileScope(const char *name, int len) {
|
|||||||
#define BeginProfileScope(name) _BeginProfileScope(#name, sizeof(#name) - 1)
|
#define BeginProfileScope(name) _BeginProfileScope(#name, sizeof(#name) - 1)
|
||||||
|
|
||||||
void EndProfileScope() {
|
void EndProfileScope() {
|
||||||
|
if (!ActivelyProfiling) return;
|
||||||
spall_buffer_end(&spall_ctx, &spall_buffer,
|
spall_buffer_end(&spall_ctx, &spall_buffer,
|
||||||
GetTimeNanos() // timestamp in microseconds -- end of your timing block
|
GetTimeNanos() // timestamp in microseconds -- end of your timing block
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -683,6 +683,7 @@ void Update(Event event) {
|
|||||||
// We update it here despite the name to make it sure that all the possible changes are
|
// We update it here despite the name to make it sure that all the possible changes are
|
||||||
// included albeit with delayed response. If we did this at the beginning of the frame
|
// included albeit with delayed response. If we did this at the beginning of the frame
|
||||||
// and the DebugWindowUpdated we wouldnt get to know that in the OnCommand.
|
// and the DebugWindowUpdated we wouldnt get to know that in the OnCommand.
|
||||||
|
// @todo: this is slow, we don't want to loop through every buffer on every frame :(
|
||||||
For (Buffers) {
|
For (Buffers) {
|
||||||
it->begin_frame_change_id = it->change_id;
|
it->begin_frame_change_id = it->change_id;
|
||||||
}
|
}
|
||||||
@@ -772,6 +773,7 @@ void Update(Event event) {
|
|||||||
// Reopen modified buffers
|
// Reopen modified buffers
|
||||||
// @todo: This is O(n) so could see slow downs with number of buffers, likely need OS help to make it more
|
// @todo: This is O(n) so could see slow downs with number of buffers, likely need OS help to make it more
|
||||||
// efficient
|
// efficient
|
||||||
|
// @todo: maybe instead go through windows and only reopen active buffers
|
||||||
For(Buffers) {
|
For(Buffers) {
|
||||||
if (it->file_mod_time) {
|
if (it->file_mod_time) {
|
||||||
int64_t new_file_mod_time = GetFileModTime(it->name);
|
int64_t new_file_mod_time = GetFileModTime(it->name);
|
||||||
@@ -868,7 +870,6 @@ int main(int argc, char **argv)
|
|||||||
char **argv = __argv;
|
char **argv = __argv;
|
||||||
AttachConsole(ATTACH_PARENT_PROCESS);
|
AttachConsole(ATTACH_PARENT_PROCESS);
|
||||||
#endif
|
#endif
|
||||||
BeginProfiler();
|
|
||||||
|
|
||||||
if (1) {
|
if (1) {
|
||||||
RunArenaTest();
|
RunArenaTest();
|
||||||
@@ -1067,7 +1068,5 @@ int main(int argc, char **argv)
|
|||||||
SDL_DestroyWindow(SDLWindow);
|
SDL_DestroyWindow(SDLWindow);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
||||||
EndProfiler();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user