#include "obj.h"
#include "stats.h"
STATS_CTL_HANDLER(persistent, curr_allocated, heap_curr_allocated);
static const struct ctl_node CTL_NODE(heap)[] = {
STATS_CTL_LEAF(persistent, curr_allocated),
CTL_NODE_END
};
static int
CTL_READ_HANDLER(enabled)(PMEMobjpool *pop,
enum ctl_query_source source, void *arg,
struct ctl_indexes *indexes)
{
int *arg_out = arg;
*arg_out = pop->stats->enabled;
return 0;
}
static int
CTL_WRITE_HANDLER(enabled)(PMEMobjpool *pop,
enum ctl_query_source source, void *arg,
struct ctl_indexes *indexes)
{
int arg_in = *(int *)arg;
pop->stats->enabled = arg_in;
return 0;
}
static struct ctl_argument CTL_ARG(enabled) = CTL_ARG_BOOLEAN;
static const struct ctl_node CTL_NODE(stats)[] = {
CTL_CHILD(heap),
CTL_LEAF_RW(enabled),
CTL_NODE_END
};
struct stats *
stats_new(PMEMobjpool *pop)
{
struct stats *s = Malloc(sizeof(*s));
s->enabled = 0;
s->persistent = &pop->stats_persistent;
s->transient = Zalloc(sizeof(struct stats_transient));
if (s->transient == NULL)
goto error_transient_alloc;
return s;
error_transient_alloc:
Free(s);
return NULL;
}
void
stats_delete(PMEMobjpool *pop, struct stats *s)
{
pmemops_persist(&pop->p_ops, s->persistent,
sizeof(struct stats_persistent));
Free(s->transient);
Free(s);
}
void
stats_ctl_register(PMEMobjpool *pop)
{
CTL_REGISTER_MODULE(pop->ctl, stats);
}