blob: 917d28ebeacd24ab2a6f0f3772be1846b4011bb5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/**
2 * @file oprofile_stats.c
3 *
4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
6 *
7 * @author John Levon
8 */
9
10#include <linux/oprofile.h>
11#include <linux/smp.h>
12#include <linux/cpumask.h>
13#include <linux/threads.h>
Robert Richter6a180372008-10-16 15:01:40 +020014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include "oprofile_stats.h"
16#include "cpu_buffer.h"
Robert Richter6a180372008-10-16 15:01:40 +020017
Linus Torvalds1da177e2005-04-16 15:20:36 -070018struct oprofile_stat_struct oprofile_stats;
Robert Richter6a180372008-10-16 15:01:40 +020019
Linus Torvalds1da177e2005-04-16 15:20:36 -070020void oprofile_reset_stats(void)
21{
Robert Richter25ad29132008-09-05 17:12:36 +020022 struct oprofile_cpu_buffer *cpu_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 int i;
Robert Richter6a180372008-10-16 15:01:40 +020024
KAMEZAWA Hiroyukife449f42006-03-28 01:56:38 -080025 for_each_possible_cpu(i) {
Tejun Heob3e9f672009-10-29 22:34:13 +090026 cpu_buf = &per_cpu(op_cpu_buffer, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 cpu_buf->sample_received = 0;
28 cpu_buf->sample_lost_overflow = 0;
Philippe Eliedf9d1772007-11-14 16:58:48 -080029 cpu_buf->backtrace_aborted = 0;
30 cpu_buf->sample_invalid_eip = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 }
Robert Richter6a180372008-10-16 15:01:40 +020032
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
34 atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35 atomic_set(&oprofile_stats.event_lost_overflow, 0);
Maynard Johnson2b8777c2009-05-27 10:15:08 -050036 atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
Robert Richter1b294f52009-07-09 14:56:25 +020037 atomic_set(&oprofile_stats.multiplex_counter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038}
39
40
Robert Richter25ad29132008-09-05 17:12:36 +020041void oprofile_create_stats_files(struct super_block *sb, struct dentry *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042{
Robert Richter25ad29132008-09-05 17:12:36 +020043 struct oprofile_cpu_buffer *cpu_buf;
44 struct dentry *cpudir;
45 struct dentry *dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 char buf[10];
47 int i;
48
49 dir = oprofilefs_mkdir(sb, root, "stats");
50 if (!dir)
51 return;
52
KAMEZAWA Hiroyukife449f42006-03-28 01:56:38 -080053 for_each_possible_cpu(i) {
Tejun Heob3e9f672009-10-29 22:34:13 +090054 cpu_buf = &per_cpu(op_cpu_buffer, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 snprintf(buf, 10, "cpu%d", i);
56 cpudir = oprofilefs_mkdir(sb, dir, buf);
Robert Richter6a180372008-10-16 15:01:40 +020057
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 /* Strictly speaking access to these ulongs is racy,
59 * but we can't simply lock them, and they are
60 * informational only.
61 */
62 oprofilefs_create_ro_ulong(sb, cpudir, "sample_received",
63 &cpu_buf->sample_received);
64 oprofilefs_create_ro_ulong(sb, cpudir, "sample_lost_overflow",
65 &cpu_buf->sample_lost_overflow);
66 oprofilefs_create_ro_ulong(sb, cpudir, "backtrace_aborted",
67 &cpu_buf->backtrace_aborted);
Philippe Eliedf9d1772007-11-14 16:58:48 -080068 oprofilefs_create_ro_ulong(sb, cpudir, "sample_invalid_eip",
69 &cpu_buf->sample_invalid_eip);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 }
Robert Richter6a180372008-10-16 15:01:40 +020071
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 oprofilefs_create_ro_atomic(sb, dir, "sample_lost_no_mm",
73 &oprofile_stats.sample_lost_no_mm);
74 oprofilefs_create_ro_atomic(sb, dir, "sample_lost_no_mapping",
75 &oprofile_stats.sample_lost_no_mapping);
76 oprofilefs_create_ro_atomic(sb, dir, "event_lost_overflow",
77 &oprofile_stats.event_lost_overflow);
78 oprofilefs_create_ro_atomic(sb, dir, "bt_lost_no_mapping",
79 &oprofile_stats.bt_lost_no_mapping);
Jason Yeh4d4036e2009-07-08 13:49:38 +020080#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
81 oprofilefs_create_ro_atomic(sb, dir, "multiplex_counter",
Robert Richter1b294f52009-07-09 14:56:25 +020082 &oprofile_stats.multiplex_counter);
Jason Yeh4d4036e2009-07-08 13:49:38 +020083#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}