Profiling

mm_tic

#include <mmprofile.h>
void mm_tic(void)

Start a iteration of profiling

Parameters:
  • void – no arguments

Description

Update the timing statistics with the previous data if applicable and reset the metadata for a new timing iteration. Finally measure the timestamp of the iteration start.

NOTE

Contrary to the usual API functions, mm_tic() uses the attribute API_EXPORTED_RELOCATABLE. This is done on purpose. See NOTE of estimate_toc_overhead().

mm_toc

#include <mmprofile.h>
void mm_toc(void)

Add a new point of measure to the current timing iteration

Parameters:
  • void – no arguments

NOTE

Contrary to the usual API functions, mm_toc() uses the attribute API_EXPORTED_RELOCATABLE. This is done on purpose. See NOTE of estimate_toc_overhead().

mm_toc_label

#include <mmprofile.h>
void mm_toc_label(const char* label)

Add a new point of measure associated with a label

Parameters:
  • label (const char*) – string to appear in front of measure point at result display

Description

This function is the same as mm_toc() excepting it provides a way to label the meansure point. Beware than only the first occurrence of a label associated with a measure point will be retained. Any subsequent call to mm_toc_label() at the same measure point index will be the same as calling mm_toc().

NOTE

Contrary to the usual API functions, mm_toc_label() uses the attribute API_EXPORTED_RELOCATABLE. This is done on purpose. See NOTE of estimate_toc_overhead().

See also

mm_toc()

mm_profile_print

#include <mmprofile.h>
int mm_profile_print(int mask, int fd)

Print the timing statistics gathered so far

Parameters:
  • mask (int) – combination of flags indicating statistics must be printed
  • fd (int) – file descriptor to which the statistics must be printed

Description

Print the timing statistics on the file descriptor specified by fd. The printed statistics between each consecutive point of measure is controlled by the mask parameter which will a bitwise-or’d combination of the following flags :

  • PROF_CURR: display the value of the current iteration
  • PROF_MIN: display the min value since the last reset
  • PROF_MAX: display the max value since the last reset
  • PROF_MEDIAN: display the median value since the last reset
  • PROF_FORCE_NSEC: force result display in nanoseconds
  • PROF_FORCE_USEC: force result display in microseconds
  • PROF_FORCE_MSEC: force result display in milliseconds
  • PROF_FORCE_SEC: force result display in seconds

Return

0 in case of success, -1 otherwise with errno set accordingly

See also

mm_profile_reset(), mm_tic(), write()

mm_profile_get_data

#include <mmprofile.h>
int64_t mm_profile_get_data(int measure_point, int type)

Retrieve profile result programmatically

Parameters:
  • measure_point (int) – measure point whose statistic must be get
  • type (int) – type of statistic (PROF_[CURR|MIN|MEAN|MAX|MEDIAN])

Return

statistic value in nanosecond

mm_profile_reset

#include <mmprofile.h>
void mm_profile_reset(int flags)

Reset the statistics and change the timer

Parameters:
  • flags (int) – bit-OR combination of flags influencing the reset behavior.

Description

Reset the timing statistics, ie, reset the min, max, mean values as well as the number of point used in one iteration and the associated labels. Additionally it provides a ways to change the type of timer used for measure.

The flags arguments allows to change the behavior of the reset. If the PROF_RESET_CPUCLOCK flag is set, it will use a timer based on CPU’s instruction counter. This timer has a very fine granularity (of the order of very few nanoseconds) but it does not take measure time spent on sleeping while waiting certain event (disk io, mutex/cond, etc…). This timer indicates the processing power spent on tasks.

Alternatively if PROF_RESET_CPUCLOCK is not set, it will use a timer based on wall clock. This timer has bigger granularity (order of hundred nanoseconds) and report time spent at sleeping. The indicates the realtime update will performing certain task.

If the PROF_RESET_KEEPLABEL flag is set in the flags argument, the labels associated with each measure point will be kept over the reset. In practice, this provides a way to avoid the overhead of of label copy when using mm_toc_label(): an initial iteration will copy the label and the measurements are reset after this first iteration while keeping the label. Then the subsequent call to mm_toc_label() will not be affected by the string copy overhead.

At startup, the function are configured to use CPU based timer.