Compare commits
6 Commits
5e84e270bc
...
0360a2da35
Author | SHA1 | Date | |
---|---|---|---|
0360a2da35 | |||
43ec97378c | |||
e17ca4d3d2 | |||
6b9a7ab8a5 | |||
a118afaffb | |||
f11d4481a2 |
14
haversine_02/.vscode/launch.json
vendored
14
haversine_02/.vscode/launch.json
vendored
@ -5,7 +5,7 @@
|
|||||||
"type": "cppdbg",
|
"type": "cppdbg",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
"program": "${workspaceFolder}/main",
|
"program": "${workspaceFolder}/genhavr",
|
||||||
"args": [
|
"args": [
|
||||||
"--cluster",
|
"--cluster",
|
||||||
"10"
|
"10"
|
||||||
@ -16,10 +16,20 @@
|
|||||||
"type": "cppdbg",
|
"type": "cppdbg",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
"program": "${workspaceFolder}/main",
|
"program": "${workspaceFolder}/genhavr",
|
||||||
"args": [
|
"args": [
|
||||||
"10"
|
"10"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Debug processor",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"program": "${workspaceFolder}/prochavr",
|
||||||
|
"args": [
|
||||||
|
"${workspaceFolder}/pairs.json"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -51,7 +51,7 @@ PROF_BUILD_DIR=prof_build
|
|||||||
|
|
||||||
# PROCESSOR
|
# PROCESSOR
|
||||||
JSONSRC="../src/json/*.c"
|
JSONSRC="../src/json/*.c"
|
||||||
JSONFLAGS="-c"
|
JSONFLAGS="-c "
|
||||||
JSON_BUILD_DIR=json_build
|
JSON_BUILD_DIR=json_build
|
||||||
|
|
||||||
PROCSRC="./$JSON_BUILD_DIR/*.o \
|
PROCSRC="./$JSON_BUILD_DIR/*.o \
|
||||||
@ -62,6 +62,7 @@ PROCSRC="./$JSON_BUILD_DIR/*.o \
|
|||||||
PROCOUT=prochavr
|
PROCOUT=prochavr
|
||||||
|
|
||||||
if [[ $ENABLE_PROFILING == true ]]; then
|
if [[ $ENABLE_PROFILING == true ]]; then
|
||||||
|
JSONFLAGS+="-DENABLE_PROFILING"
|
||||||
PROCSRC+="./$PROF_BUILD_DIR/*.o"
|
PROCSRC+="./$PROF_BUILD_DIR/*.o"
|
||||||
PROCFLAGS="-DENABLE_PROFILING"
|
PROCFLAGS="-DENABLE_PROFILING"
|
||||||
|
|
||||||
|
22
haversine_02/include/profiler/ids.h
Normal file
22
haversine_02/include/profiler/ids.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef PROFILER_IDS_H
|
||||||
|
#define PROFILER_IDS_H
|
||||||
|
|
||||||
|
enum profiler_ids {
|
||||||
|
PROFILER_ID_CLI_PARSE,
|
||||||
|
PROFILER_ID_JSON_PARSE,
|
||||||
|
PROFILER_ID_READ_JSON_FILE,
|
||||||
|
PROFILER_ID_PARSER_SETUP,
|
||||||
|
PROFILER_ID_LEX_GET_TOKEN,
|
||||||
|
PROFILER_ID_PARSE_TOKEN,
|
||||||
|
PROFILER_ID_PARSER_TEAR_DOWN,
|
||||||
|
PROFILER_ID_LOAD_JSON_PAIRS,
|
||||||
|
PROFILER_ID_READ_BINARY,
|
||||||
|
PROFILER_ID_HAVERSINE_SUM,
|
||||||
|
PROFILER_ID_HAVERSINE_DISTANCE,
|
||||||
|
PROFILER_ID_HAVERSINE_AVG,
|
||||||
|
PROFILER_ID_TEAR_DOWN,
|
||||||
|
|
||||||
|
COUNT_PROFILER_IDS,
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // !PROFILER_IDS_H
|
@ -8,12 +8,12 @@
|
|||||||
#endif // !MAX_PROFILE_SAMPLES
|
#endif // !MAX_PROFILE_SAMPLES
|
||||||
|
|
||||||
#ifdef ENABLE_PROFILING
|
#ifdef ENABLE_PROFILING
|
||||||
#define PROFILE_START profile_start()
|
#define PROFILE_START(COUNT) profile_start(COUNT)
|
||||||
#define PROFILE_END profile_end()
|
#define PROFILE_END profile_end()
|
||||||
#define SAMPLE_START(ID, TITLE) profiler_sample_t ID = sample_start(TITLE)
|
#define SAMPLE_START(ID, TITLE) sample_start(ID, TITLE)
|
||||||
#define SAMPLE_END(ID) sample_end(&ID)
|
#define SAMPLE_END(ID) sample_end(ID)
|
||||||
#else
|
#else
|
||||||
#define PROFILE_START
|
#define PROFILE_START(COUNT)
|
||||||
#define PROFILE_END
|
#define PROFILE_END
|
||||||
#define SAMPLE_START(ID, TITLE)
|
#define SAMPLE_START(ID, TITLE)
|
||||||
#define SAMPLE_END(ID)
|
#define SAMPLE_END(ID)
|
||||||
@ -23,11 +23,16 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct sample profiler_sample_t;
|
||||||
|
|
||||||
|
struct sample {
|
||||||
const char *title;
|
const char *title;
|
||||||
u64 start;
|
u64 start;
|
||||||
u64 end;
|
u64 duration;
|
||||||
} profiler_sample_t;
|
u64 children_duration;
|
||||||
|
u64 hit_count;
|
||||||
|
profiler_sample_t *parent;
|
||||||
|
};
|
||||||
|
|
||||||
u64 get_os_frequency();
|
u64 get_os_frequency();
|
||||||
|
|
||||||
@ -40,11 +45,11 @@ u64 read_cpu_timer(void);
|
|||||||
// CPU frequency in hz/sec
|
// CPU frequency in hz/sec
|
||||||
u64 get_cpu_freq(u64 milliseconds);
|
u64 get_cpu_freq(u64 milliseconds);
|
||||||
|
|
||||||
void profile_start();
|
void profile_start(u64 count);
|
||||||
void profile_end();
|
void profile_end();
|
||||||
|
|
||||||
profiler_sample_t sample_start(const char *title);
|
void sample_start(u64 id, const char *title);
|
||||||
void sample_end(profiler_sample_t *sample);
|
void sample_end(u64 id);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,10 @@ dstr_t *dstr_with_capacity(u64 capacity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dstr_t *dstr_from_string(const char *str) {
|
dstr_t *dstr_from_string(const char *str) {
|
||||||
|
if (!str) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
u64 length = strlen(str);
|
u64 length = strlen(str);
|
||||||
|
|
||||||
u64 capacity = length * CAPACITY_SCALAR;
|
u64 capacity = length * CAPACITY_SCALAR;
|
||||||
@ -46,7 +50,7 @@ dstr_t *dstr_from_string(const char *str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void dstr_update(dstr_t **dst, const char *src) {
|
void dstr_update(dstr_t **dst, const char *src) {
|
||||||
if (!(*dst)) {
|
if (!dst || !(*dst)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +82,7 @@ void dstr_update(dstr_t **dst, const char *src) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void dstr_free(dstr_t **str) {
|
void dstr_free(dstr_t **str) {
|
||||||
if (!(*str)) {
|
if (!str || !(*str)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +91,7 @@ void dstr_free(dstr_t **str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void dstr_concat(dstr_t **dst, const char *src) {
|
void dstr_concat(dstr_t **dst, const char *src) {
|
||||||
if (!(*dst)) {
|
if (!dst || !(*dst)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +113,7 @@ void dstr_concat(dstr_t **dst, const char *src) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void dstr_append(dstr_t **dst, char c) {
|
void dstr_append(dstr_t **dst, char c) {
|
||||||
if (!(*dst)) {
|
if (!dst || !(*dst)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,6 +129,10 @@ void dstr_append(dstr_t **dst, char c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void dstr_resize(dstr_t **str) {
|
void dstr_resize(dstr_t **str) {
|
||||||
|
if (!str || !(*str)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
u64 capacity = (*str)->size;
|
u64 capacity = (*str)->size;
|
||||||
|
|
||||||
dstr_t *tmp = (dstr_t *)realloc(*str, sizeof(dstr_t) + capacity + 1);
|
dstr_t *tmp = (dstr_t *)realloc(*str, sizeof(dstr_t) + capacity + 1);
|
||||||
|
@ -131,8 +131,16 @@ void free_json(jentity_t **entity) {
|
|||||||
dstr_free(&(entt_ptr->pair.key));
|
dstr_free(&(entt_ptr->pair.key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (value->type) {
|
switch (value->type) {
|
||||||
case JVAL_COLLECTION:
|
case JVAL_COLLECTION:
|
||||||
|
if (!(value->collection)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (value->collection->begin) {
|
if (value->collection->begin) {
|
||||||
free_json(&(value->collection->begin));
|
free_json(&(value->collection->begin));
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "json/parser.h"
|
#include "json/parser.h"
|
||||||
#include "aliases.h"
|
#include "aliases.h"
|
||||||
|
#include "profiler/ids.h"
|
||||||
|
#include "profiler/timer.h"
|
||||||
#include "json/dstring.h"
|
#include "json/dstring.h"
|
||||||
#include "json/json_entities.h"
|
#include "json/json_entities.h"
|
||||||
#include "json/lexer.h"
|
#include "json/lexer.h"
|
||||||
@ -21,6 +23,8 @@ INTERNAL jentity_t *add_value(parser_t *parser);
|
|||||||
INTERNAL void add_collection(parser_t *parser);
|
INTERNAL void add_collection(parser_t *parser);
|
||||||
|
|
||||||
jentity_t *load_json(const char *filepath) {
|
jentity_t *load_json(const char *filepath) {
|
||||||
|
SAMPLE_START(PROFILER_ID_READ_JSON_FILE, "READ JSON FILE");
|
||||||
|
|
||||||
FILE *fp = fopen(filepath, "r");
|
FILE *fp = fopen(filepath, "r");
|
||||||
|
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
@ -40,6 +44,10 @@ jentity_t *load_json(const char *filepath) {
|
|||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
|
SAMPLE_END(PROFILER_ID_READ_JSON_FILE);
|
||||||
|
|
||||||
|
SAMPLE_START(PROFILER_ID_PARSER_SETUP, "JSON PARSER SETUP");
|
||||||
|
|
||||||
lexer_t *lexer = NULL;
|
lexer_t *lexer = NULL;
|
||||||
parser_t *parser = NULL;
|
parser_t *parser = NULL;
|
||||||
|
|
||||||
@ -55,15 +63,23 @@ jentity_t *load_json(const char *filepath) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SAMPLE_END(PROFILER_ID_PARSER_SETUP);
|
||||||
|
|
||||||
|
SAMPLE_START(PROFILER_ID_LEX_GET_TOKEN, "GET NEXT TOKEN");
|
||||||
lex_result_t result = get_next_token(lexer, json);
|
lex_result_t result = get_next_token(lexer, json);
|
||||||
|
SAMPLE_END(PROFILER_ID_LEX_GET_TOKEN);
|
||||||
|
|
||||||
if (result.error.errno) {
|
if (result.error.errno) {
|
||||||
printf("%s\n", result.error.msg);
|
printf("%s\n", result.error.msg);
|
||||||
} else {
|
} else {
|
||||||
while (result.token.type != TK_NO_TOKEN) {
|
while (result.token.type != TK_NO_TOKEN) {
|
||||||
|
SAMPLE_START(PROFILER_ID_PARSE_TOKEN, "PARSE TOKEN");
|
||||||
parse_token(parser, result.token);
|
parse_token(parser, result.token);
|
||||||
|
SAMPLE_END(PROFILER_ID_PARSE_TOKEN);
|
||||||
|
|
||||||
|
SAMPLE_START(PROFILER_ID_LEX_GET_TOKEN, "GET NEXT TOKEN");
|
||||||
result = get_next_token(lexer, NULL);
|
result = get_next_token(lexer, NULL);
|
||||||
|
SAMPLE_END(PROFILER_ID_LEX_GET_TOKEN);
|
||||||
|
|
||||||
if (result.error.errno) {
|
if (result.error.errno) {
|
||||||
printf("%s\n", result.error.msg);
|
printf("%s\n", result.error.msg);
|
||||||
@ -74,10 +90,14 @@ jentity_t *load_json(const char *filepath) {
|
|||||||
|
|
||||||
jentity_t *root = parser->root;
|
jentity_t *root = parser->root;
|
||||||
|
|
||||||
|
SAMPLE_START(PROFILER_ID_PARSER_TEAR_DOWN, "PARSER TEAR DOWN");
|
||||||
|
|
||||||
parser_free(&parser);
|
parser_free(&parser);
|
||||||
lexer_free(&lexer);
|
lexer_free(&lexer);
|
||||||
free(json);
|
free(json);
|
||||||
|
|
||||||
|
SAMPLE_END(PROFILER_ID_PARSER_TEAR_DOWN);
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "haversine.h"
|
#include "haversine.h"
|
||||||
#include "point_types.h"
|
#include "point_types.h"
|
||||||
#include "processor/proc_argparser.h"
|
#include "processor/proc_argparser.h"
|
||||||
|
#include "profiler/ids.h"
|
||||||
#include "profiler/timer.h"
|
#include "profiler/timer.h"
|
||||||
#include "json/dstring.h"
|
#include "json/dstring.h"
|
||||||
#include "json/json_entities.h"
|
#include "json/json_entities.h"
|
||||||
@ -14,21 +15,21 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
PROFILE_START;
|
PROFILE_START(COUNT_PROFILER_IDS);
|
||||||
|
|
||||||
SAMPLE_START(cli_parse, "CLI PARSING");
|
SAMPLE_START(PROFILER_ID_CLI_PARSE, "CLI PARSING");
|
||||||
ProcessorArgs args = parse_args(argc, argv);
|
ProcessorArgs args = parse_args(argc, argv);
|
||||||
SAMPLE_END(cli_parse);
|
SAMPLE_END(PROFILER_ID_CLI_PARSE);
|
||||||
|
|
||||||
SAMPLE_START(json_parse, "JSON PARSING");
|
SAMPLE_START(PROFILER_ID_JSON_PARSE, "JSON PARSING");
|
||||||
|
|
||||||
jentity_t *root = load_json(args.filepath);
|
jentity_t *root = load_json(args.filepath);
|
||||||
|
|
||||||
assert(root->type == JENTITY_SINGLE && root->value.type == JVAL_COLLECTION);
|
assert(root->type == JENTITY_SINGLE && root->value.type == JVAL_COLLECTION);
|
||||||
|
|
||||||
SAMPLE_END(json_parse);
|
SAMPLE_END(PROFILER_ID_JSON_PARSE);
|
||||||
|
|
||||||
SAMPLE_START(load_pairs_json, "LOAD JSON PAIRS");
|
SAMPLE_START(PROFILER_ID_LOAD_JSON_PAIRS, "LOAD JSON PAIRS");
|
||||||
|
|
||||||
jentity_t *pairs = root->value.collection->begin;
|
jentity_t *pairs = root->value.collection->begin;
|
||||||
|
|
||||||
@ -61,9 +62,9 @@ int main(int argc, char *argv[]) {
|
|||||||
point_pairs[index++] = p;
|
point_pairs[index++] = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
SAMPLE_END(load_pairs_json);
|
SAMPLE_END(PROFILER_ID_LOAD_JSON_PAIRS);
|
||||||
|
|
||||||
SAMPLE_START(binary_file_read, "BINARY READ");
|
SAMPLE_START(PROFILER_ID_READ_BINARY, "BINARY READ");
|
||||||
|
|
||||||
const char *filename = "count_and_distances";
|
const char *filename = "count_and_distances";
|
||||||
|
|
||||||
@ -75,15 +76,17 @@ int main(int argc, char *argv[]) {
|
|||||||
fseek(fp, sizeof(u64), SEEK_SET);
|
fseek(fp, sizeof(u64), SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
SAMPLE_END(binary_file_read);
|
SAMPLE_END(PROFILER_ID_READ_BINARY);
|
||||||
|
|
||||||
SAMPLE_START(haversine_sum, "HAVERSINE SUM");
|
SAMPLE_START(PROFILER_ID_HAVERSINE_SUM, "HAVERSINE SUM");
|
||||||
|
|
||||||
f64 sum = 0.0;
|
f64 sum = 0.0;
|
||||||
f64 distance = 0.0;
|
f64 distance = 0.0;
|
||||||
f64 saved_distance = 0.0;
|
f64 saved_distance = 0.0;
|
||||||
for (u64 i = 0; i < pair_count; ++i) {
|
for (u64 i = 0; i < pair_count; ++i) {
|
||||||
|
SAMPLE_START(PROFILER_ID_HAVERSINE_DISTANCE, "HAVERSINE DISTANCE");
|
||||||
distance = haversine_of_degrees(point_pairs[i], EARTH_RADIUS_KM);
|
distance = haversine_of_degrees(point_pairs[i], EARTH_RADIUS_KM);
|
||||||
|
SAMPLE_END(PROFILER_ID_HAVERSINE_DISTANCE);
|
||||||
|
|
||||||
if (fp) {
|
if (fp) {
|
||||||
fread(&saved_distance, sizeof(f64), 1, fp);
|
fread(&saved_distance, sizeof(f64), 1, fp);
|
||||||
@ -97,13 +100,13 @@ int main(int argc, char *argv[]) {
|
|||||||
sum += distance;
|
sum += distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
SAMPLE_END(haversine_sum);
|
SAMPLE_END(PROFILER_ID_HAVERSINE_SUM);
|
||||||
|
|
||||||
SAMPLE_START(haversine_average, "HAVERSINE AVERAGE");
|
SAMPLE_START(PROFILER_ID_HAVERSINE_AVG, "HAVERSINE AVERAGE");
|
||||||
printf("\nAVERAGE DISTANCE: %f\n", sum / pair_count);
|
printf("\nAVERAGE DISTANCE: %f\n", sum / pair_count);
|
||||||
SAMPLE_END(haversine_average);
|
SAMPLE_END(PROFILER_ID_HAVERSINE_AVG);
|
||||||
|
|
||||||
SAMPLE_START(tear_down, "TEAR DOWN");
|
SAMPLE_START(PROFILER_ID_TEAR_DOWN, "TEAR DOWN");
|
||||||
|
|
||||||
if (fp) {
|
if (fp) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@ -111,7 +114,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
free(point_pairs);
|
free(point_pairs);
|
||||||
|
|
||||||
SAMPLE_END(tear_down);
|
SAMPLE_END(PROFILER_ID_TEAR_DOWN);
|
||||||
|
|
||||||
PROFILE_END;
|
PROFILE_END;
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ typedef struct {
|
|||||||
u64 start;
|
u64 start;
|
||||||
u64 end;
|
u64 end;
|
||||||
u64 max_title_length;
|
u64 max_title_length;
|
||||||
|
profiler_sample_t *active;
|
||||||
} profiler_t;
|
} profiler_t;
|
||||||
|
|
||||||
INTERNAL profiler_t profiler = {0};
|
INTERNAL profiler_t profiler = {0};
|
||||||
@ -58,10 +59,11 @@ u64 get_cpu_freq(u64 milliseconds) {
|
|||||||
return cpu_freq;
|
return cpu_freq;
|
||||||
}
|
}
|
||||||
|
|
||||||
void profile_start() {
|
void profile_start(u64 count) {
|
||||||
profiler.cpu_freq = get_cpu_freq(500);
|
profiler.cpu_freq = get_cpu_freq(500);
|
||||||
profiler.start = read_cpu_timer();
|
profiler.start = read_cpu_timer();
|
||||||
profiler.max_title_length = 0;
|
profiler.max_title_length = 0;
|
||||||
|
profiler.size = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void profile_end() {
|
void profile_end() {
|
||||||
@ -71,11 +73,16 @@ void profile_end() {
|
|||||||
|
|
||||||
profiler.end = read_cpu_timer();
|
profiler.end = read_cpu_timer();
|
||||||
|
|
||||||
u64 total = profiler.end - profiler.start;
|
u64 total = 0;
|
||||||
|
|
||||||
|
if (profiler.end >= profiler.start) {
|
||||||
|
total = profiler.end - profiler.start;
|
||||||
|
}
|
||||||
|
|
||||||
u16 time_precision = 16;
|
u16 time_precision = 16;
|
||||||
u16 time_char_count = 20;
|
u16 time_char_count = 20;
|
||||||
u16 duration_char_count = 22;
|
u16 duration_char_count = 22;
|
||||||
|
u16 hits_char_count = 10;
|
||||||
u16 percentage_precision = 8;
|
u16 percentage_precision = 8;
|
||||||
u16 percentage_char_count = 12;
|
u16 percentage_char_count = 12;
|
||||||
|
|
||||||
@ -94,35 +101,85 @@ void profile_end() {
|
|||||||
for (u64 i = 0; i < profiler.size; ++i) {
|
for (u64 i = 0; i < profiler.size; ++i) {
|
||||||
sample = &(profiler.samples[i]);
|
sample = &(profiler.samples[i]);
|
||||||
|
|
||||||
u64 duration = sample->end - sample->start;
|
if (sample->hit_count == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
printf("%*s: %*lld (%*.*f %%)\n", (i32)profiler.max_title_length,
|
u64 duration = 0;
|
||||||
sample->title, duration_char_count, (unsigned long long)duration,
|
|
||||||
percentage_char_count, percentage_precision,
|
if (sample->duration >= sample->children_duration) {
|
||||||
(f64)duration / total * 100.0);
|
duration = sample->duration - sample->children_duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%*s (hits: %*lld): %*lld (%*.*f %%", (i32)profiler.max_title_length,
|
||||||
|
sample->title, hits_char_count,
|
||||||
|
(unsigned long long)sample->hit_count, duration_char_count,
|
||||||
|
(unsigned long long)duration, percentage_char_count,
|
||||||
|
percentage_precision, (f64)duration / total * 100.0);
|
||||||
|
|
||||||
|
if (sample->children_duration > 0) {
|
||||||
|
printf(", w/ children: %*.*f %%", percentage_char_count,
|
||||||
|
percentage_precision, (f64)sample->duration / total * 100.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(")\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
profiler_sample_t sample_start(const char *title) {
|
void sample_start(u64 id, const char *title) {
|
||||||
return (profiler_sample_t){
|
if (id >= MAX_PROFILE_SAMPLES) {
|
||||||
.title = title,
|
|
||||||
.start = read_cpu_timer(),
|
|
||||||
.end = 0,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
void sample_end(profiler_sample_t *sample) {
|
|
||||||
if (profiler.size == MAX_PROFILE_SAMPLES) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
profiler_sample_t *sample = &(profiler.samples[id]);
|
||||||
|
|
||||||
|
if (!(sample->title) || strcmp(title, sample->title) != 0) {
|
||||||
|
sample->title = title;
|
||||||
|
sample->start = 0;
|
||||||
|
sample->duration = 0;
|
||||||
|
sample->children_duration = 0;
|
||||||
|
sample->hit_count = 0;
|
||||||
|
sample->parent = NULL;
|
||||||
|
|
||||||
u64 length = strlen(sample->title);
|
u64 length = strlen(sample->title);
|
||||||
|
|
||||||
if (length > profiler.max_title_length) {
|
if (length > profiler.max_title_length) {
|
||||||
profiler.max_title_length = length;
|
profiler.max_title_length = length;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sample->end = read_cpu_timer();
|
sample->start = read_cpu_timer();
|
||||||
|
++(sample->hit_count);
|
||||||
|
|
||||||
profiler.samples[(profiler.size)++] = *sample;
|
if (sample != profiler.active) {
|
||||||
|
// This handles recursive functions by changing the parent only when a
|
||||||
|
// function isn't calling itself
|
||||||
|
sample->parent = profiler.active;
|
||||||
|
}
|
||||||
|
|
||||||
|
profiler.active = sample;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sample_end(u64 id) {
|
||||||
|
if (id >= MAX_PROFILE_SAMPLES) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
profiler_sample_t *sample = &(profiler.samples[id]);
|
||||||
|
|
||||||
|
u64 duration = read_cpu_timer() - sample->start;
|
||||||
|
|
||||||
|
if (!(sample->parent) || sample != sample->parent) {
|
||||||
|
// This handles recursive functions by adding to the duration only when a
|
||||||
|
// function isn't calling itself
|
||||||
|
sample->duration += duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sample->parent && sample != sample->parent) {
|
||||||
|
// This handles recursive functions by adding to the children_duration only
|
||||||
|
// when a function isn't calling itself
|
||||||
|
sample->parent->children_duration += duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
profiler.active = sample->parent;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user