Add profiling code to the json parser
This commit is contained in:
		@@ -1,5 +1,7 @@
 | 
			
		||||
#include "json/parser.h"
 | 
			
		||||
#include "aliases.h"
 | 
			
		||||
#include "profiler/ids.h"
 | 
			
		||||
#include "profiler/timer.h"
 | 
			
		||||
#include "json/dstring.h"
 | 
			
		||||
#include "json/json_entities.h"
 | 
			
		||||
#include "json/lexer.h"
 | 
			
		||||
@@ -21,6 +23,8 @@ INTERNAL jentity_t *add_value(parser_t *parser);
 | 
			
		||||
INTERNAL void add_collection(parser_t *parser);
 | 
			
		||||
 | 
			
		||||
jentity_t *load_json(const char *filepath) {
 | 
			
		||||
  SAMPLE_START(PROFILER_ID_READ_JSON_FILE, "READ JSON FILE");
 | 
			
		||||
 | 
			
		||||
  FILE *fp = fopen(filepath, "r");
 | 
			
		||||
 | 
			
		||||
  if (!fp) {
 | 
			
		||||
@@ -40,6 +44,10 @@ jentity_t *load_json(const char *filepath) {
 | 
			
		||||
 | 
			
		||||
  fclose(fp);
 | 
			
		||||
 | 
			
		||||
  SAMPLE_END(PROFILER_ID_READ_JSON_FILE);
 | 
			
		||||
 | 
			
		||||
  SAMPLE_START(PROFILER_ID_PARSER_SETUP, "JSON PARSER SETUP");
 | 
			
		||||
 | 
			
		||||
  lexer_t *lexer = NULL;
 | 
			
		||||
  parser_t *parser = NULL;
 | 
			
		||||
 | 
			
		||||
@@ -55,15 +63,23 @@ jentity_t *load_json(const char *filepath) {
 | 
			
		||||
    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);
 | 
			
		||||
  SAMPLE_END(PROFILER_ID_LEX_GET_TOKEN);
 | 
			
		||||
 | 
			
		||||
  if (result.error.errno) {
 | 
			
		||||
    printf("%s\n", result.error.msg);
 | 
			
		||||
  } else {
 | 
			
		||||
    while (result.token.type != TK_NO_TOKEN) {
 | 
			
		||||
      SAMPLE_START(PROFILER_ID_PARSE_TOKEN, "PARSE 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);
 | 
			
		||||
      SAMPLE_END(PROFILER_ID_LEX_GET_TOKEN);
 | 
			
		||||
 | 
			
		||||
      if (result.error.errno) {
 | 
			
		||||
        printf("%s\n", result.error.msg);
 | 
			
		||||
@@ -74,10 +90,14 @@ jentity_t *load_json(const char *filepath) {
 | 
			
		||||
 | 
			
		||||
  jentity_t *root = parser->root;
 | 
			
		||||
 | 
			
		||||
  SAMPLE_START(PROFILER_ID_PARSER_TEAR_DOWN, "PARSER TEAR DOWN");
 | 
			
		||||
 | 
			
		||||
  parser_free(&parser);
 | 
			
		||||
  lexer_free(&lexer);
 | 
			
		||||
  free(json);
 | 
			
		||||
 | 
			
		||||
  SAMPLE_END(PROFILER_ID_PARSER_TEAR_DOWN);
 | 
			
		||||
 | 
			
		||||
  return root;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user