c++ - how to run Clock-gettime correctly in Vxworks to get accurate time -


i trying measure time take processes in c++ program linux , vxworks. have noticed clock_gettime(clock_realtime, timespec ) accurate enough (resolution 1 ns) job on many oses. portability matter using function , running on both vxworks 6.2 , linux 3.7. ve tried measure time taken simple print:

    #define <timers.h<     #define <iostream>     #define billion 1000000000l     int main(){        struct timespec start, end; uint32_t diff;        for(int i=0; i<1000; i++){          clock_gettime(clock_realtme, &start);          std::cout<<"do stuff"<<std::endl;          clock_gettime(clock_realtme, &end);          diff = billion*(end.tv_sec-start.tv_sec)+(end.tv_nsec-start.tv_nsec);         std::cout<<diff<<std::endl;        }        return 0;     } 

i compiled on linux , vxworks. linux results seemed logic (average 20 µs). vxworks, ve got lot of zeros , 5000000 ns , lot of zeros... ps , vxwroks, runned app on arm-cortex a8, , results seemed random have seen same bug before,

in vxworks, clock resolution defined system scheduler frequency. default, typically 60hz, may different dependant on bsp, kernel configuration, or runtime configuration.

the vxworks kernel configuration parameters sys_clk_rate_max , sys_clk_rate_min define maximum , minimum values supported, , sys_clk_rate defines default rate, applied @ boot.

the actual clock rate can modified @ runtime using sysclkrateset, either within code, or shell.

you can check current rate using sysclkrateget.

given seeing either 0 or 5000000ns - 5ms, expect system clock rate ~200hz.

to greater resolution, can increase system clock rate. however, may have undesired side effects, increase frequency of system operations.

a better method of timing code may use systimestamp typically driven high frequency timer, , can used perform high-res timing of short-lived activities.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -