I am using unsigned long to collect performance data while profiling an application as follows
unsigned long time_taken = (unsigned long) ((finish_time_in_nano_sec - start_time_in_nano_sec)/1000);
Write time_taken to a file. Do this for every function that gets called in my app.
Now after app execution, have a separate program read the above file and sum up the time taken for every function including call counts such as
func_name aggregate_time call_counts
The problem I have is that for some functions, the aggregate_time field is a 20 digit value i.e. the maximum value an unsigned long can hold. This cannot be true because I measure time in microseconds and don't run my app for more than like 20 seconds. How can it then be a 20 digit value?
Do you see mistakes in Steps 1,2 and 3?
Regards, Krishna
EDIT:
1) Time measurement: clock_gettime(CLOCK_REALTIME, &start_time); clock_gettime(CLOCK_REALTIME, &finish_time); unsigned long time_taken = (unsigned long)((finish_time.tv_nsec - art_time.tv_nsec)/1000);
2) File write: fwrite(&time_taken, sizeof(unsigned long), 1, datafile);
3) File read: fread(&time_taken, sizeof(long), 1, datafile);