blob: ddb1940a9e9f0657e6531c74d6a53414cd556e57 [file] [log] [blame]
Upstreamcc2ee171970-01-12 13:46:40 +00001/**
2 * @file daemon/opd_stats.c
3 * Management of daemon statistics
4 *
5 * @remark Copyright 2002 OProfile authors
6 * @remark Read the file COPYING
7 *
8 * @author John Levon
9 * @author Philippe Elie
10 */
11
12#include "opd_stats.h"
13#include "oprofiled.h"
14
15#include "op_get_time.h"
16
17#include <dirent.h>
18#include <stdlib.h>
19#include <stdio.h>
20
21unsigned long opd_stats[OPD_MAX_STATS];
22
23/**
24 * print_if - print an integer value read from file filename,
25 * do nothing if the value read == -1 except if force is non-zero
26 */
27static void print_if(char const * fmt, char const * path, char const * filename, int force)
28{
29 int value = opd_read_fs_int(path, filename, 0);
30 if (value != -1 || force)
31 printf(fmt, value);
32}
33
34/**
35 * opd_print_stats - print out latest statistics
36 */
37void opd_print_stats(void)
38{
39 DIR * dir;
40 struct dirent * dirent;
41
42 printf("\n%s\n", op_get_time());
43 printf("Nr. sample dumps: %lu\n", opd_stats[OPD_DUMP_COUNT]);
44 printf("Nr. non-backtrace samples: %lu\n", opd_stats[OPD_SAMPLES]);
45 printf("Nr. kernel samples: %lu\n", opd_stats[OPD_KERNEL]);
46 printf("Nr. lost samples (no kernel/user): %lu\n", opd_stats[OPD_NO_CTX]);
47 printf("Nr. lost kernel samples: %lu\n", opd_stats[OPD_LOST_KERNEL]);
48 printf("Nr. incomplete code structs: %lu\n", opd_stats[OPD_DANGLING_CODE]);
49 printf("Nr. samples lost due to sample file open failure: %lu\n",
50 opd_stats[OPD_LOST_SAMPLEFILE]);
51 printf("Nr. samples lost due to no permanent mapping: %lu\n",
52 opd_stats[OPD_LOST_NO_MAPPING]);
53 print_if("Nr. event lost due to buffer overflow: %u\n",
Ben Cheng2b16b5f2008-10-23 16:07:43 -070054 "/dev/oprofile/stats", "event_lost_overflow", 1);
Upstreamcc2ee171970-01-12 13:46:40 +000055 print_if("Nr. samples lost due to no mapping: %u\n",
Ben Cheng2b16b5f2008-10-23 16:07:43 -070056 "/dev/oprofile/stats", "sample_lost_no_mapping", 1);
Upstreamcc2ee171970-01-12 13:46:40 +000057 print_if("Nr. backtraces skipped due to no file mapping: %u\n",
Ben Cheng2b16b5f2008-10-23 16:07:43 -070058 "/dev/oprofile/stats", "bt_lost_no_mapping", 0);
Upstreamcc2ee171970-01-12 13:46:40 +000059 print_if("Nr. samples lost due to no mm: %u\n",
Ben Cheng2b16b5f2008-10-23 16:07:43 -070060 "/dev/oprofile/stats", "sample_lost_no_mm", 1);
Upstreamcc2ee171970-01-12 13:46:40 +000061
Ben Cheng2b16b5f2008-10-23 16:07:43 -070062 if (!(dir = opendir("/dev/oprofile/stats/")))
Upstreamcc2ee171970-01-12 13:46:40 +000063 goto out;
64 while ((dirent = readdir(dir))) {
65 int cpu_nr;
66 char path[256];
67 if (sscanf(dirent->d_name, "cpu%d", &cpu_nr) != 1)
68 continue;
Ben Cheng2b16b5f2008-10-23 16:07:43 -070069 snprintf(path, 256, "/dev/oprofile/stats/%s", dirent->d_name);
Upstreamcc2ee171970-01-12 13:46:40 +000070
71 print_if("Nr. samples lost cpu buffer overflow: %u\n",
72 path, "sample_lost_overflow", 1);
73 print_if("Nr. samples lost task exit: %u\n",
74 path, "sample_lost_task_exit", 0);
75 print_if("Nr. samples received: %u\n",
76 path, "sample_received", 1);
77 print_if("Nr. backtrace aborted: %u\n",
78 path, "backtrace_aborted", 0);
Ben Cheng2b16b5f2008-10-23 16:07:43 -070079 print_if("Nr. samples lost invalid pc: %u\n",
80 path, "sample_invalid_eip", 0);
Upstreamcc2ee171970-01-12 13:46:40 +000081 }
82 closedir(dir);
83out:
84 fflush(stdout);
85}