tests: Test parametric per-user syntax for hide/veto files
[samba4-gss.git] / examples / perfcounter / perf.h
blob03b544846c5268a8e7deac9cbfbfa1afd13fcbef
1 /*
2 * Unix SMB/CIFS implementation.
3 * Performance Counter Daemon
5 * Copyright (C) Marcin Krzysztof Porwit 2005
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #ifndef __PERF_H__
22 #define __PERF_H__
24 #define _PUBLIC_
26 #ifdef HAVE_STDBOOL_H
27 #include <stdbool.h>
28 #endif
30 #if !defined(HAVE_BOOL)
31 #ifdef HAVE__Bool
32 #define bool _Bool
33 #else
34 #error Need a real boolean type
35 #endif
36 #endif
39 #include <stdlib.h>
40 #include <time.h>
41 #include <math.h>
42 #include <stdio.h>
43 #include <fcntl.h>
44 #include <unistd.h>
45 #include <string.h>
46 #include <fcntl.h>
47 #include <signal.h>
48 #include <stdarg.h>
49 #include <sys/mman.h>
50 #include <sys/stat.h>
51 #include <sys/time.h>
52 #include <sys/wait.h>
53 #include <limits.h>
54 #include <tdb.h>
55 #include "librpc/gen_ndr/perfcount.h"
56 #include <sys/statfs.h>
57 #include <sys/times.h>
58 #include <sys/sysinfo.h>
60 #define NUM_COUNTERS 10
62 #define NAME_LEN 256
63 #define HELP_LEN 1024
65 #define PERF_OBJECT 0
66 #define PERF_INSTANCE 1
67 #define PERF_COUNTER 2
69 #define FALSE 0
70 #define TRUE !FALSE
72 #define PROC_BUF 256
73 #define LARGE_BUF 16384
75 typedef struct perf_counter
77 int index;
78 char name[NAME_LEN];
79 char help[HELP_LEN];
80 char relationships[NAME_LEN];
81 unsigned int counter_type;
82 int record_type;
83 } PerfCounter;
85 typedef struct mem_data
87 unsigned int availPhysKb;
88 unsigned int availSwapKb;
89 unsigned int totalPhysKb;
90 unsigned int totalSwapKb;
91 } MemData;
93 typedef struct mem_info
95 PerfCounter memObjDesc;
96 PerfCounter availPhysKb;
97 PerfCounter availSwapKb;
98 PerfCounter totalPhysKb;
99 PerfCounter totalSwapKb;
100 MemData *data;
101 } MemInfo;
103 typedef struct cpu_data
105 unsigned long long user;
106 unsigned long long nice;
107 unsigned long long system;
108 unsigned long long idle;
109 } CPUData;
111 typedef struct cpu_info
113 unsigned int numCPUs;
114 PerfCounter cpuObjDesc;
115 PerfCounter userCPU;
116 PerfCounter niceCPU;
117 PerfCounter systemCPU;
118 PerfCounter idleCPU;
119 CPUData *data;
120 } CPUInfo;
122 typedef struct disk_meta_data
124 char name[NAME_LEN];
125 char mountpoint[NAME_LEN];
126 } DiskMetaData;
128 typedef struct disk_data
130 unsigned long long freeMegs;
131 unsigned int writesPerSec;
132 unsigned int readsPerSec;
133 } DiskData;
135 typedef struct disk_info
137 unsigned int numDisks;
138 DiskMetaData *mdata;
139 PerfCounter diskObjDesc;
140 PerfCounter freeMegs;
141 PerfCounter writesPerSec;
142 PerfCounter readsPerSec;
143 DiskData *data;
144 } DiskInfo;
146 typedef struct process_data
148 unsigned int runningProcessCount;
149 } ProcessData;
151 typedef struct process_info
153 PerfCounter processObjDesc;
154 PerfCounter runningProcessCount;
155 ProcessData *data;
156 } ProcessInfo;
158 typedef struct perf_data_block
160 unsigned int counter_id;
161 unsigned int num_counters;
162 unsigned int NumObjectTypes;
163 unsigned long long PerfTime;
164 unsigned long long PerfFreq;
165 unsigned long long PerfTime100nSec;
166 MemInfo memInfo;
167 CPUInfo cpuInfo;
168 ProcessInfo processInfo;
169 DiskInfo diskInfo;
170 } PERF_DATA_BLOCK;
172 typedef struct runtime_settings
174 /* Runtime flags */
175 int dflag;
176 /* DB path names */
177 char dbDir[PATH_MAX];
178 char nameFile[PATH_MAX];
179 char counterFile[PATH_MAX];
180 /* TDB context */
181 TDB_CONTEXT *cnames;
182 TDB_CONTEXT *cdata;
183 } RuntimeSettings;
185 /* perf_writer_ng_util.c function prototypes */
186 void fatal(char *msg);
187 void add_key(TDB_CONTEXT *db, char *keystring, char *datastring, int flags);
188 void add_key_raw(TDB_CONTEXT *db, char *keystring, void *datastring, size_t datasize, int flags);
189 void make_key(char *buf, int buflen, int key_part1, char *key_part2);
190 void parse_flags(RuntimeSettings *rt, int argc, char **argv);
191 void setup_file_paths(RuntimeSettings *rt);
192 void daemonize(RuntimeSettings *rt);
194 /* perf_writer_ng_mem.c function prototypes */
195 void get_meminfo(PERF_DATA_BLOCK *data);
196 void init_memdata_desc(PERF_DATA_BLOCK *data);
197 void init_memdata(PERF_DATA_BLOCK *data);
198 void output_mem_desc(PERF_DATA_BLOCK *data, RuntimeSettings rt);
199 void output_meminfo(PERF_DATA_BLOCK *data, RuntimeSettings rt, int tdb_flags);
200 void init_perf_counter(PerfCounter *counter, PerfCounter *parent, unsigned int index, char *name, char *help, int counter_type, int record_type);
202 /* perf_writer_ng_cpu.c function prototypes */
203 unsigned long long get_cpufreq();
204 void init_cpudata_desc(PERF_DATA_BLOCK *data);
205 void get_cpuinfo(PERF_DATA_BLOCK *data);
206 void init_cpu_data(PERF_DATA_BLOCK *data);
207 void output_cpu_desc(PERF_DATA_BLOCK *data, RuntimeSettings rt);
208 void output_cpuinfo(PERF_DATA_BLOCK *data, RuntimeSettings rt, int tdb_flags);
210 #endif /* __PERF_H__ */