Skip to content

Commit

Permalink
trigger_utils: add tstat log
Browse files Browse the repository at this point in the history
Add a tstat log function for logging timing statistics using rtlog
  • Loading branch information
kmarkus committed Jan 6, 2020
1 parent 9df12bb commit 930ca5a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions libubx/trig_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "trig_utils.h"

static const char* log_fmt = "cnt: %lu, min: %11.9f, max: %11.9f, avg: %11.9f\n";

/**
* initialise a tstat structure
*/
Expand Down Expand Up @@ -89,3 +91,24 @@ void tstat_print(const char *profile_path, struct ubx_tstat *stats)
if (fp)
fclose(fp);
}

/**
* log timing statistics
*/
void tstat_log(const ubx_node_info_t *ni, const struct ubx_tstat *stats)
{
struct ubx_timespec avg;

if (stats->cnt == 0) {
ubx_log(UBX_LOGLEVEL_INFO, ni, stats->block_name, "cnt: 0 - no statistics aquired");
return;
}
ubx_ts_div(&stats->total, stats->cnt, &avg);

ubx_log(UBX_LOGLEVEL_INFO, ni, stats->block_name,
log_fmt,
stats->cnt,
ubx_ts_to_double(&stats->min),
ubx_ts_to_double(&stats->max),
ubx_ts_to_double(&avg));
}
2 changes: 2 additions & 0 deletions libubx/trig_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ void tstat_update(struct ubx_tstat *stats,
struct ubx_timespec *start,
struct ubx_timespec *end);
void tstat_print(const char *profile_path, struct ubx_tstat *stats);

void tstat_log(const ubx_node_info_t *ni, const struct ubx_tstat *stats);

0 comments on commit 930ca5a

Please sign in to comment.