diff --git a/.gitignore b/.gitignore index c80f325..199b770 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ callgrind.out programs/cube.asm programs/utah_teapot.asm auxiliary_progs/stl_to_source_code + +simlog.json diff --git a/cpu.c b/cpu.c index f1b0117..f8e03d9 100644 --- a/cpu.c +++ b/cpu.c @@ -581,6 +581,7 @@ int exec(struct simdata_t *simdata){ if(simdata->exec_data->cycles_left==0){ simdata->fetch_data->exec_done=1; simdata->decode_data->exec_done=1; + simdata->finished_instructions++; } add_to_instr_list(&simdata->cpu_gui_hints->executing_list,simdata->exec_data->address); return 0; diff --git a/main.c b/main.c index c386811..bbb0ae2 100644 --- a/main.c +++ b/main.c @@ -41,6 +41,7 @@ void help(char* progname){ #else " braille\n" #endif + " -o < file > Output simualtion data to specified json log file\n" , progname); } @@ -61,7 +62,9 @@ int main(int argc, char* argd[] ){ char *assemble = NULL; enum FB_DRIVER_t fb_driver=FB_BRAILLE; int opt; - while ((opt = getopt(argc, argd, "hi:a:r:")) != -1) { + char *json_log_filename=NULL; + FILE *JSON_LOG_FILE; + while ((opt = getopt(argc, argd, "hi:a:r:o:")) != -1) { switch (opt) { case 'h': help(argd[0]); @@ -88,6 +91,9 @@ int main(int argc, char* argd[] ){ return 1; } break; + case 'o': + json_log_filename=optarg; + break; default: help(argd[0]); return 1; @@ -104,6 +110,14 @@ int main(int argc, char* argd[] ){ help(argd[0]); return 1; } + if (json_log_filename){ + JSON_LOG_FILE=fopen(json_log_filename,"w"); + if(JSON_LOG_FILE==NULL){ + printf("Error opening file \"%s\": %s\n",json_log_filename,strerror(errno)); + return 1; + } + fprintf(JSON_LOG_FILE, "{\n\"end_of_simulation_data\" : {\n"); + } /// READ INPUT FILE /// FILE* rom=fopen(infile,"r"); @@ -275,6 +289,14 @@ int main(int argc, char* argd[] ){ usleep(100000); } + if(json_log_filename){ + fprintf(JSON_LOG_FILE, "\"cycles_run_for\" : %lu ,\n", simdata->current_clock); + fprintf(JSON_LOG_FILE, "\"instructions_executed\" : %lu\n", simdata->finished_instructions); + fprintf(JSON_LOG_FILE, "}\n}\n" ); + + fclose(JSON_LOG_FILE); + } + if(end_gui()){ printf("Failed on end_gui()\n"); cpu_simdata_free(simdata); diff --git a/parse_log.sh b/parse_log.sh new file mode 100755 index 0000000..0501d6a --- /dev/null +++ b/parse_log.sh @@ -0,0 +1,13 @@ +#!/bin/sh +set -eu + +if ! [ "$#" = 1 ] +then + echo $0 \ + exit 1 +fi + +CYCLES=$(cat "$1" | json2tsv | sed -n '/^\.end_of_simulation_data\.cycles_run_for\t/s/\.end_of_simulation_data\.cycles_run_for\tn\t//p' ) +INSTRUCTIONS=$(cat "$1" | json2tsv | sed -n '/^\.end_of_simulation_data\.instructions_executed\t/s/\.end_of_simulation_data\.instructions_executed\tn\t//p' ) + +echo executed $INSTRUCTIONS instructions with an IPC=$(echo "$INSTRUCTIONS/$CYCLES" | bc -l|grep -o '^.*\...') diff --git a/simdata.c b/simdata.c index 2a22314..b964e81 100644 --- a/simdata.c +++ b/simdata.c @@ -25,10 +25,11 @@ struct simdata_t *init_simdata(){ struct simdata_t * ret=malloc(sizeof(struct simdata_t)); - if(!ret){ - ret->current_clock=0; + if(!ret) return 0; - } + + ret->current_clock=0; + ret->finished_instructions=0; ret->RAM=malloc(16777216); //Maximum addressable memory if(!ret->RAM){ diff --git a/simdata.h b/simdata.h index de35061..d5e65c5 100644 --- a/simdata.h +++ b/simdata.h @@ -13,6 +13,7 @@ enum CPU_STRUCTURE_t{ //TODO: I would prefer this would go to cpu.h struct simdata_t{ long unsigned int current_clock; + long unsigned int finished_instructions; uint8_t *RAM; struct fetch_data_t *fetch_data;