#ifndef STATISTIC_H
#define STATISTIC_H
#include <stdio.h>
#include <inttypes.h>
#include <curses.h>
#include <panel.h>
#include <stdbool.h>
enum {
STATISTIC_PID, STATISTIC_COMMAND, STATISTIC_CPU, STATISTIC_CPU_ME,
STATISTIC_CPU_OTHERS, STATISTIC_BOOSTS, STATISTIC_TIME,
STATISTIC_THREADS, STATISTIC_PORTS, STATISTIC_MREGION,
#ifdef TOP_ANONYMOUS_MEMORY
STATISTIC_PMEM, STATISTIC_RPRVT, STATISTIC_PURG, STATISTIC_COMPRESSED,
#else
STATISTIC_RPRVT, STATISTIC_RSHRD, STATISTIC_RSIZE,
#endif
STATISTIC_VSIZE,
STATISTIC_VPRVT,
STATISTIC_INSTRS, STATISTIC_CYCLES,
STATISTIC_PGRP, STATISTIC_PPID, STATISTIC_PSTATE,
STATISTIC_UID, STATISTIC_WORKQUEUE, STATISTIC_FAULTS, STATISTIC_COW_FAULTS,
STATISTIC_MESSAGES_SENT, STATISTIC_MESSAGES_RECEIVED, STATISTIC_SYSBSD,
STATISTIC_SYSMACH, STATISTIC_CSW, STATISTIC_PAGEINS, STATISTIC_KPRVT, STATISTIC_KSHRD,
STATISTIC_IDLEWAKE,
STATISTIC_POWERSCORE,
STATISTIC_USER,
NUM_STATISTICS,
};
struct statistic;
struct statistics_controller;
struct statistic_name_map {
int e;
struct statistic *(*creator)(WINDOW *parent, const char *name);
const char *name;
};
extern struct statistic_name_map statistic_name_map[];
struct statistic_state {
int type;
char name[50];
struct statistic *(*create_statistic)(WINDOW *parent, const char *name);
struct statistic *instance;
};
struct statistics_controller {
void *globalstats;
WINDOW *parent;
struct statistic_state state[NUM_STATISTICS];
int total_possible_statistics;
int total_active_statistics;
void (*reset_insertion)(struct statistics_controller *c);
void (*insert_sample)(struct statistics_controller *c, const void *sample);
void (*remove_tail)(struct statistics_controller *c);
void (*insert_tail)(struct statistics_controller *c);
int (*get_total_possible)(struct statistics_controller *c);
int (*get_total_active)(struct statistics_controller *c);
void (*iterate)(struct statistics_controller *c,
bool (*func)(struct statistic *, void *),
void *ptr);
};
struct statistic_size {
int width, height;
};
struct statistic_destructor {
void (*destructor) (struct statistic *s, void *ptr);
void *ptr;
struct statistic_destructor *next;
};
struct statistic_callbacks {
void (*draw) (struct statistic *s, int x);
bool (*resize_cells) (struct statistic *s, struct statistic_size *size);
bool (*move_cells) (struct statistic *s, int x, int y);
void (*get_request_size) (struct statistic *s);
void (*get_minimum_size) (struct statistic *s);
bool (*insert_cell) (struct statistic *s, const void *sample);
void (*reset_insertion) (struct statistic *s);
};
struct statistic {
WINDOW *parent;
WINDOW *window;
PANEL *panel;
int type;
void *cells;
void *ptr;
char *header;
bool visible;
struct statistics_controller *controller;
uint64_t time_consumed;
uint64_t runs;
struct statistic_callbacks callbacks;
struct statistic_destructor *destructors;
struct statistic_size request_size;
struct statistic_size actual_size;
struct statistic_size minimum_size;
struct statistic *previous, *next;
};
struct statistics_controller *create_statistics_controller(WINDOW *parent);
struct statistic *create_statistic(int type, WINDOW *parent, void *ptr,
struct statistic_callbacks *callbacks,
const char *name);
void destroy_statistic(struct statistic *s);
bool create_statistic_destructor(struct statistic *s,
void (*destructor) (struct statistic *, void *),
void *ptr);
#endif