src/base/cs_timer.c File Reference

| programmer's documentation

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Typedefs | Enumerations | Functions
cs_timer.c File Reference
`#include "cs_config.h"`
`#include "cs_defs.h"`
`#include <math.h>`
`#include <time.h>`
`#include <sys/time.h>`
`#include <sys/resource.h>`
`#include <unistd.h>`
`#include "cs_timer.h"`
Include dependency graph for cs_timer.c:

## Typedefs
typedef void( | _cs_timer_wall_func_t )(cs_timer_t *timer)
typedef void( | _cs_timer_cpu_func_t )(cs_timer_t *timer)

## Enumerations
enum | cs_timer_method_t { CS_TIMER_DISABLE, CS_TIMER_CLOCK_GETTIME, CS_TIMER_GETTIMEOFDAY, CS_TIMER_GETRUSAGE, CS_TIMER_TIME, CS_TIMER_TIMES, CS_TIMER_CLOCK }

## Functions
void | _cs_timer_wall_null (cs_timer_t *timer)
void | _cs_timer_wall_gettimeofday (cs_timer_t *timer)
void | _cs_timer_wall_stdc_time (cs_timer_t *timer)
void | _cs_timer_cpu_null (cs_timer_t *timer)
void | _cs_timer_cpu_getrusage (cs_timer_t *timer)
void | _cs_timer_cpu_stdc_clock (cs_timer_t *timer)
double | cs_timer_wtime (void)
| Return Wall clock time. More...
double | cs_timer_cpu_time (void)
| Return CPU time. More...
void | cs_timer_cpu_times (double *user_time, double *system_time)
| Return separate user and system CPU times. More...
cs_timer_t | cs_timer_time (void)
| Return a timer's value. More...
cs_timer_counter_t | cs_timer_diff (const cs_timer_t *t0, const cs_timer_t *t1)
| Compute the difference between 2 timers. More...
void | cs_timer_counter_add_diff (cs_timer_counter_t *tc, const cs_timer_t *t0, const cs_timer_t *t1)
| Add the the difference between 2 timers to a counter. More...
const char * | cs_timer_wtime_method (void)
| Return method used to return wall clock time. More...
const char * | cs_timer_cpu_time_method (void)
| Return method used to return CPU time. More...

## Typedef Documentation

typedef void( _cs_timer_cpu_func_t)(cs_timer_t *timer)

typedef void( _cs_timer_wall_func_t)(cs_timer_t *timer)

## Enumeration Type Documentation

enum cs_timer_method_t

Enumerator
CS_TIMER_DISABLE |
CS_TIMER_CLOCK_GETTIME |
CS_TIMER_GETTIMEOFDAY |
CS_TIMER_GETRUSAGE |
CS_TIMER_TIME |
CS_TIMER_TIMES |
CS_TIMER_CLOCK |

## Function Documentation

void _cs_timer_cpu_getrusage | ( | cs_timer_t * | timer | ) |

void _cs_timer_cpu_null | ( | cs_timer_t * | timer | ) |

void _cs_timer_cpu_stdc_clock | ( | cs_timer_t * | timer | ) |

void _cs_timer_wall_gettimeofday | ( | cs_timer_t * | timer | ) |

void _cs_timer_wall_null | ( | cs_timer_t * | timer | ) |

void _cs_timer_wall_stdc_time | ( | cs_timer_t * | timer | ) |

void cs_timer_counter_add_diff | ( | cs_timer_counter_t * | tc,
|  | const cs_timer_t * | t0,
|  | const cs_timer_t * | t1
| ) |  |

Add the the difference between 2 timers to a counter.

Parameters

  [in,out] | tc | pointer to timer counter
  [in] | t0 | oldest timer value
  [in] | t1 | most recent timer value

double cs_timer_cpu_time | ( | void |  | ) |

Return CPU time.

Note that in the rare case that only the minimal C library clock() method is available (see cs_timer_cpu_time_method()), at least one of the cs_timer_...() functions (possibly this one) must be called upon program start for this function to be used. In addition, in this case, time may "loop" back to 0 every multiple of 2^size_t / CLOCKS_PER_SEC seconds.

Returns
  current CPU time usage, or -1 if unable to compute.

const char* cs_timer_cpu_time_method | ( | void |  | ) |

Return method used to return CPU time.

Returns
  short description of method used to return CPU time.

void cs_timer_cpu_times | ( | double * | user_time,
|  | double * | system_time
| ) |  |

Return separate user and system CPU times.

Note that in the rare case that only the minimal C library clock() method is available, this function will return -1 values.

Parameters

  [out] | user_time | current user CPU usage.
  [out] | system_time | current system CPU usage.

cs_timer_counter_t cs_timer_diff | ( | const cs_timer_t * | t0,
|  | const cs_timer_t * | t1
| ) |  |

Compute the difference between 2 timers.

Parameters

  [in] | t0 | oldest timer value
  [in] | t1 | most recent timer value

Returns
  last - first timer value.

cs_timer_t cs_timer_time | ( | void |  | ) |

Return a timer's value.

Returns
  timer structure.

double cs_timer_wtime | ( | void |  | ) |

Return Wall clock time.

Returns
  elapsed time from first call of a function of the cs_timer_...() series, or -1 if unable to compute.

const char* cs_timer_wtime_method | ( | void |  | ) |

Return method used to return wall clock time.

Returns
  short description of method used to return wall clock time.