summaryrefslogtreecommitdiffstats
path: root/examples/perfcounter/perf.h
blob: 7279e788310361c46a2ac6b3af4bd14ad7cf537a (plain)
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
/* 
 *  Unix SMB/CIFS implementation.
 *  Performance Counter Daemon
 *
 *  Copyright (C) Marcin Krzysztof Porwit    2005
 *  
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef __PERF_H__
#define __PERF_H__

#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <signal.h>
#include <stdarg.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <limits.h>
#include "tdb.h"
#include <rpc_perfcount_defs.h>
#include <sys/statfs.h>
#include <sys/times.h>
#include <sys/sysinfo.h>

#define NUM_COUNTERS 10

#define NAME_LEN 256
#define HELP_LEN 1024

#define PERF_OBJECT 0
#define PERF_INSTANCE 1
#define PERF_COUNTER 2

#define FALSE 0
#define TRUE !FALSE

#define PROC_BUF 256
#define LARGE_BUF 16384

typedef struct perf_counter
{
    int index;
    char name[NAME_LEN];
    char help[HELP_LEN];
    char relationships[NAME_LEN];
    unsigned int counter_type;
    int record_type;
} PerfCounter;

typedef struct mem_data
{
    unsigned int availPhysKb;
    unsigned int availSwapKb;
    unsigned int totalPhysKb;
    unsigned int totalSwapKb;
} MemData;

typedef struct mem_info
{
    PerfCounter memObjDesc;
    PerfCounter availPhysKb;
    PerfCounter availSwapKb;
    PerfCounter totalPhysKb;
    PerfCounter totalSwapKb;
    MemData *data;
} MemInfo;

typedef struct cpu_data
{
    unsigned long long user;
    unsigned long long nice;
    unsigned long long system;
    unsigned long long idle;
} CPUData;

typedef struct cpu_info
{
    unsigned int numCPUs;
    PerfCounter cpuObjDesc;
    PerfCounter userCPU;
    PerfCounter niceCPU;
    PerfCounter systemCPU;
    PerfCounter idleCPU;
    CPUData *data;
} CPUInfo;

typedef struct disk_meta_data
{
	char name[NAME_LEN];
	char mountpoint[NAME_LEN];
} DiskMetaData;

typedef struct disk_data
{
	unsigned long long freeMegs;
	unsigned int writesPerSec;
	unsigned int readsPerSec;
} DiskData;

typedef struct disk_info
{
	unsigned int numDisks;
	DiskMetaData *mdata;
	PerfCounter diskObjDesc;
	PerfCounter freeMegs;
	PerfCounter writesPerSec;
	PerfCounter readsPerSec;
	DiskData *data;
} DiskInfo;

typedef struct process_data
{
	unsigned int runningProcessCount;
} ProcessData;

typedef struct process_info
{
	PerfCounter processObjDesc;
	PerfCounter runningProcessCount;
	ProcessData *data;
} ProcessInfo;

typedef struct perf_data_block
{
	unsigned int counter_id;
	unsigned int num_counters;
	unsigned int NumObjectTypes;
	unsigned long long PerfTime;
	unsigned long long PerfFreq;
	unsigned long long PerfTime100nSec;
	MemInfo memInfo;
	CPUInfo cpuInfo;
	ProcessInfo processInfo;
	DiskInfo diskInfo;
} PERF_DATA_BLOCK;

typedef struct runtime_settings
{
    /* Runtime flags */
    int dflag;
    /* DB path names */
    char dbDir[PATH_MAX];
    char nameFile[PATH_MAX];
    char counterFile[PATH_MAX];
    /* TDB context */
    TDB_CONTEXT *cnames;
    TDB_CONTEXT *cdata;
} RuntimeSettings;

/* perf_writer_ng_util.c function prototypes */
void fatal(char *msg);
void add_key(TDB_CONTEXT *db, char *keystring, char *datastring, int flags);
void add_key_raw(TDB_CONTEXT *db, char *keystring, void *datastring, size_t datasize, int flags);
void make_key(char *buf, int buflen, int key_part1, char *key_part2);
void parse_flags(RuntimeSettings *rt, int argc, char **argv);
void setup_file_paths(RuntimeSettings *rt);
void daemonize(RuntimeSettings *rt);

/* perf_writer_ng_mem.c function prototypes */
void get_meminfo(PERF_DATA_BLOCK *data);
void init_memdata_desc(PERF_DATA_BLOCK *data);
void init_memdata(PERF_DATA_BLOCK *data);
void output_mem_desc(PERF_DATA_BLOCK *data, RuntimeSettings rt);
void output_meminfo(PERF_DATA_BLOCK *data, RuntimeSettings rt, int tdb_flags);
void init_perf_counter(PerfCounter *counter, PerfCounter *parent, unsigned int index, char *name, char *help, int counter_type, int record_type);

/* perf_writer_ng_cpu.c function prototypes */
unsigned long long get_cpufreq();
void init_cpudata_desc(PERF_DATA_BLOCK *data);
void get_cpuinfo(PERF_DATA_BLOCK *data);
void init_cpu_data(PERF_DATA_BLOCK *data);
void output_cpu_desc(PERF_DATA_BLOCK *data, RuntimeSettings rt);
void output_cpuinfo(PERF_DATA_BLOCK *data, RuntimeSettings rt, int tdb_flags);

#endif /* __PERF_H__ */