1 /*
2 ** Zabbix
3 ** Copyright (C) 2001-2021 Zabbix SIA
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 **/
19 
20 #ifndef ZABBIX_CPUSTAT_H
21 #define ZABBIX_CPUSTAT_H
22 
23 #include "sysinfo.h"
24 #include "zbxalgo.h"
25 
26 #ifdef _WINDOWS
27 #	include "perfmon.h"
28 
29 typedef struct
30 {
31 	PERF_COUNTER_DATA	**cpu_counter;
32 	PERF_COUNTER_DATA	*queue_counter;
33 	int			count;
34 }
35 ZBX_CPUS_STAT_DATA;
36 
37 #define CPU_COLLECTOR_STARTED(collector)	((collector) && (collector)->cpus.queue_counter)
38 
39 int	get_cpu_perf_counter_value(int cpu_num, int interval, double *value, char **error);
40 
41 #else	/* not _WINDOWS */
42 
43 typedef struct
44 {
45 	zbx_uint64_t	h_counter[ZBX_CPU_STATE_COUNT][MAX_COLLECTOR_HISTORY];
46 	unsigned char	h_status[MAX_COLLECTOR_HISTORY];
47 #if (MAX_COLLECTOR_HISTORY % 8) > 0
48 	unsigned char	padding0[8 - (MAX_COLLECTOR_HISTORY % 8)];	/* for 8-byte alignment */
49 #endif
50 	int		h_first;
51 	int		h_count;
52 	int		cpu_num;
53 	int		padding1;	/* for 8-byte alignment */
54 }
55 ZBX_SINGLE_CPU_STAT_DATA;
56 
57 typedef struct
58 {
59 	ZBX_SINGLE_CPU_STAT_DATA	*cpu;
60 	int				count;
61 }
62 ZBX_CPUS_STAT_DATA;
63 
64 #define CPU_COLLECTOR_STARTED(collector)	(collector)
65 
66 void	collect_cpustat(ZBX_CPUS_STAT_DATA *pcpus);
67 int	get_cpustat(AGENT_RESULT *result, int cpu_num, int state, int mode);
68 
69 #endif	/* _WINDOWS */
70 
71 int	init_cpu_collector(ZBX_CPUS_STAT_DATA *pcpus);
72 void	free_cpu_collector(ZBX_CPUS_STAT_DATA *pcpus);
73 
74 #define ZBX_CPUNUM_UNDEF	-1	/* unidentified yet CPUs */
75 #define ZBX_CPUNUM_ALL		-2	/* request data for all CPUs */
76 
77 #define ZBX_CPU_STATUS_ONLINE	0
78 #define ZBX_CPU_STATUS_OFFLINE	1
79 #define ZBX_CPU_STATUS_UNKNOWN	2
80 
81 int	get_cpus(zbx_vector_uint64_pair_t *vector);
82 
83 #endif
84