-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstatistic.h
195 lines (173 loc) · 5.42 KB
/
statistic.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
* Copyright (c) 2008 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* The contents of this file constitute Original Code as defined in and
* are subject to the Apple Public Source License Version 1.1 (the
* "License"). You may not use this file except in compliance with the
* License. Please obtain a copy of the License at
* http://www.apple.com/publicsource and read it before using this file.
*
* This Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef STATISTIC_H
#define STATISTIC_H
#include <curses.h>
#include <inttypes.h>
#include <panel.h>
#include <stdbool.h>
#include <stdio.h>
/*
* Extend this if we add another type.
*
* These types are used for sorting, and priority of display. Make sure to add
* a matching entry to statistic_name_map in statistic.c.
*/
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 /* defined(TOP_ANONYMOUS_MEMORY) */
STATISTIC_RPRVT,
STATISTIC_RSHRD,
STATISTIC_RSIZE,
#endif /* !defined(TOP_ANONYMOUS_MEMORY) */
STATISTIC_VSIZE,
/* end of entries in same order as old top */
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_JETSAM_PRI,
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 {
/* This provides a destructor that may be called to cleanup a statistic. */
void (*destructor)(struct statistic *s, void *ptr);
/* This is passed to the callback stored above. */
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; /* The STATISTIC enum type from above. */
void *cells; /* This usually stores a struct generic_cell. */
void *ptr; /* This is for private data created at the time of
* create_statistic.
*/
char *header;
bool visible;
struct statistics_controller *controller;
/* Used for profiling: */
uint64_t time_consumed;
uint64_t runs;
struct statistic_callbacks callbacks;
struct statistic_destructor *destructors;
struct statistic_size request_size; /* Used with get_request_size */
struct statistic_size actual_size;
struct statistic_size minimum_size;
struct statistic *previous, *next;
};
/* This should be called before any of the functions below: */
struct statistics_controller *create_statistics_controller(WINDOW *parent);
/*
* This takes a STATISTIC_ enum type from above, a WINDOW parent for a derwin,
* and a pointer of some sort (if desired for extra data).
*
* This returns NULL when an error occurs.
*/
struct statistic *create_statistic(int type, WINDOW *parent, void *ptr,
struct statistic_callbacks *callbacks, const char *name);
/*
* This destroys the statistic and calls any destructors necessary.
*/
void destroy_statistic(struct statistic *s);
/*
* This creates a callback that is invoked when destroy_statistic is called.
*
* This returns true when an error occurs.
*/
bool create_statistic_destructor(
struct statistic *s, void (*destructor)(struct statistic *, void *), void *ptr);
#endif /*STATISTIC_H*/