Samba 3: added Samba 3.0.24 sources
[tomato.git] / release / src / router / samba3 / examples / perfcounter / perf.h
blob7279e788310361c46a2ac6b3af4bd14ad7cf537a
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 2 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, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #ifndef __PERF_H__
23 #define __PERF_H__
25 #include <stdlib.h>
26 #include <time.h>
27 #include <math.h>
28 #include <stdio.h>
29 #include <fcntl.h>
30 #include <unistd.h>
31 #include <string.h>
32 #include <fcntl.h>
33 #include <signal.h>
34 #include <stdarg.h>
35 #include <sys/mman.h>
36 #include <sys/stat.h>
37 #include <sys/time.h>
38 #include <sys/wait.h>
39 #include <limits.h>
40 #include "tdb.h"
41 #include <rpc_perfcount_defs.h>
42 #include <sys/statfs.h>
43 #include <sys/times.h>
44 #include <sys/sysinfo.h>
46 #define NUM_COUNTERS 10
48 #define NAME_LEN 256
49 #define HELP_LEN 1024
51 #define PERF_OBJECT 0
52 #define PERF_INSTANCE 1
53 #define PERF_COUNTER 2
55 #define FALSE 0
56 #define TRUE !FALSE
58 #define PROC_BUF 256
59 #define LARGE_BUF 16384
61 typedef struct perf_counter
63 int index;
64 char name[NAME_LEN];
65 char help[HELP_LEN];
66 char relationships[NAME_LEN];
67 unsigned int counter_type;
68 int record_type;
69 } PerfCounter;
71 typedef struct mem_data
73 unsigned int availPhysKb;
74 unsigned int availSwapKb;
75 unsigned int totalPhysKb;
76 unsigned int totalSwapKb;
77 } MemData;
79 typedef struct mem_info
81 PerfCounter memObjDesc;
82 PerfCounter availPhysKb;
83 PerfCounter availSwapKb;
84 PerfCounter totalPhysKb;
85 PerfCounter totalSwapKb;
86 MemData *data;
87 } MemInfo;
89 typedef struct cpu_data
91 unsigned long long user;
92 unsigned long long nice;
93 unsigned long long system;
94 unsigned long long idle;
95 } CPUData;
97 typedef struct cpu_info
99 unsigned int numCPUs;
100 PerfCounter cpuObjDesc;
101 PerfCounter userCPU;
102 PerfCounter niceCPU;
103 PerfCounter systemCPU;
104 PerfCounter idleCPU;
105 CPUData *data;
106 } CPUInfo;
108 typedef struct disk_meta_data
110 char name[NAME_LEN];
111 char mountpoint[NAME_LEN];
112 } DiskMetaData;
114 typedef struct disk_data
116 unsigned long long freeMegs;
117 unsigned int writesPerSec;
118 unsigned int readsPerSec;
119 } DiskData;
121 typedef struct disk_info
123 unsigned int numDisks;
124 DiskMetaData *mdata;
125 PerfCounter diskObjDesc;
126 PerfCounter freeMegs;
127 PerfCounter writesPerSec;
128 PerfCounter readsPerSec;
129 DiskData *data;
130 } DiskInfo;
132 typedef struct process_data
134 unsigned int runningProcessCount;
135 } ProcessData;
137 typedef struct process_info
139 PerfCounter processObjDesc;
140 PerfCounter runningProcessCount;
141 ProcessData *data;
142 } ProcessInfo;
144 typedef struct perf_data_block
146 unsigned int counter_id;
147 unsigned int num_counters;
148 unsigned int NumObjectTypes;
149 unsigned long long PerfTime;
150 unsigned long long PerfFreq;
151 unsigned long long PerfTime100nSec;
152 MemInfo memInfo;
153 CPUInfo cpuInfo;
154 ProcessInfo processInfo;
155 DiskInfo diskInfo;
156 } PERF_DATA_BLOCK;
158 typedef struct runtime_settings
160 /* Runtime flags */
161 int dflag;
162 /* DB path names */
163 char dbDir[PATH_MAX];
164 char nameFile[PATH_MAX];
165 char counterFile[PATH_MAX];
166 /* TDB context */
167 TDB_CONTEXT *cnames;
168 TDB_CONTEXT *cdata;
169 } RuntimeSettings;
171 /* perf_writer_ng_util.c function prototypes */
172 void fatal(char *msg);
173 void add_key(TDB_CONTEXT *db, char *keystring, char *datastring, int flags);
174 void add_key_raw(TDB_CONTEXT *db, char *keystring, void *datastring, size_t datasize, int flags);
175 void make_key(char *buf, int buflen, int key_part1, char *key_part2);
176 void parse_flags(RuntimeSettings *rt, int argc, char **argv);
177 void setup_file_paths(RuntimeSettings *rt);
178 void daemonize(RuntimeSettings *rt);
180 /* perf_writer_ng_mem.c function prototypes */
181 void get_meminfo(PERF_DATA_BLOCK *data);
182 void init_memdata_desc(PERF_DATA_BLOCK *data);
183 void init_memdata(PERF_DATA_BLOCK *data);
184 void output_mem_desc(PERF_DATA_BLOCK *data, RuntimeSettings rt);
185 void output_meminfo(PERF_DATA_BLOCK *data, RuntimeSettings rt, int tdb_flags);
186 void init_perf_counter(PerfCounter *counter, PerfCounter *parent, unsigned int index, char *name, char *help, int counter_type, int record_type);
188 /* perf_writer_ng_cpu.c function prototypes */
189 unsigned long long get_cpufreq();
190 void init_cpudata_desc(PERF_DATA_BLOCK *data);
191 void get_cpuinfo(PERF_DATA_BLOCK *data);
192 void init_cpu_data(PERF_DATA_BLOCK *data);
193 void output_cpu_desc(PERF_DATA_BLOCK *data, RuntimeSettings rt);
194 void output_cpuinfo(PERF_DATA_BLOCK *data, RuntimeSettings rt, int tdb_flags);
196 #endif /* __PERF_H__ */