Use profiling functions to time the haversine processor
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
#include "haversine.h"
 | 
			
		||||
#include "point_types.h"
 | 
			
		||||
#include "processor/proc_argparser.h"
 | 
			
		||||
#include "profiler/timer.h"
 | 
			
		||||
#include "json/dstring.h"
 | 
			
		||||
#include "json/json_entities.h"
 | 
			
		||||
#include "json/parser.h"
 | 
			
		||||
@@ -13,12 +14,20 @@
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
int main(int argc, char *argv[]) {
 | 
			
		||||
  u64 cpu_freq = get_cpu_freq(500);
 | 
			
		||||
 | 
			
		||||
  u64 cli_parse_start = read_cpu_timer();
 | 
			
		||||
 | 
			
		||||
  ProcessorArgs args = parse_args(argc, argv);
 | 
			
		||||
 | 
			
		||||
  u64 json_parse_start = read_cpu_timer();
 | 
			
		||||
 | 
			
		||||
  jentity_t *root = load_json(args.filepath);
 | 
			
		||||
 | 
			
		||||
  assert(root->type == JENTITY_SINGLE && root->value.type == JVAL_COLLECTION);
 | 
			
		||||
 | 
			
		||||
  u64 load_pairs_json_start = read_cpu_timer();
 | 
			
		||||
 | 
			
		||||
  jentity_t *pairs = root->value.collection->begin;
 | 
			
		||||
 | 
			
		||||
  assert(pairs->type == JENTITY_PAIR &&
 | 
			
		||||
@@ -50,6 +59,8 @@ int main(int argc, char *argv[]) {
 | 
			
		||||
    point_pairs[index++] = p;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  u64 binary_file_read_start = read_cpu_timer();
 | 
			
		||||
 | 
			
		||||
  const char *filename = "count_and_distances";
 | 
			
		||||
 | 
			
		||||
  FILE *fp = fopen(filename, "r");
 | 
			
		||||
@@ -60,6 +71,8 @@ int main(int argc, char *argv[]) {
 | 
			
		||||
    fseek(fp, sizeof(u64), SEEK_SET);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  u64 haversine_sum_start = read_cpu_timer();
 | 
			
		||||
 | 
			
		||||
  f64 sum = 0.0;
 | 
			
		||||
  f64 distance = 0.0;
 | 
			
		||||
  f64 saved_distance = 0.0;
 | 
			
		||||
@@ -77,13 +90,61 @@ int main(int argc, char *argv[]) {
 | 
			
		||||
 | 
			
		||||
    sum += distance;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  u64 haversine_average_start = read_cpu_timer();
 | 
			
		||||
 | 
			
		||||
  printf("\nAVERAGE DISTANCE: %f\n", sum / pair_count);
 | 
			
		||||
 | 
			
		||||
  u64 tear_down_start = read_cpu_timer();
 | 
			
		||||
 | 
			
		||||
  if (fp) {
 | 
			
		||||
    fclose(fp);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  free(point_pairs);
 | 
			
		||||
 | 
			
		||||
  u64 end = read_cpu_timer();
 | 
			
		||||
 | 
			
		||||
  if (cpu_freq) {
 | 
			
		||||
    u16 time_precision = 16;
 | 
			
		||||
    u16 time_char_count = 20;
 | 
			
		||||
    u16 percentage_precision = 8;
 | 
			
		||||
    u16 percentage_char_count = 12;
 | 
			
		||||
 | 
			
		||||
    f64 total = (f64)end - (f64)cli_parse_start;
 | 
			
		||||
    f64 cli_parse = (f64)json_parse_start - (f64)cli_parse_start;
 | 
			
		||||
    f64 json_parse = (f64)load_pairs_json_start - (f64)json_parse_start;
 | 
			
		||||
    f64 json_load = (f64)binary_file_read_start - (f64)load_pairs_json_start;
 | 
			
		||||
    f64 binary_open = (f64)haversine_sum_start - (f64)binary_file_read_start;
 | 
			
		||||
    f64 haversine_sum = (f64)haversine_average_start - (f64)haversine_sum_start;
 | 
			
		||||
    f64 haversine_average = (f64)tear_down_start - (f64)haversine_average_start;
 | 
			
		||||
    f64 tear_down = (f64)end - (f64)tear_down_start;
 | 
			
		||||
 | 
			
		||||
    printf("\n==========================PROFILING==========================\n");
 | 
			
		||||
    printf("Total: %*.*f seconds (CPU frequency: %llu)\n\n", time_char_count,
 | 
			
		||||
           time_precision, total / cpu_freq, (unsigned long long)cpu_freq);
 | 
			
		||||
    printf("  CLI PARSING: %*.*f seconds (%*.*f %%)\n", time_char_count,
 | 
			
		||||
           time_precision, cli_parse / cpu_freq, percentage_char_count,
 | 
			
		||||
           percentage_precision, cli_parse / total * 100.0);
 | 
			
		||||
    printf(" JSON PARSING: %*.*f seconds (%*.*f %%)\n", time_char_count,
 | 
			
		||||
           time_precision, json_parse / cpu_freq, percentage_char_count,
 | 
			
		||||
           percentage_precision, json_parse / total * 100.0);
 | 
			
		||||
    printf(" JSON LOADING: %*.*f seconds (%*.*f %%)\n", time_char_count,
 | 
			
		||||
           time_precision, json_load / cpu_freq, percentage_char_count,
 | 
			
		||||
           percentage_precision, json_load / total * 100.0);
 | 
			
		||||
    printf("  BINARY OPEN: %*.*f seconds (%*.*f %%)\n", time_char_count,
 | 
			
		||||
           time_precision, binary_open / cpu_freq, percentage_char_count,
 | 
			
		||||
           percentage_precision, binary_open / total * 100.0);
 | 
			
		||||
    printf("HAVERSINE SUM: %*.*f seconds (%*.*f %%)\n", time_char_count,
 | 
			
		||||
           time_precision, haversine_sum / cpu_freq, percentage_char_count,
 | 
			
		||||
           percentage_precision, haversine_sum / total * 100.0);
 | 
			
		||||
    printf("HAVERSINE AVG: %*.*f seconds (%*.*f %%)\n", time_char_count,
 | 
			
		||||
           time_precision, haversine_average / cpu_freq, percentage_char_count,
 | 
			
		||||
           percentage_precision, haversine_average / total * 100.0);
 | 
			
		||||
    printf("     TEARDOWN: %*.*f seconds (%*.*f %%)\n", time_char_count,
 | 
			
		||||
           time_precision, tear_down / cpu_freq, percentage_char_count,
 | 
			
		||||
           percentage_precision, tear_down / total * 100.0);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user