Initial IBM OpenAFS 1.0 tree
[openafs.git] / src / viced / fs_stats.h
1 /*
2  * (C) Copyright Transarc Corporation 1991
3  * Licensed Materials - Property of Transarc
4  * All Rights Reserved.
5  */
6
7 #ifndef __fs_stats_h
8 #define __fs_stats_h  1
9
10 /*------------------------------------------------------------------------
11  * fs_stats.h
12  *
13  * Definitions supporting call and performance information gathering for
14  * the FileServer xstat (extended statistics) interface.
15  *
16  *------------------------------------------------------------------------*/
17
18
19 #include <afs/param.h>          /*System configuration info*/
20
21 /*
22  * Decide if we're keeping detailed File Server stats.
23  */
24 #define FS_STATS_DETAILED 1
25
26 /*
27  * Performance numbers.
28  */
29 struct afs_PerfStats {
30     afs_int32 numPerfCalls;             /*# of performance calls rcvd*/
31
32     /*
33      * Vnode cache section.
34      */
35     afs_int32 vcache_L_Entries; /*Num entries in LARGE vnode cache*/
36     afs_int32 vcache_L_Allocs;  /*# allocs, large*/
37     afs_int32 vcache_L_Gets;            /*# gets, large*/
38     afs_int32 vcache_L_Reads;   /*# reads, large*/
39     afs_int32 vcache_L_Writes;  /*# writes, large*/
40
41     afs_int32 vcache_S_Entries; /*Num entries in SMALL vnode cache*/
42     afs_int32 vcache_S_Allocs;  /*# allocs, small*/
43     afs_int32 vcache_S_Gets;            /*# gets, small*/
44     afs_int32 vcache_S_Reads;   /*# reads, small*/
45     afs_int32 vcache_S_Writes;  /*# writes, small*/
46
47     afs_int32 vcache_H_Entries; /*Num entries in HEADER vnode cache */
48     afs_int32 vcache_H_Gets;            /*# gets*/
49     afs_int32 vcache_H_Replacements;    /*# replacements*/
50
51     /*
52      * Directory package section.
53      */
54     afs_int32 dir_Buffers;              /*Num buffers in use*/
55     afs_int32 dir_Calls;                /*Num read calls made*/
56     afs_int32 dir_IOs;          /*I/O ops performed*/
57
58     /*
59      * Rx section.  These numbers represent the contents of the
60      * rx_stats structure maintained by Rx.  All other Rx info,
61      * including struct rx_debug and connection stuff is available
62      * via the rxdebug interface.
63      */
64     afs_int32 rx_packetRequests;                /*Packet alloc requests*/
65     afs_int32 rx_noPackets_RcvClass;            /*Failed pkt requests, receives*/
66     afs_int32 rx_noPackets_SendClass;   /*Ditto, sends*/
67     afs_int32 rx_noPackets_SpecialClass;        /*Ditto, specials*/
68     afs_int32 rx_socketGreedy;          /*Did SO_GREEDY succeed?*/
69     afs_int32 rx_bogusPacketOnRead;             /*Short pkts rcvd*/
70     afs_int32 rx_bogusHost;                     /*Host addr from bogus pkts*/
71     afs_int32 rx_noPacketOnRead;                /*Read pkts w/no packet there*/
72     afs_int32 rx_noPacketBuffersOnRead; /*Pkts dropped from buff shortage*/
73     afs_int32 rx_selects;                       /*Selects waiting on pkt or timeout*/
74     afs_int32 rx_sendSelects;           /*Selects forced upon sends*/
75     afs_int32 rx_packetsRead_RcvClass;  /*Packets read, rcv class*/
76     afs_int32 rx_packetsRead_SendClass; /*Packets read, send class*/
77     afs_int32 rx_packetsRead_SpecialClass;      /*Packets read, special class*/
78     afs_int32 rx_dataPacketsRead;               /*Uniq data packets read off wire*/
79     afs_int32 rx_ackPacketsRead;                /*Ack packets read*/
80     afs_int32 rx_dupPacketsRead;                /*Duplicate data packets read*/
81     afs_int32 rx_spuriousPacketsRead;   /*Inappropriate packets read*/
82     afs_int32 rx_packetsSent_RcvClass;  /*Packets sent, rcv class*/
83     afs_int32 rx_packetsSent_SendClass; /*Packets sent, send class*/
84     afs_int32 rx_packetsSent_SpecialClass;      /*Packets sent, special class*/
85     afs_int32 rx_ackPacketsSent;                /*Ack packets sent*/
86     afs_int32 rx_pingPacketsSent;               /*Ping packets sent*/
87     afs_int32 rx_abortPacketsSent;              /*Abort packets sent*/
88     afs_int32 rx_busyPacketsSent;               /*Busy packets sent*/
89     afs_int32 rx_dataPacketsSent;               /*Unique data packets sent*/
90     afs_int32 rx_dataPacketsReSent;             /*Retransmissions sent*/
91     afs_int32 rx_dataPacketsPushed;             /*Retransmissions pushed by NACK*/
92     afs_int32 rx_ignoreAckedPacket;             /*Packets w/acked flag on rxi_Start*/
93     afs_int32 rx_totalRtt_Sec;          /*Ttl round trip time, secs*/
94     afs_int32 rx_totalRtt_Usec;         /*Ttl round trip time, usecs*/
95     afs_int32 rx_minRtt_Sec;                    /*Min round trip time, secs*/
96     afs_int32 rx_minRtt_Usec;           /*Min round trip time, usecs*/
97     afs_int32 rx_maxRtt_Sec;                    /*Max round trip time, secs*/
98     afs_int32 rx_maxRtt_Usec;           /*Max round trip time, usecs*/
99     afs_int32 rx_nRttSamples;           /*Round trip samples*/
100     afs_int32 rx_nServerConns;          /*Ttl server connections*/
101     afs_int32 rx_nClientConns;          /*Ttl client connections*/
102     afs_int32 rx_nPeerStructs;          /*Ttl peer structures*/
103     afs_int32 rx_nCallStructs;          /*Ttl call structures*/
104     afs_int32 rx_nFreeCallStructs;              /*Ttl free call structures*/
105
106     /*
107      * Host module fields.
108      */
109     afs_int32 host_NumHostEntries;              /*Number of host entries*/
110     afs_int32 host_HostBlocks;          /*Blocks in use for hosts*/
111     afs_int32 host_NonDeletedHosts;             /*Non-deleted hosts*/
112     afs_int32 host_HostsInSameNetOrSubnet;      /*" in same [sub]net as server*/
113     afs_int32 host_HostsInDiffSubnet;   /*" in different subnet as server*/
114     afs_int32 host_HostsInDiffNetwork;  /*" in different network as server*/
115     afs_int32 host_NumClients;          /*Number of client entries*/
116     afs_int32 host_ClientBlocks;                /*Blocks in use for clients*/
117
118     /*
119      * Host systype
120      */
121     afs_int32 sysname_ID;                       /*Unique hardware/OS identifier*/
122
123     /*
124      * Spares
125      */
126     afs_int32 spare[31];
127 };
128
129 #if FS_STATS_DETAILED
130 /*
131  * Assign each of the File Server's RPC interface routines an index.
132  */
133 #define FS_STATS_RPCIDX_FETCHDATA        0
134 #define FS_STATS_RPCIDX_FETCHACL         1
135 #define FS_STATS_RPCIDX_FETCHSTATUS      2
136 #define FS_STATS_RPCIDX_STOREDATA        3
137 #define FS_STATS_RPCIDX_STOREACL         4
138 #define FS_STATS_RPCIDX_STORESTATUS      5
139 #define FS_STATS_RPCIDX_REMOVEFILE       6
140 #define FS_STATS_RPCIDX_CREATEFILE       7
141 #define FS_STATS_RPCIDX_RENAME           8
142 #define FS_STATS_RPCIDX_SYMLINK          9
143 #define FS_STATS_RPCIDX_LINK            10
144 #define FS_STATS_RPCIDX_MAKEDIR         11
145 #define FS_STATS_RPCIDX_REMOVEDIR       12
146 #define FS_STATS_RPCIDX_SETLOCK         13
147 #define FS_STATS_RPCIDX_EXTENDLOCK      14
148 #define FS_STATS_RPCIDX_RELEASELOCK     15
149 #define FS_STATS_RPCIDX_GETSTATISTICS   16
150 #define FS_STATS_RPCIDX_GIVEUPCALLBACKS 17
151 #define FS_STATS_RPCIDX_GETVOLUMEINFO   18
152 #define FS_STATS_RPCIDX_GETVOLUMESTATUS 19
153 #define FS_STATS_RPCIDX_SETVOLUMESTATUS 20
154 #define FS_STATS_RPCIDX_GETROOTVOLUME   21
155 #define FS_STATS_RPCIDX_CHECKTOKEN      22
156 #define FS_STATS_RPCIDX_GETTIME         23
157 #define FS_STATS_RPCIDX_NGETVOLUMEINFO  24
158 #define FS_STATS_RPCIDX_BULKSTATUS      25
159 #define FS_STATS_RPCIDX_XSTATSVERSION   26
160 #define FS_STATS_RPCIDX_GETXSTATS       27
161
162 #define FS_STATS_NUM_RPC_OPS            28
163
164 /*
165  * Assign an index to each of the File Server's RPC interface routines
166  * that transfer any data to speak of.
167  */
168 #define FS_STATS_XFERIDX_FETCHDATA       0
169 #define FS_STATS_XFERIDX_STOREDATA       1
170
171 #define FS_STATS_NUM_XFER_OPS            2
172
173 /*
174  * Record to track timing numbers for each File Server RPC operation.
175  */
176 struct fs_stats_opTimingData {
177     afs_int32 numOps;                   /*Number of operations executed*/
178     afs_int32 numSuccesses;                     /*Number of successful ops*/
179     struct timeval sumTime;             /*Sum of sample timings*/
180     struct timeval sqrTime;             /*Sum of squares of sample timings */
181     struct timeval minTime;             /*Minimum timing value observed*/
182     struct timeval maxTime;             /*Minimum timing value observed*/
183 };
184
185 /*
186  * We discriminate byte size transfers into this many buckets.
187  */
188 #define FS_STATS_NUM_XFER_BUCKETS       9
189
190 #define FS_STATS_MAXBYTES_BUCKET0     128
191 #define FS_STATS_MAXBYTES_BUCKET1    1024
192 #define FS_STATS_MAXBYTES_BUCKET2    8192
193 #define FS_STATS_MAXBYTES_BUCKET3   16384
194 #define FS_STATS_MAXBYTES_BUCKET4   32768
195 #define FS_STATS_MAXBYTES_BUCKET5  131072
196 #define FS_STATS_MAXBYTES_BUCKET6  524288
197 #define FS_STATS_MAXBYTES_BUCKET7 1048576
198
199
200 /*
201  * Record to track timings and byte sizes for data transfers.
202  */
203 struct fs_stats_xferData {
204     afs_int32 numXfers;                    /*Number of xfers*/
205     afs_int32 numSuccesses;                        /*Number of successful xfers*/
206     struct timeval sumTime;                /*Sum of timing values*/
207     struct timeval sqrTime;                /*Sum of squares of timing values */
208     struct timeval minTime;                /*Minimum xfer time recorded*/
209     struct timeval maxTime;                /*Maximum xfer time recorded*/
210     afs_int32 sumBytes;                    /*Sum of bytes transferred*/
211     afs_int32 minBytes;                    /*Minimum value observed*/
212     afs_int32 maxBytes;                    /*Maximum value observed*/
213     afs_int32 count[FS_STATS_NUM_XFER_BUCKETS]; /*Tally for each range of bytes*/
214 };
215
216 /*
217  * Macros to operate on time values.
218  *
219  * fs_stats_TimeLessThan(t1, t2)     Non-zero if t1 is less than t2
220  * fs_stats_TimeGreaterThan(t1, t2)  Non-zero if t1 is greater than t2
221  * fs_stats_GetDiff(t3, t1, t2)      Set t3 to the difference between
222  *                                      t1 and t2 (t1 is less than or
223  *                                      equal to t2).
224  * fs_stats_AddTo(t1, t2)            Add t2 to t1
225  * fs_stats_TimeAssign(t1, t2)       Assign time t2 to t1
226  * afs_stats_SquareAddTo(t1,t2)      Add square of t2 to t1
227  */
228 #define fs_stats_TimeLessThan(t1, t2)        \
229             ((t1.tv_sec  < t2.tv_sec)  ? 1 : \
230              (t1.tv_sec  > t2.tv_sec)  ? 0 : \
231              (t1.tv_usec < t2.tv_usec) ? 1 : \
232              0)
233
234 #define fs_stats_TimeGreaterThan(t1, t2)     \
235             ((t1.tv_sec  > t2.tv_sec)  ? 1 : \
236              (t1.tv_sec  < t2.tv_sec)  ? 0 : \
237              (t1.tv_usec > t2.tv_usec) ? 1 : \
238              0)
239
240 #define fs_stats_GetDiff(t3, t1, t2)                            \
241 {                                                               \
242     /*                                                          \
243      * If the microseconds of the later time are smaller than   \
244      * the earlier time, set up for proper subtraction (doing   \
245      * the carry).                                              \
246      */                                                         \
247     if (t2.tv_usec < t1.tv_usec) {                              \
248         t2.tv_usec += 1000000;                                  \
249         t2.tv_sec -= 1;                                         \
250     }                                                           \
251     t3.tv_sec  = t2.tv_sec  - t1.tv_sec;                        \
252     t3.tv_usec = t2.tv_usec - t1.tv_usec;                       \
253 }
254
255 #define fs_stats_AddTo(t1, t2)    \
256 {                                 \
257     t1.tv_sec  += t2.tv_sec;      \
258     t1.tv_usec += t2.tv_usec;     \
259     if (t1.tv_usec > 1000000) {   \
260         t1.tv_usec -= 1000000;    \
261         t1.tv_sec++;              \
262     }                             \
263 }
264
265 #define fs_stats_TimeAssign(t1, t2)     \
266 {                                       \
267     t1.tv_sec = t2.tv_sec;              \
268     t1.tv_usec = t2.tv_usec;            \
269 }
270
271 #define fs_stats_SquareAddTo(t1, t2)                         \
272 {                                                            \
273     if (t2.tv_sec > 0)                                       \
274       {                                                      \
275        t1.tv_sec += (int) (t2.tv_sec * t2.tv_sec                    \
276                     + (0.000002 * t2.tv_sec) * t2.tv_usec) ;  \
277        t1.tv_usec += (int) ((2 * t2.tv_sec * t2.tv_usec) % 1000000  \
278                     + (0.000001 * t2.tv_usec) * t2.tv_usec);  \
279       }                                                      \
280     else                                                     \
281       {                                                      \
282        t1.tv_usec += (int) ((0.000001 * t2.tv_usec) * t2.tv_usec);   \
283       }                                                      \
284     if (t1.tv_usec > 1000000) {                              \
285         t1.tv_usec -= 1000000;                               \
286         t1.tv_sec++;                                         \
287     }                                                        \
288 }
289
290 /*
291  * This is the detailed performance data collection for the File Server.
292  */
293 struct fs_stats_DetailedStats {
294     struct timeval epoch;                   /*Time when data collection began*/
295     struct fs_stats_opTimingData
296         rpcOpTimes[FS_STATS_NUM_RPC_OPS];   /*Individual RPC operation timings*/
297     struct fs_stats_xferData
298         xferOpTimes[FS_STATS_NUM_XFER_OPS]; /*Byte info for certain ops*/
299 };
300
301 /*
302  * This is all of the performance data, both overall and detailed.
303  */
304 struct fs_stats_FullPerfStats {
305     struct afs_PerfStats overall;
306     struct fs_stats_DetailedStats det;
307 };
308
309 /*
310  * This is the structure accessible by specifying the
311  * AFS_XSTATSCOLL_FULL_PERF_INFO collection to the xstat package.
312  */
313 extern struct fs_stats_FullPerfStats afs_FullPerfStats;
314 #endif /* FS_STATS_DETAILED */
315
316
317 /*
318  * This is the structure accessible by specifying the
319  * AFS_XSTATSCOLL_PERF_INFO collection to the xstat package.
320  */
321 extern struct afs_PerfStats afs_perfstats;
322
323 /*
324   * FileServer's name and IP address, both network byte order and
325   * host byte order.
326   */
327 extern char FS_HostName[];
328 extern afs_uint32 FS_HostAddr_NBO;
329 extern afs_uint32 FS_HostAddr_HBO;
330
331 #endif /* __fs_stats_h */