Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Commit

Permalink
fwk/trace: add calculate overhead function
Browse files Browse the repository at this point in the history
Add a function which roughly estimate the overhead of tracing by calling
a FWK_TRACE_START followed by FWK_TRACE_FINISH and calculating how long
the empty trace took.

Signed-off-by: Mohamed Omar Asaker <[email protected]>
  • Loading branch information
mohamedasaker-arm committed Aug 9, 2024
1 parent 3d6478a commit a6a4be9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 14 additions & 0 deletions framework/include/fwk_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
#define FWK_TRACE_FINISH(ID, MSG) \
fwk_trace_finish(__FILE__, __func__, __LINE__, ID, MSG)

/*!
* \brief Calculate the trace overhead.
*
* \return Tracing overhead.
*/
#define FWK_TRACE_CALC_OVERHEAD() fwk_trace_calc_overhead()

typedef uint64_t fwk_trace_count_t;
typedef uint32_t fwk_trace_id_t;
#define PRItraceid PRIu32
Expand Down Expand Up @@ -84,6 +91,13 @@ struct fwk_trace_driver {
*/
void fwk_trace_init(void);

/*!
* \brief Calculate the trace overhead.
*
* \return Tracing overhead.
*/
fwk_trace_count_t fwk_trace_calc_overhead(void);

/*!
* \brief Start trace of an event.
*
Expand Down
14 changes: 12 additions & 2 deletions framework/src/fwk_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ FWK_CONSTRUCTOR void fwk_trace_init(void)
(void)fwk_str_memcpy(&fwk_trace_ctx.driver, &driver, sizeof(driver));
if (fwk_trace_ctx.driver.trace_entry_count != 0) {
fwk_trace_ctx.start_timestamp = fwk_mm_calloc(
fwk_trace_ctx.driver.trace_entry_count, sizeof(fwk_trace_count_t));
fwk_trace_ctx.driver.trace_entry_count + 1,
sizeof(fwk_trace_count_t));
fwk_trace_ctx.entry_pending = fwk_mm_calloc(
fwk_trace_ctx.driver.trace_entry_count, sizeof(fwk_trace_count_t));
fwk_trace_ctx.driver.trace_entry_count + 1,
sizeof(fwk_trace_count_t));
}
}

Expand All @@ -39,6 +41,14 @@ static inline fwk_trace_count_t calc_delta(
((fwk_trace_count_t)(-1) - start + end);
}

fwk_trace_count_t fwk_trace_calc_overhead(void)
{
fwk_trace_count_t start = fwk_trace_ctx.driver.get_trace_count();
(void)FWK_TRACE_START(fwk_trace_ctx.driver.trace_entry_count);
(void)FWK_TRACE_FINISH(fwk_trace_ctx.driver.trace_entry_count, "");
return calc_delta(start, fwk_trace_ctx.driver.get_trace_count());
}

int fwk_trace_start(fwk_trace_id_t id)
{
if (id >= fwk_trace_ctx.driver.trace_entry_count) {
Expand Down

0 comments on commit a6a4be9

Please sign in to comment.