blob: bb4d389f4df94add48acd95e5e41b5fc59300164 [file] [log] [blame]
/*
* Copyright 2017, Data61, CSIRO (ABN 41 687 119 230)
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <sel4utils/profile.h>
#include <stdio.h>
#include <inttypes.h>
/*
* __start_SECTION_NAME and __stop_SECTION_NAME are magic symbols inserted by the gcc
* linker
*/
extern profile_var_t __start__profile_var[];
extern profile_var_t __stop__profile_var[];
void profile_print32(uint32_t value, const char *varname, const char *description, void *cookie)
{
printf("%s: %"PRIu32" %s\n", varname, value, description);
}
void profile_print64(uint64_t value, const char *varname, const char *description, void *cookie)
{
printf("%s: %"PRIu64" %s\n", varname, value, description);
}
void profile_scrape(profile_callback32 callback32, profile_callback64 callback64, void *cookie)
{
for (profile_var_t *i = __start__profile_var; i < __stop__profile_var; i++) {
switch (i->type) {
case PROFILE_VAR_TYPE_INT32:
callback32(*(uint32_t*)i->var, i->varname, i->description, cookie);
break;
case PROFILE_VAR_TYPE_INT64:
callback64(*(uint64_t*)i->var, i->varname, i->description, cookie);
break;
default:
ZF_LOGE("Unknown profile var. Probable memory corruption or linker failure!");
break;
}
}
}
void profile_reset(void)
{
for (profile_var_t *i = __start__profile_var; i < __stop__profile_var; i++) {
switch (i->type) {
case PROFILE_VAR_TYPE_INT32:
*(uint32_t*)i->var = 0;
break;
case PROFILE_VAR_TYPE_INT64:
*(uint64_t*)i->var = 0;
break;
default:
ZF_LOGE("Unknown profile var. Probable memory corruption or linker failure!");
break;
}
}
}