root/examples/perfcounter/perf.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


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

/* [<][>][^][v][top][bottom][index][help] */