1/* 2 * Copyright 2017, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the BSD 2-Clause license. Note that NO WARRANTY is provided. 8 * See "LICENSE_BSD2.txt" for details. 9 * 10 * @TAG(DATA61_BSD) 11 */ 12 13#include <sel4utils/profile.h> 14#include <stdio.h> 15#include <inttypes.h> 16 17/* 18 * __start_SECTION_NAME and __stop_SECTION_NAME are magic symbols inserted by the gcc 19 * linker 20 */ 21extern profile_var_t __start__profile_var[]; 22extern profile_var_t __stop__profile_var[]; 23 24void profile_print32(uint32_t value, const char *varname, const char *description, void *cookie) 25{ 26 printf("%s: %"PRIu32" %s\n", varname, value, description); 27} 28void profile_print64(uint64_t value, const char *varname, const char *description, void *cookie) 29{ 30 printf("%s: %"PRIu64" %s\n", varname, value, description); 31} 32 33void profile_scrape(profile_callback32 callback32, profile_callback64 callback64, void *cookie) 34{ 35 for (profile_var_t *i = __start__profile_var; i < __stop__profile_var; i++) { 36 switch (i->type) { 37 case PROFILE_VAR_TYPE_INT32: 38 callback32(*(uint32_t*)i->var, i->varname, i->description, cookie); 39 break; 40 case PROFILE_VAR_TYPE_INT64: 41 callback64(*(uint64_t*)i->var, i->varname, i->description, cookie); 42 break; 43 default: 44 ZF_LOGE("Unknown profile var. Probable memory corruption or linker failure!"); 45 break; 46 } 47 } 48} 49 50void profile_reset(void) 51{ 52 for (profile_var_t *i = __start__profile_var; i < __stop__profile_var; i++) { 53 switch (i->type) { 54 case PROFILE_VAR_TYPE_INT32: 55 *(uint32_t*)i->var = 0; 56 break; 57 case PROFILE_VAR_TYPE_INT64: 58 *(uint64_t*)i->var = 0; 59 break; 60 default: 61 ZF_LOGE("Unknown profile var. Probable memory corruption or linker failure!"); 62 break; 63 } 64 } 65} 66