Project: Added support for json log file

This commit is contained in:
(Tim) Efthimis Kritikos 2024-05-02 08:28:15 +01:00
parent 99c0af752b
commit 48237ccd95
6 changed files with 44 additions and 4 deletions

2
.gitignore vendored
View File

@ -7,3 +7,5 @@ callgrind.out
programs/cube.asm programs/cube.asm
programs/utah_teapot.asm programs/utah_teapot.asm
auxiliary_progs/stl_to_source_code auxiliary_progs/stl_to_source_code
simlog.json

1
cpu.c
View File

@ -581,6 +581,7 @@ int exec(struct simdata_t *simdata){
if(simdata->exec_data->cycles_left==0){ if(simdata->exec_data->cycles_left==0){
simdata->fetch_data->exec_done=1; simdata->fetch_data->exec_done=1;
simdata->decode_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); add_to_instr_list(&simdata->cpu_gui_hints->executing_list,simdata->exec_data->address);
return 0; return 0;

24
main.c
View File

@ -41,6 +41,7 @@ void help(char* progname){
#else #else
" braille\n" " braille\n"
#endif #endif
" -o < file > Output simualtion data to specified json log file\n"
, progname); , progname);
} }
@ -61,7 +62,9 @@ int main(int argc, char* argd[] ){
char *assemble = NULL; char *assemble = NULL;
enum FB_DRIVER_t fb_driver=FB_BRAILLE; enum FB_DRIVER_t fb_driver=FB_BRAILLE;
int opt; 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) { switch (opt) {
case 'h': case 'h':
help(argd[0]); help(argd[0]);
@ -88,6 +91,9 @@ int main(int argc, char* argd[] ){
return 1; return 1;
} }
break; break;
case 'o':
json_log_filename=optarg;
break;
default: default:
help(argd[0]); help(argd[0]);
return 1; return 1;
@ -104,6 +110,14 @@ int main(int argc, char* argd[] ){
help(argd[0]); help(argd[0]);
return 1; 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 /// /// READ INPUT FILE ///
FILE* rom=fopen(infile,"r"); FILE* rom=fopen(infile,"r");
@ -275,6 +289,14 @@ int main(int argc, char* argd[] ){
usleep(100000); 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()){ if(end_gui()){
printf("Failed on end_gui()\n"); printf("Failed on end_gui()\n");
cpu_simdata_free(simdata); cpu_simdata_free(simdata);

13
parse_log.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
set -eu
if ! [ "$#" = 1 ]
then
echo $0 \<simlog json file\>
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 '^.*\...')

View File

@ -25,10 +25,11 @@
struct simdata_t *init_simdata(){ struct simdata_t *init_simdata(){
struct simdata_t * ret=malloc(sizeof(struct simdata_t)); struct simdata_t * ret=malloc(sizeof(struct simdata_t));
if(!ret){ if(!ret)
ret->current_clock=0;
return 0; return 0;
}
ret->current_clock=0;
ret->finished_instructions=0;
ret->RAM=malloc(16777216); //Maximum addressable memory ret->RAM=malloc(16777216); //Maximum addressable memory
if(!ret->RAM){ if(!ret->RAM){

View File

@ -13,6 +13,7 @@ enum CPU_STRUCTURE_t{ //TODO: I would prefer this would go to cpu.h
struct simdata_t{ struct simdata_t{
long unsigned int current_clock; long unsigned int current_clock;
long unsigned int finished_instructions;
uint8_t *RAM; uint8_t *RAM;
struct fetch_data_t *fetch_data; struct fetch_data_t *fetch_data;