• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *   Copyright (c) International Business Machines Corp., 2001-2007
3  *
4  *   This program is free software;  you can redistribute it and/or modify
5  *   it under the terms of the GNU General Public License as published by
6  *   the Free Software Foundation; either version 2 of the License, or
7  *   (at your option) any later version.
8  *
9  *   This program is distributed in the hope that it will be useful,
10  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
12  *   the GNU General Public License for more details.
13  *
14  *   You should have received a copy of the GNU General Public License
15  *   along with this program;  if not, write to the Free Software
16  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 #ifndef _FFSB_STATS_H_
19 #define _FFSB_STATS_H_
20 
21 #include <inttypes.h>
22 
23 /* Latency statistics collection extension.
24  *
25  * For now, we are going to collect latency info on each (most)
26  * syscalls using gettimeofday. Unfortunately, it is the
27  * responsibility of each operation to collect this timing info.  We
28  * try to make this easier by providing a function that does the
29  * timing for supported syscalls.
30  *
31  * We want the ability to collect the average latency for a particular
32  * call, and also to collect latency info for user specified intervals
33  * -- called "buckets"
34  */
35 
36 struct stat_bucket {
37 	uint32_t min;
38 	uint32_t max;
39 	/* max = 0 indicates uninitialized bucket */
40 };
41 
42 /* These are all the syscalls we currently support */
43 typedef enum { SYS_OPEN = 0,
44 	       SYS_READ,
45 	       SYS_WRITE,
46 	       SYS_CREATE,
47 	       SYS_LSEEK,
48 	       SYS_UNLINK,
49 	       SYS_CLOSE,
50 	       SYS_STAT
51 } syscall_t;
52 
53 /* ASCII versions of the syscall names */
54 extern char *syscall_names[];
55 
56 /* Return 1 on success, 0 on error */
57 int ffsb_stats_str2syscall(char *, syscall_t *);
58 
59 /* Keep it in sync with syscall_t */
60 #define FFSB_NUM_SYSCALLS (8UL)
61 
62 /* What stats to collect, shared among all threads  */
63 typedef struct ffsb_stats_config {
64 	unsigned num_buckets;
65 	struct stat_bucket *buckets;
66 
67 	/* Ignore stats collection for some syscalls.
68 	 * Each bit corresponds to one syscall.
69 	 */
70 	uint32_t ignore_stats;
71 } ffsb_statsc_t;
72 
73 void ffsb_statsc_init(ffsb_statsc_t *);
74 void ffsb_statsc_addbucket(ffsb_statsc_t *, uint32_t min, uint32_t max);
75 void ffsb_statsc_ignore_sys(ffsb_statsc_t *, syscall_t s);
76 void ffsb_statsc_destroy(ffsb_statsc_t *);
77 
78 /* If we are collecting stats, then the config field is non-NULL */
79 typedef struct ffsb_stats_data {
80 	ffsb_statsc_t *config;
81 	uint32_t counts[FFSB_NUM_SYSCALLS];
82 	uint64_t totals[FFSB_NUM_SYSCALLS]; /* cumulative sums */
83 	uint64_t mins[FFSB_NUM_SYSCALLS];
84 	uint64_t maxs[FFSB_NUM_SYSCALLS];
85 	uint32_t *buckets[FFSB_NUM_SYSCALLS]; /* bucket counters */
86 } ffsb_statsd_t ;
87 
88 /* constructor/destructor */
89 void ffsb_statsd_init(ffsb_statsd_t *, ffsb_statsc_t *);
90 void ffsb_statsd_destroy(ffsb_statsd_t *);
91 
92 /* Add data to a stats data struct.  Value should be in microsecs
93  * _NOT_ milli-secs
94  */
95 void ffsb_add_data(ffsb_statsd_t *, syscall_t, uint32_t);
96 
97 /* Make a copy of a stats config */
98 void ffsb_statsc_copy(ffsb_statsc_t *, ffsb_statsc_t *);
99 
100 /* Add two statsd structs together */
101 void ffsb_statsd_add(ffsb_statsd_t *, ffsb_statsd_t *);
102 
103 /* Print out statsd structure */
104 void ffsb_statsd_print(ffsb_statsd_t *fsd);
105 
106 /* Do we want stats for the specified syscall */
107 int fsc_ignore_sys(ffsb_statsc_t *fsc, syscall_t s);
108 
109 #endif /* _FFSB_STATS_H_ */
110