2 * linux/net/sunrpc/stats.c
4 * procfs-based user access to generic RPC statistics. The stats files
5 * reside in /proc/net/rpc.
7 * The read routines assume that the buffer passed in is just big enough.
8 * If you implement an RPC service that has its own stats routine which
9 * appends the generic RPC stats, make sure you don't exceed the PAGE_SIZE
12 * Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de>
15 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/kernel.h>
19 #include <linux/proc_fs.h>
20 #include <linux/seq_file.h>
21 #include <linux/sunrpc/clnt.h>
22 #include <linux/sunrpc/svcsock.h>
23 #include <linux/sunrpc/metrics.h>
25 #define RPCDBG_FACILITY RPCDBG_MISC
27 struct proc_dir_entry *proc_net_rpc = NULL;
30 * Get RPC client stats
32 static int rpc_proc_show(struct seq_file *seq, void *v) {
33 const struct rpc_stat *statp = seq->private;
34 const struct rpc_program *prog = statp->program;
47 statp->rpcauthrefresh);
49 for (i = 0; i < prog->nrvers; i++) {
50 const struct rpc_version *vers = prog->version[i];
53 seq_printf(seq, "proc%u %u",
54 vers->number, vers->nrprocs);
55 for (j = 0; j < vers->nrprocs; j++)
56 seq_printf(seq, " %u",
57 vers->procs[j].p_count);
63 static int rpc_proc_open(struct inode *inode, struct file *file)
65 return single_open(file, rpc_proc_show, PDE(inode)->data);
68 static const struct file_operations rpc_proc_fops = {
70 .open = rpc_proc_open,
73 .release = single_release,
77 * Get RPC server stats
79 void svc_seq_show(struct seq_file *seq, const struct svc_stat *statp) {
80 const struct svc_program *prog = statp->program;
81 const struct svc_procedure *proc;
82 const struct svc_version *vers;
92 "rpc %u %u %u %u %u\n",
94 statp->rpcbadfmt+statp->rpcbadauth+statp->rpcbadclnt,
99 for (i = 0; i < prog->pg_nvers; i++) {
100 if (!(vers = prog->pg_vers[i]) || !(proc = vers->vs_proc))
102 seq_printf(seq, "proc%d %u", i, vers->vs_nproc);
103 for (j = 0; j < vers->vs_nproc; j++, proc++)
104 seq_printf(seq, " %u", proc->pc_count);
110 * rpc_alloc_iostats - allocate an rpc_iostats structure
111 * @clnt: RPC program, version, and xprt
114 struct rpc_iostats *rpc_alloc_iostats(struct rpc_clnt *clnt)
116 struct rpc_iostats *new;
117 new = kcalloc(clnt->cl_maxproc, sizeof(struct rpc_iostats), GFP_KERNEL);
120 EXPORT_SYMBOL(rpc_alloc_iostats);
123 * rpc_free_iostats - release an rpc_iostats structure
124 * @stats: doomed rpc_iostats structure
127 void rpc_free_iostats(struct rpc_iostats *stats)
131 EXPORT_SYMBOL(rpc_free_iostats);
134 * rpc_count_iostats - tally up per-task stats
135 * @task: completed rpc_task
137 * Relies on the caller for serialization.
139 void rpc_count_iostats(struct rpc_task *task)
141 struct rpc_rqst *req = task->tk_rqstp;
142 struct rpc_iostats *stats = task->tk_client->cl_metrics;
143 struct rpc_iostats *op_metrics;
144 long rtt, execute, queue;
148 op_metrics = &stats[task->tk_msg.rpc_proc->p_statidx];
150 op_metrics->om_ops++;
151 op_metrics->om_ntrans += req->rq_ntrans;
152 op_metrics->om_timeouts += task->tk_timeouts;
154 op_metrics->om_bytes_sent += task->tk_bytes_sent;
155 op_metrics->om_bytes_recv += req->rq_received;
157 queue = (long)req->rq_xtime - task->tk_start;
160 op_metrics->om_queue += queue;
165 op_metrics->om_rtt += rtt;
167 execute = (long)jiffies - task->tk_start;
170 op_metrics->om_execute += execute;
173 static void _print_name(struct seq_file *seq, unsigned int op,
174 struct rpc_procinfo *procs)
176 if (procs[op].p_name)
177 seq_printf(seq, "\t%12s: ", procs[op].p_name);
179 seq_printf(seq, "\t NULL: ");
181 seq_printf(seq, "\t%12u: ", op);
184 #define MILLISECS_PER_JIFFY (1000 / HZ)
186 void rpc_print_iostats(struct seq_file *seq, struct rpc_clnt *clnt)
188 struct rpc_iostats *stats = clnt->cl_metrics;
189 struct rpc_xprt *xprt = clnt->cl_xprt;
190 unsigned int op, maxproc = clnt->cl_maxproc;
195 seq_printf(seq, "\tRPC iostats version: %s ", RPC_IOSTATS_VERS);
196 seq_printf(seq, "p/v: %u/%u (%s)\n",
197 clnt->cl_prog, clnt->cl_vers, clnt->cl_protname);
200 xprt->ops->print_stats(xprt, seq);
202 seq_printf(seq, "\tper-op statistics\n");
203 for (op = 0; op < maxproc; op++) {
204 struct rpc_iostats *metrics = &stats[op];
205 _print_name(seq, op, clnt->cl_procinfo);
206 seq_printf(seq, "%lu %lu %lu %Lu %Lu %Lu %Lu %Lu\n",
209 metrics->om_timeouts,
210 metrics->om_bytes_sent,
211 metrics->om_bytes_recv,
212 metrics->om_queue * MILLISECS_PER_JIFFY,
213 metrics->om_rtt * MILLISECS_PER_JIFFY,
214 metrics->om_execute * MILLISECS_PER_JIFFY);
217 EXPORT_SYMBOL(rpc_print_iostats);
220 * Register/unregister RPC proc files
222 static inline struct proc_dir_entry *
223 do_register(const char *name, void *data, const struct file_operations *fops)
225 struct proc_dir_entry *ent;
228 dprintk("RPC: registering /proc/net/rpc/%s\n", name);
230 ent = create_proc_entry(name, 0, proc_net_rpc);
232 ent->proc_fops = fops;
238 struct proc_dir_entry *
239 rpc_proc_register(struct rpc_stat *statp)
241 return do_register(statp->program->name, statp, &rpc_proc_fops);
245 rpc_proc_unregister(const char *name)
247 remove_proc_entry(name, proc_net_rpc);
250 struct proc_dir_entry *
251 svc_proc_register(struct svc_stat *statp, const struct file_operations *fops)
253 return do_register(statp->program->pg_name, statp, fops);
257 svc_proc_unregister(const char *name)
259 remove_proc_entry(name, proc_net_rpc);
265 dprintk("RPC: registering /proc/net/rpc\n");
267 struct proc_dir_entry *ent;
268 ent = proc_mkdir("rpc", proc_net);
270 ent->owner = THIS_MODULE;
279 dprintk("RPC: unregistering /proc/net/rpc\n");
282 remove_proc_entry("net/rpc", NULL);