16 struct one_stat *read_bytes;
17 struct one_stat *read_reqs;
18 struct one_stat *write_bytes;
19 struct one_stat *write_reqs;
20 struct one_stat *getattr_reqs;
21 struct one_stat *setattr_reqs;
22 struct one_stat *create_reqs;
23 struct one_stat *destroy_reqs;
24 struct one_stat *statfs_reqs;
25 struct one_stat *open_reqs;
26 struct one_stat *close_reqs;
27 struct one_stat *punch_reqs;
30 init_one_stat (char *basename, char *name)
33 struct one_stat *stat = (struct one_stat *)malloc (sizeof (*stat));
36 fprintf (stderr, "Can't allocate stat %s: %s\n",
37 name, strerror (errno));
41 snprintf (fname, sizeof (fname), "%s/%s", basename, name);
43 memset (stat, 0, sizeof (*stat));
46 stat->fd = open (fname, O_RDONLY);
48 fprintf (stderr, "Can't open stat %s: %s\n",
49 fname, strerror (errno));
57 update_one_stat (struct one_stat *stat)
59 static char buffer[1024];
60 long long prev = stat->current;
63 lseek (stat->fd, 0, SEEK_SET);
64 nob = read (stat->fd, buffer, sizeof (buffer) - 1);
66 fprintf (stderr, "Can't read stat %s: %s\n",
67 stat->name, strerror (errno));
72 if (sscanf (buffer, "%Ld", &stat->current) != 1) {
73 fprintf (stderr, "Can't parse stat %s: %s\n",
74 stat->name, strerror (errno));
78 stat->delta = stat->current - prev;
86 gettimeofday (&tv, NULL);
87 return (tv.tv_sec + tv.tv_usec / 1000000.0);
93 static double last = 0.0;
99 update_one_stat (read_bytes);
100 update_one_stat (read_reqs);
101 update_one_stat (write_bytes);
102 update_one_stat (write_reqs);
103 update_one_stat (getattr_reqs);
104 update_one_stat (setattr_reqs);
105 update_one_stat (open_reqs);
106 update_one_stat (close_reqs);
107 update_one_stat (create_reqs);
108 update_one_stat (destroy_reqs);
109 update_one_stat (statfs_reqs);
110 update_one_stat (punch_reqs);
113 printf ("R %Ld/%Ld W %Ld/%Ld attr %Ld/%Ld open %Ld/%Ld create %Ld/%Ld stat %Ld punch %Ld\n",
114 read_bytes->current, read_reqs->current,
115 write_bytes->current, write_reqs->current,
116 getattr_reqs->current, setattr_reqs->current,
117 open_reqs->current, close_reqs->current,
118 create_reqs->current, destroy_reqs->current,
119 statfs_reqs->current, punch_reqs->current);
123 printf ("R %6Ld (%5d %6.2fMb)/s W %6Ld (%5d %6.2fMb)/s",
124 read_reqs->delta, (int)(read_reqs->delta / t),
125 read_bytes->delta / ((1<<20) * t),
126 write_reqs->delta, (int)(write_reqs->delta / t),
127 write_bytes->delta / ((1<<20) * t));
129 if (getattr_reqs->delta != 0)
130 printf (" ga:%Ld,%d/s", getattr_reqs->delta,
131 (int)(getattr_reqs->delta / t));
133 if (setattr_reqs->delta != 0)
134 printf (" sa:%Ld", setattr_reqs->delta);
136 if (open_reqs->delta != 0)
137 printf (" op:%Ld", open_reqs->delta);
139 if (close_reqs->delta != 0)
140 printf (" cl:%Ld", close_reqs->delta);
142 if (create_reqs->delta != 0)
143 printf (" cx:%Ld", create_reqs->delta);
145 if (destroy_reqs->delta != 0)
146 printf (" dx:%Ld", destroy_reqs->delta);
148 if (statfs_reqs->delta != 0)
149 printf (" st:%Ld", statfs_reqs->delta);
151 if (punch_reqs->delta != 0)
152 printf (" pu:%Ld", punch_reqs->delta);
160 int main (int argc, char **argv)
166 fprintf (stderr, "obd type not specified\n");
170 snprintf (basedir, sizeof (basedir), "/proc/sys/%s", argv[1]);
173 interval = atoi (argv[2]);
175 read_bytes = init_one_stat (basedir, "read_bytes");
176 read_reqs = init_one_stat (basedir, "read_reqs");
177 write_bytes = init_one_stat (basedir, "write_bytes");
178 write_reqs = init_one_stat (basedir, "write_reqs");
179 getattr_reqs = init_one_stat (basedir, "getattr_reqs");
180 setattr_reqs = init_one_stat (basedir, "setattr_reqs");
181 create_reqs = init_one_stat (basedir, "create_reqs");
182 destroy_reqs = init_one_stat (basedir, "destroy_reqs");
183 statfs_reqs = init_one_stat (basedir, "statfs_reqs");
184 open_reqs = init_one_stat (basedir, "open_reqs");
185 close_reqs = init_one_stat (basedir, "close_reqs");
186 punch_reqs = init_one_stat (basedir, "punch_reqs");