blob: 59659cea45823a505a50a041e35e282ae8eea29d [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 Richter25ad2912008-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
Al Viro40437c72013-07-19 15:54:56 +040041void oprofile_create_stats_files(struct dentry *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042{
Robert Richter25ad2912008-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
Al Viroecde2822013-07-19 15:58:27 +040049 dir = oprofilefs_mkdir(root, "stats");
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 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);
Al Viroecde2822013-07-19 15:58:27 +040056 cpudir = oprofilefs_mkdir(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 */
Al Viro6af4ea02013-07-19 16:10:36 +040062 oprofilefs_create_ro_ulong(cpudir, "sample_received",
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 &cpu_buf->sample_received);
Al Viro6af4ea02013-07-19 16:10:36 +040064 oprofilefs_create_ro_ulong(cpudir, "sample_lost_overflow",
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 &cpu_buf->sample_lost_overflow);
Al Viro6af4ea02013-07-19 16:10:36 +040066 oprofilefs_create_ro_ulong(cpudir, "backtrace_aborted",
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 &cpu_buf->backtrace_aborted);
Al Viro6af4ea02013-07-19 16:10:36 +040068 oprofilefs_create_ro_ulong(cpudir, "sample_invalid_eip",
Philippe Eliedf9d1772007-11-14 16:58:48 -080069 &cpu_buf->sample_invalid_eip);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 }
Robert Richter6a180372008-10-16 15:01:40 +020071
Al Viro6af4ea02013-07-19 16:10:36 +040072 oprofilefs_create_ro_atomic(dir, "sample_lost_no_mm",
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 &oprofile_stats.sample_lost_no_mm);
Al Viro6af4ea02013-07-19 16:10:36 +040074 oprofilefs_create_ro_atomic(dir, "sample_lost_no_mapping",
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 &oprofile_stats.sample_lost_no_mapping);
Al Viro6af4ea02013-07-19 16:10:36 +040076 oprofilefs_create_ro_atomic(dir, "event_lost_overflow",
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 &oprofile_stats.event_lost_overflow);
Al Viro6af4ea02013-07-19 16:10:36 +040078 oprofilefs_create_ro_atomic(dir, "bt_lost_no_mapping",
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 &oprofile_stats.bt_lost_no_mapping);
Jason Yeh4d4036e2009-07-08 13:49:38 +020080#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
Al Viro6af4ea02013-07-19 16:10:36 +040081 oprofilefs_create_ro_atomic(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}