[go: up one dir, main page]

File: hyptop.h

package info (click to toggle)
s390-tools 2.35.0-1
  • links: PTS
  • area: main
  • in suites: trixie
  • size: 12,220 kB
  • sloc: ansic: 184,236; sh: 12,152; cpp: 4,954; makefile: 2,763; perl: 2,519; asm: 1,085; python: 697; xml: 29
file content (225 lines) | stat: -rw-r--r-- 4,390 bytes parent folder | download | duplicates (2)
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
 * hyptop - Show hypervisor performance data on System z
 *
 * Command line options, window definition, print functions, etc.
 *
 * Copyright IBM Corp. 2010, 2017
 *
 * s390-tools is free software; you can redistribute it and/or modify
 * it under the terms of the MIT license. See LICENSE for details.
 */

#ifndef HYPTOP_H
#define HYPTOP_H

#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>

#include "helper.h"
#include "nav_desc.h"
#include "table.h"

#define HYPTOP_OPT_DEFAULT_DELAY	2
#define HYPTOP_OPT_DEFAULT_SMT_SCALE	1.3
#define HYPTOP_MAX_WIN_DEPTH		4
#define HYPTOP_MAX_LINE			512
#define PROG_NAME			"hyptop"

/*
 * Options info
 */
struct hyptop_str_vec_opt {
	unsigned int		specified;
	char			**vec;
	unsigned int		cnt;
};

struct hyptop_col_vec_opt {
	unsigned int		specified;
	struct table_col_spec	**vec;
	unsigned int		cnt;
};

struct hyptop_win_opts {
	struct hyptop_str_vec_opt	sys;
	struct hyptop_col_vec_opt	fields;
	unsigned int			sort_field_specified;
	char				sort_field;
};

struct hyptop_opts {
	unsigned int			win_specified;
	unsigned int			batch_mode_specified;
	unsigned int			iterations_specified;
	unsigned int			iterations;
	unsigned int			iterations_act;

	struct hyptop_win		*cur_win;
	struct hyptop_str_vec_opt	cpu_types;

	int				delay_s;
	int				delay_us;

	double				smt_factor;
};

/*
 * Curses info
 */
struct hyptop_curses {
	int			row_cnt;
	int			col_cnt;
	char			line[HYPTOP_MAX_LINE];
	int			x;
	int			y;
	int			initialized;
};

/*
 * Window info
 */
struct hyptop_win_info {
	struct hyptop_win	*cur;
	struct hyptop_win	*prev[HYPTOP_MAX_WIN_DEPTH];
	unsigned int		prev_cnt;
};

/*
 * Globals definition
 */
struct hyptop_globals {
	struct hyptop_opts	o;
	struct hyptop_curses	c;
	struct hyptop_win_info	w;
	const char		*prog_name;
	struct hyptop_win	*win_cpu_types;
};

extern struct hyptop_globals g;

/*
 * Print functions
 */
#define hyptop_printf_pos(y, x, p...) \
	do { \
		if (g.o.batch_mode_specified) \
			printf(p); \
		else { \
			int len; \
			len = snprintf(g.c.line, sizeof(g.c.line) - 1, p); \
			len = MIN(len, (g.c.col_cnt - (x))); \
			if (len > 0) { \
				mvaddnstr((y), (x), g.c.line, len); \
			} \
		} \
	} while (0)

#define hyptop_printf(p...) \
	do { \
		if (g.o.batch_mode_specified) \
			printf(p); \
		else { \
			int len; \
			len = snprintf(g.c.line, sizeof(g.c.line) - 1, p); \
			len = MIN(len, (g.c.col_cnt - g.c.x)); \
			if (len > 0) { \
				mvaddnstr(g.c.y, g.c.x, g.c.line, len); \
				g.c.x += len; \
			} \
		} \
	} while (0)

static inline void hyptop_printf_init(void)
{
	g.c.x = 0;
	g.c.y = 0;
}

static inline void hyptop_print_seek_back(int i)
{
	unsigned int cnt = MAX(g.c.col_cnt - g.c.x - i, 0);

	if (g.o.batch_mode_specified)
		return;
	if (cnt) {
		memset(g.c.line, ' ', cnt);
		assert(cnt < sizeof(g.c.line));
		g.c.line[cnt] = 0;
		addstr(g.c.line);
	}
	g.c.x = g.c.col_cnt - i;
}

static inline void hyptop_print_nl(void)
{
	unsigned int cnt = MAX(g.c.col_cnt - g.c.x, 0);

	if (g.o.batch_mode_specified) {
		printf("\n");
		return;
	}
	if (cnt) {
		memset(g.c.line, ' ', g.c.col_cnt - g.c.x);
		assert(cnt < sizeof(g.c.line));
		g.c.line[cnt] = 0;
		addstr(g.c.line);
	}
	g.c.x = 0;
	g.c.y++;
}

/*
 * hyptop windows
 */

enum hyptop_win_action {
	WIN_SWITCH,
	WIN_KEEP,
};

extern enum hyptop_win_action hyptop_process_input_timeout(void);
extern enum hyptop_win_action hyptop_process_input(void);
extern enum hyptop_win_action win_switch(struct hyptop_win *w);
extern enum hyptop_win_action win_back(void);

struct hyptop_win;
struct hyptop_win {
	enum hyptop_win_action	(*process_input)(struct hyptop_win *w, int c);
	void			(*update_term)(struct hyptop_win *w);
	void			(*run)(struct hyptop_win *w);
	const char		*id;
	const char		*desc;
	struct nav_desc		**desc_normal_vec;
	struct nav_desc		**desc_select_vec;
	struct nav_desc		**desc_general_vec;
	struct hyptop_win_opts	opts;
};

/*
 * Window sys_list
 */
extern struct hyptop_win win_sys_list;
extern void win_sys_list_init(void);

/*
 * Window sys
 */
extern struct hyptop_win win_sys;
extern void win_sys_set(const char *sys_id);
extern void win_sys_init(void);

/*
 * Window cpu_types
 */
extern void win_cpu_types_init(void);

/*
 * Misc functions
 */
extern void hyptop_update_term(void);
extern void __noreturn hyptop_exit(int rc);
extern void hyptop_text_mode(void);

#endif /* HYPTOP_H */