An illustrative code example in C using the performance timer API is shown below (and is also available in the examples directory from a top-level install). This example illustrates basic timer usage (including the use of nested timers).
#include<stdio.h>
#include<unistd.h>
#include<sys/time.h>
#include<time.h>
const double Foo_Sleep = 0.3 * 1.e6;
const double Bar_Sleep = 0.05 * 1.e6;
const double Boo_Sleep = 0.1167 * 1.e6;
const int Max_Iters = 10;
void foo();
void bar();
void boo();
int main()
{
int i,itest;
const int num_repeat = 2;
for(itest=0;itest<num_repeat;itest++)
{
if(itest > 0)
for(i=0;i<Max_Iters;i++)
{
printf("Main iteration loop = %i\n",i);
foo();
}
}
printf("Querying global timer elapsed time:\n");
printf("\nQuerying individual timers (exclusive values):\n");
printf("\nQuerying individual stats for timer \"bar\" (exclusive values)\n");
printf("\nQuerying individual timers (inclusive values):\n");
printf("\nQuerying individual stats for timer \"foo\" (inclusive values)\n");
const int num_procs = 1;
return 0;
}
void foo()
{
usleep(Foo_Sleep);
bar();
return;
}
void bar()
{
usleep(Bar_Sleep);
boo();
return;
}
void boo()
{
usleep(Boo_Sleep);
return;
}
int grvy_timer_save_hist(const char *experiment_name, const char *comment, int num_procs, const char *filename)
Save current libGRVY timing results to HDF file for logging.
double grvy_timer_stats_min(const char *id)
Returns the minimum (exclusive) measured timing (in seconds) for defined timer id.
void grvy_timer_finalize()
Finalize global timing process - stops the active global timer.
double grvy_timer_elapsedseconds_inc(const char *id)
Returns total (inclusive) elapsed time (in seconds) for defined timer id.
void grvy_timer_begin(const char *id)
Identify beginning of code section to time with unique id string.
int grvy_timer_stats_count(const char *id)
Returns the total number of timer calls for defined timer id.
void grvy_timer_init(const char *description)
Initialize timer library with a description string which initiates the global timing process (the des...
void grvy_timer_summarize()
Print a concise summary of all defined timers to stdout. This routine shows the relative runtime perc...
double grvy_timer_elapsedseconds(const char *id)
Returns total (exclusive) elapsed time (in seconds) for defined timer id.
double grvy_timer_stats_min_inc(const char *id)
Returns the minimum (inclusive) measured timing (in seconds) for defined timer id.
double grvy_timer_stats_max_inc(const char *id)
Returns the largest (inclusive) measured timing (in seconds) for defined timer id.
double grvy_timer_stats_mean_inc(const char *id)
Returns the mean (inclusive) value (in seconds) for defined timer id.
void grvy_timer_reset()
Resets all actively defined timers (accumulated time and calling statistics are reinitialized).
void grvy_timer_end(const char *id)
Identify end of code section to time with a matching id string.
double grvy_timer_stats_variance_inc(const char *id)
Returns the variance (inclusive) for defined timer id.
double grvy_timer_elapsed_global()
Returns total elapsed time (in seconds) for the global timer.
double grvy_timer_stats_mean(const char *id)
Returns the mean (exclusive) value (in seconds) for defined timer id.
double grvy_timer_stats_variance(const char *id)
Returns the variance (exclusive) for defined timer id.
double grvy_timer_stats_max(const char *id)
Returns the largest (exclusive) measured timing (in seconds) for defined timer id.
Generated on Wed Jul 12 2023 16:53:23 for GRVY-0.38.0
by
doxygen
1.8.17