blob: 77a57a6792f61994826580a2ed151ba50f96dc58 [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;
Jason Yeh4d4036e2009-07-08 13:49:38 +020019#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
20atomic_t multiplex_counter;
21#endif
Robert Richter6a180372008-10-16 15:01:40 +020022
Linus Torvalds1da177e2005-04-16 15:20:36 -070023void oprofile_reset_stats(void)
24{
Robert Richter25ad29132008-09-05 17:12:36 +020025 struct oprofile_cpu_buffer *cpu_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 int i;
Robert Richter6a180372008-10-16 15:01:40 +020027
KAMEZAWA Hiroyukife449f42006-03-28 01:56:38 -080028 for_each_possible_cpu(i) {
Mike Travis608dfdd2008-04-28 02:14:15 -070029 cpu_buf = &per_cpu(cpu_buffer, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 cpu_buf->sample_received = 0;
31 cpu_buf->sample_lost_overflow = 0;
Philippe Eliedf9d1772007-11-14 16:58:48 -080032 cpu_buf->backtrace_aborted = 0;
33 cpu_buf->sample_invalid_eip = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 }
Robert Richter6a180372008-10-16 15:01:40 +020035
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
37 atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
38 atomic_set(&oprofile_stats.event_lost_overflow, 0);
Maynard Johnson2b8777c2009-05-27 10:15:08 -050039 atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
Jason Yeh4d4036e2009-07-08 13:49:38 +020040#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
41 atomic_set(&multiplex_counter, 0);
42#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070043}
44
45
Robert Richter25ad29132008-09-05 17:12:36 +020046void oprofile_create_stats_files(struct super_block *sb, struct dentry *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -070047{
Robert Richter25ad29132008-09-05 17:12:36 +020048 struct oprofile_cpu_buffer *cpu_buf;
49 struct dentry *cpudir;
50 struct dentry *dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 char buf[10];
52 int i;
53
54 dir = oprofilefs_mkdir(sb, root, "stats");
55 if (!dir)
56 return;
57
KAMEZAWA Hiroyukife449f42006-03-28 01:56:38 -080058 for_each_possible_cpu(i) {
Mike Travis608dfdd2008-04-28 02:14:15 -070059 cpu_buf = &per_cpu(cpu_buffer, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 snprintf(buf, 10, "cpu%d", i);
61 cpudir = oprofilefs_mkdir(sb, dir, buf);
Robert Richter6a180372008-10-16 15:01:40 +020062
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 /* Strictly speaking access to these ulongs is racy,
64 * but we can't simply lock them, and they are
65 * informational only.
66 */
67 oprofilefs_create_ro_ulong(sb, cpudir, "sample_received",
68 &cpu_buf->sample_received);
69 oprofilefs_create_ro_ulong(sb, cpudir, "sample_lost_overflow",
70 &cpu_buf->sample_lost_overflow);
71 oprofilefs_create_ro_ulong(sb, cpudir, "backtrace_aborted",
72 &cpu_buf->backtrace_aborted);
Philippe Eliedf9d1772007-11-14 16:58:48 -080073 oprofilefs_create_ro_ulong(sb, cpudir, "sample_invalid_eip",
74 &cpu_buf->sample_invalid_eip);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 }
Robert Richter6a180372008-10-16 15:01:40 +020076
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 oprofilefs_create_ro_atomic(sb, dir, "sample_lost_no_mm",
78 &oprofile_stats.sample_lost_no_mm);
79 oprofilefs_create_ro_atomic(sb, dir, "sample_lost_no_mapping",
80 &oprofile_stats.sample_lost_no_mapping);
81 oprofilefs_create_ro_atomic(sb, dir, "event_lost_overflow",
82 &oprofile_stats.event_lost_overflow);
83 oprofilefs_create_ro_atomic(sb, dir, "bt_lost_no_mapping",
84 &oprofile_stats.bt_lost_no_mapping);
Jason Yeh4d4036e2009-07-08 13:49:38 +020085#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
86 oprofilefs_create_ro_atomic(sb, dir, "multiplex_counter",
87 &multiplex_counter);
88#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}