Skip to content
Snippets Groups Projects
Commit 2ec7eca0 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Add function to convert millisec into ticks

parent a9b7c600
Branches
Tags
1 merge request!491Add restart facility
...@@ -216,6 +216,25 @@ double clocks_from_ticks(ticks tics) { ...@@ -216,6 +216,25 @@ double clocks_from_ticks(ticks tics) {
return ((double)tics / (double)clocks_get_cpufreq() * clocks_units_scale); return ((double)tics / (double)clocks_get_cpufreq() * clocks_units_scale);
} }
/**
* @brief Convert a number of milli seconds into ticks, if possible.
*
* Only an approximation as based on how well we have estimated the
* rtc frequency. Should be good for machines that support constant_rtc
* and clock_gettime(), and reasonable for most Linux machines, otherwise
* a guess will just be returned. See clocks_getunit() for the actual units.
*
* @param ms a number of "milliseconds" to convert to ticks
*
* @result the number of ticks, if possible.
*/
ticks clocks_to_ticks(double ms) {
return (ticks) (ms * (double)clocks_get_cpufreq() / clocks_units_scale);
}
ticks clocks_to_ticks(double interval);
/** /**
* @brief return the time units. * @brief return the time units.
* *
......
...@@ -39,6 +39,7 @@ const char *clocks_getunit(); ...@@ -39,6 +39,7 @@ const char *clocks_getunit();
void clocks_set_cpufreq(unsigned long long freq); void clocks_set_cpufreq(unsigned long long freq);
unsigned long long clocks_get_cpufreq(); unsigned long long clocks_get_cpufreq();
double clocks_from_ticks(ticks tics); double clocks_from_ticks(ticks tics);
ticks clocks_to_ticks(double interval);
double clocks_diff_ticks(ticks tic, ticks toc); double clocks_diff_ticks(ticks tic, ticks toc);
const char *clocks_get_timesincestart(); const char *clocks_get_timesincestart();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment