1 /* CacheFiles statistics
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
12 #include <linux/module.h>
13 #include <linux/proc_fs.h>
14 #include <linux/seq_file.h>
17 atomic_t cachefiles_lookup_histogram
[HZ
];
18 atomic_t cachefiles_mkdir_histogram
[HZ
];
19 atomic_t cachefiles_create_histogram
[HZ
];
22 * display the latency histogram
24 static int cachefiles_histogram_show(struct seq_file
*m
, void *v
)
29 switch ((unsigned long) v
) {
31 seq_puts(m
, "JIFS SECS LOOKUPS MKDIRS CREATES\n");
34 seq_puts(m
, "===== ===== ========= ========= =========\n");
37 index
= (unsigned long) v
- 3;
38 x
= atomic_read(&cachefiles_lookup_histogram
[index
]);
39 y
= atomic_read(&cachefiles_mkdir_histogram
[index
]);
40 z
= atomic_read(&cachefiles_create_histogram
[index
]);
41 if (x
== 0 && y
== 0 && z
== 0)
44 t
= (index
* 1000) / HZ
;
46 seq_printf(m
, "%4lu 0.%03u %9u %9u %9u\n", index
, t
, x
, y
, z
);
52 * set up the iterator to start reading from the first line
54 static void *cachefiles_histogram_start(struct seq_file
*m
, loff_t
*_pos
)
56 if ((unsigned long long)*_pos
>= HZ
+ 2)
60 return (void *)(unsigned long) *_pos
;
64 * move to the next line
66 static void *cachefiles_histogram_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
69 return (unsigned long long)*pos
> HZ
+ 2 ?
70 NULL
: (void *)(unsigned long) *pos
;
74 * clean up after reading
76 static void cachefiles_histogram_stop(struct seq_file
*m
, void *v
)
80 static const struct seq_operations cachefiles_histogram_ops
= {
81 .start
= cachefiles_histogram_start
,
82 .stop
= cachefiles_histogram_stop
,
83 .next
= cachefiles_histogram_next
,
84 .show
= cachefiles_histogram_show
,
88 * initialise the /proc/fs/cachefiles/ directory
90 int __init
cachefiles_proc_init(void)
94 if (!proc_mkdir("fs/cachefiles", NULL
))
97 if (!proc_create_seq("fs/cachefiles/histogram", S_IFREG
| 0444, NULL
,
98 &cachefiles_histogram_ops
))
105 remove_proc_entry("fs/cachefiles", NULL
);
107 _leave(" = -ENOMEM");
112 * clean up the /proc/fs/cachefiles/ directory
114 void cachefiles_proc_cleanup(void)
116 remove_proc_entry("fs/cachefiles/histogram", NULL
);
117 remove_proc_entry("fs/cachefiles", NULL
);