I use unsigned long to collect performance data when profiling the 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 called in my application.
Now, after running the application, ask a separate program to read the above file and summarize the time spent on each function, including the number of calls, for example
func_name aggregate_time call_counts
The problem is that for some functions, the aggregate_time field is a 20-digit value, i.e. The maximum value that an unsigned long can contain. This cannot be true, because I measure the time in microseconds and do not start my application for more than 20 seconds. How can this be a 20 digit value?
Do you see errors in steps 1,2 and 3?
Regards, Krishna
EDIT:
1) Time measurement: clock_gettime (CLOCK_REALTIME, & start_time); clock_gettime (CLOCK_REALTIME, & end_time); unsigned long time_taken = (unsigned long) ((finish_time.tv_nsec - art_time.tv_nsec) / 1000);
2) File recording: fwrite (& time_taken, sizeof (unsigned long), 1, data file);
3) The file has been read: fread (& time_taken, sizeof (long), 1, data file);
:
clock_gettime(CLOCK_REALTIME, &start_time); clock_gettime(CLOCK_REALTIME, &finish_time); unsigned long time_taken = (unsigned long)((finish_time.tv_nsec - start_time.tv_nsec)/1000);
1- start_time finish_time, .
start_time
finish_time
tv_sec:
tv_sec
unsigned long time_taken; time_taken = (unsigned long)((finish_time.tv_sec - start_time.tv_sec) * 1000000); time_taken += (unsigned long)(finish_time.tv_nsec / 1000); time_taken -= (unsigned long)(start_time.tv_nsec / 1000);
(, 23989032,452 struct timespec .tv_sec = 23989032 .tv_nsec = 452000000)
struct timespec
.tv_sec = 23989032
.tv_nsec = 452000000
, , .
, :
, . , , , , RDTSC, , CPU. AMD , , , , , .
, , , Win32 API SetProcessAffinityMask.
SetProcessAffinityMask
EDIT: , . API , . RDTSC .
: - - , . , , , , , , , fwrite. , , ( , , fwrite, fwrite).
fwrite
Source: https://habr.com/ru/post/1780788/More articles:An alternative to CoreGraphics? - c ++Application Launch Event Detection - cocoaSVN Info: Last Modified Date? - svnCompare each element in the array with each other - arraysNH QueryOver FetchMany Exception - vb.netИзмените плагин jquery от подсчета слов к плагину символов? - jqueryQuestion with Scrapy Newbie - can't work with tutorial file - pythonIs there a better way to get the public “properties” of a Ruby object? - reflectionUsing identifier in databases - databaseHeroku на Windows дает ошибку: Содержание Недействительный открытый ключ - windowsAll Articles