Tools (tool)#
- group tool
Development tools, such as grind (execution timing and counting).
rcsw/tool/grind.h#
Grind: execution timing and counting instrumentation.
Defines
-
RCSW_GRIND_START(the_grinder, name)#
Compile-time macro for grind_capture_start()
-
RCSW_GRIND_END(the_grinder, name)#
Compile-time macro for grind_capture_end()
-
RCSW_GRIND_COUNT(the_grinder, name)#
Compile-time macro for grind_capture_count()
-
RCSW_GRIND_TICK(the_grinder, name)#
Compile-time macro for grind_capture_tick()
-
RCSW_GRIND_INTERVAL#
Compute all measurements within an absolute time interval.
The grinder timeout will be used.
This behavior is useful for gathering timing metrics on a small piece of a large system (e.g. how long interrupt handlers run).
See also
RCSW_GRIND_RESET_AUTO for what happens on a timeout.
If this flag is not passed, then all statistics will be relatively computed; that is regardless of the “real” amount of time (wall time) all statistics take, all utilization percentages will always add to 100%.
-
RCSW_GRIND_RESET_AUTO#
Automatically reset statistics for some/all grindees.
Behavior with RCSW_GRIND_INTERVAL : At the end of the timeout interval, reset statistics for
allgrindees.Behavior without RCSW_GRIND_INTERVAL : once a grindee instance becomes full it will be reset upon the next request to gather stats (other stat instances are not affected).
If this flag is not passed, then stats for a grindee will never be reset, and once full no more stats will be gathered.
-
RCSW_GRIND_REPORT_AUTO#
Automatically report statistics for a grindee once full to stdout.
If not passed: stat gathering on a grindee whose stats are full to block until statistics for that instance are reported unless RCSW_GRIND_RESET_AUTO is passed.
If both RCSW_GRIND_REPORT_AUTO and RCSW_GRIND_RESET_AUTO are passed, then statistics for a grindee will be reported and then reset, the exact nature of the reset being determined by the presence/absence of RCSW_GRIND_INTERVAL.
-
RCSW_GRIND_REPORT_REQ_FULL#
Require that statistics for any grindee to be full when reported.
If passed: reporting statistics on grindees that are not full will fail.
If not passed: statistics can be reported for any grindee at any time.
Note
Has no effect on whether or not statistics for a “full” grindee will be reset/reported when full; it only comes into play WHEN the grind_report() function has been called (either automatically if RCSW_GRIND_REPORT_AUTO is passed, or manually by the calling application.
-
RCSW_GRIND_REPORT_DATAPOINTS#
Show collected datapoints when reporting.
Valid in any mode.
-
RCSW_GRIND_REPORT_HISTOGRAM#
Show histogram of datapoints when reporting.
Valid in any mode.
-
RCSW_GRINDEE_NAMELEN#
Max length of all grindee names.
Enums
-
enum grind_mode#
The type of “grinding” to do; sets the domain for a grinder.
Values:
-
enumerator RCSW_GRIND_MODE_COUNT#
Enable usage of grind_capture_count() to capture execution counts.
All timing related flags are ignored in this mode. All stats must be reported/cleared manually for each grindee.
-
enumerator RCSW_GRIND_MODE_DURATION#
Enable usage of grind_capture_start() / grind_capture_end() to capture duration.
Durations are captured by (end - start) time. Execution counts of the section between grind_capture_start() and grind_capture_end() are also captured.
-
enumerator RCSW_GRIND_MODE_PERIOD#
Enable usage of grind_capture_tick() to capture ticks.
Ticks are captured by tick = current time - last tick; this is the same as the period of the thing that is ticking. Execution counts of grind_capture_tick() are also captured.
-
enumerator RCSW_GRIND_MODE_COUNT#
Functions
-
struct grinder *grind_init(struct grinder *grind_in, const struct grind_config *config)#
Initialize a grinder for statistics collection.
This function initializes the statistics global data structure to gather statistics on all stat instances encountered during execution.
- Parameters:
grind_in – Caller storage for the handle, used only if RCSW_NOALLOC_HANDLE is passed; ignored (may be NULL) otherwise. See Memory Model .
config – The initialization parameters.
- Returns:
The initialized grinder, or NULL if an error occurred.
-
void grind_destroy(struct grinder *the_grinder)#
Shutdown grinding.
Any further use of the API is undefined until grind_init() is called again.
-
status_t grind_capture_start(struct grinder *the_grinder, const char *name)#
Mark the start of a single [begin, end] datapoint for a grindee.
Only valid with RCSW_GRIND_MODE_DURATION.
- Returns:
-
status_t grind_capture_end(struct grinder *the_grinder, const char *name)#
Mark the end of a single [begin, end] datapoint for a grindee.
Only valid with RCSW_GRIND_MODE_DURATION.
- Returns:
-
status_t grind_capture_count(struct grinder *the_grinder, const char *name)#
Increment the execution count for the grindee.
Only valid with RCSW_GRIND_MODE_COUNT.
- Returns:
-
status_t grind_capture_tick(struct grinder *the_grinder, const char *name)#
Capture the current time/tick for the grindee.
Only valid with RCSW_GRIND_MODE_PERIOD.
- Returns:
-
void grind_report_all(const struct grinder *the_grinder)#
Report stats for all pending instances.
Note
Should only need to be called if RCSW_GRIND_REPORT_AUTO was not passed.
-
status_t grind_report(const struct grinder *the_grinder, struct grindee *grindee)#
Report statistics for a grindee by name.
Report stats for the grindee and then flushes/resets them. The format of the reported stats depends on initialization parameters.
- Returns:
-
status_t grind_report_utilization(const struct grinder *the_grinder)#
Report utilization results to stdout.
Utilization reported in relative or absolute time, depending on flags, and the result written to stdout via DPRINTF.
- Returns:
-
int grind_report_utilization_buf(const struct grinder *the_grinder, char *buf, size_t len)#
Report utilization results to a buffer.
Same content as grind_report_utilization(), written to
bufwith snprintf() semantics: at mostlenbytes (including the terminating NUL) are written, and the output is always NUL-terminated iflen> 0.- Parameters:
the_grinder – The grinder to report on.
buf – The buffer to write to. Can be NULL if
lenis 0.len – Size of
bufin bytes.
- Returns:
The number of characters the full report requires, excluding the terminating NUL. If this is >=
len, the output was truncated; call again with a buffer of at least the returned value + 1. -1 on ERROR.
-
void grind_reset(struct grinder *the_grinder, struct grindee *grindee)#
Reset statistics for a single grindee.
-
int grind_lookup(const struct grinder *the_grinder, const char *name)#
Given the name of a grindee, get the index it maps to.
- Returns:
The index the grindee module name maps to, or -1 on ERROR
-
uint64_t grind_sum_all(const struct grinder *the_grinder)#
Sum ALL grindee datapoints.
Compute the sum of all datapoints for all grindees. It is only a true total if the resolution for grindees is 1. Otherwise it is a sum of the averages according to the resolution parameter.
-
double grind_get_utilization(struct grinder *the_grinder, const char *name)#
Get utilization for a grindee.
For timing-related grinding:
If RCSW_GRIND_INTERVAL passed: utilization is fraction of the timeout interval attributed to the specified grindee. Otherwise it is the fraction of the total amount of time spent by all grindees attributed to the specified grindee.
For counting relating grinding: utilization is the fraction of the total # of execution counts for all grindees attributed to the specified grindee.
- Returns:
The utilization, or -1 on ERROR.
-
struct grindee#
- #include <rcsw/tool/grind.h>
A semantic unit for collecting timing/execution count information.
Can be a function, a section of code, etc. VERY flexible. Identified/differentiated from other grindees by name.
Public Members
-
char name[32]#
Name of grindee
-
size_t count#
How many times the section has been entered since last datapoint
-
size_t tindex#
Location of next datapoint to insert/count of datapoints gathered thus far.
-
bool full#
Flag indicating if the stat table is full
-
uint64_t *table#
Sample table for grindee; all data stored here. Timing datapoints are in nanoseconds; 64 bits so that they do not wrap on 32-bit targets.
-
size_t tsize#
Size of sample table
-
union grindee.grind_mode_impl domain#
-
union grind_mode_impl#
- #include <rcsw/tool/grind.h>
Low-level implementation details for grinder.
There are currently two domains: duration and tick. See grind_mode for details.
Public Members
-
uint64_t accum#
Temporary variable for holding accumulated execution time (ns).
-
struct timespec start#
Duration start time.
-
struct timespec end#
Duration end time.
-
bool active#
The last call to grind_capture_start() has not yet been followed by a call to grind_capture_end() (i.e., grinding is in progress).
-
struct grindee.grind_mode_impl duration#
-
struct timespec current#
Recorded time of current tick
-
bool first#
Is this the first tick capture since last reset?
-
struct grindee.grind_mode_impl tick#
-
uint64_t accum#
-
char name[32]#
-
struct grind_config#
- #include <rcsw/tool/grind.h>
Grinder initialization parameters
Public Members
-
char **names#
Names of grindees
-
size_t n_inst#
Number of grindee names in grind_config::names.
-
uint32_t flags#
Configuration flags. Valid flags are:
All other flags are ignored.
-
enum grind_mode mode#
-
size_t res#
How many collected samples will be averaged to form a single datapoint for each grindee.
-
size_t tsize#
Size of stat table for each grindee (homogeneous)
-
struct timespec interval#
Timeout to reset statistics.
-
struct timespec (*gettime)(void)#
Callback to return the current time for a grindee. If NULL, clock_monotime() is used. Not used in RCSW_GRIND_MODE_COUNT mode.
-
char **names#
-
struct grinder#
- #include <rcsw/tool/grind.h>
Structure for tracking timing, execution count, etc. information gathered about a running application.
Public Members
-
struct grind_config cfg#
The configuration the grinder was initialized with, with grind_config::gettime set to the clock in use. grind_config::names is NULL: the names are copied into the grindees, so the caller’s array is not retained.
-
bool avail#
One or more grindees are ready to report
-
bool in_interval#
That the timeout interval has begun (timing-related modes only)
-
struct timespec interval_start#
Time call to /\ref grind_capture_tick() was made. Used for determining if/when to reset statistics for ALL instances if RCSW_GRIND_INTERVAL was passed.
-
struct grind_config cfg#