typedef int64_t profile_value;
struct profile
{
ProfileVTable vtable;
/*
Using trylock for sampling makes it never contend on the lock but some
samples are lost. Should be ok.
*/
mutex_t lock; /* with trylock? */
/* statistics / running averages */
/* n being a small number 2-5 or so */
profile_value max[n]; /* n maximum values seen so far,
decreased by recovery */
profile_value min[n]; /* n minimum values seen so far,
increased by recovery */
/* store sum & count, but average calculation implies a division and will be
only done on demand */
profile_value count; /* count profile calls */
profile_value sum; /* sum up all calls, average =
sum/count */
/* current is the sampled value to be integrated */
/* trend is caclulated before theb new run_average */
profile_value trend; /* trend = (trend +
(run_average-current))>>1 */
/* we may need some slower diverging formula for running average */
profile_value run_average; /* run_average = (run_average +
current)>>1) */
/* active limits, define whats good and whats bad, calls back to vtable when
limit is hit */
profile_value max_limit;
profile_value min_limit;
/* do we want limits for trends too? */
/* we count how often we hit limits, a hit/miss ratio will give a good value
for optimization */
profile_value hit_cnt;
profile_value high_miss_cnt;
profile_value low_miss_cnt;
/* recovery state */
int rec_init;
int rec_current;
int rec_percent;
void* extra;
};