blob: e7af72bc97808f55c0c1c85304223b63bfc9b581 [file] [log] [blame]
The Android Open Source Project10e23ee2009-03-03 19:30:30 -08001/**
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"
Ben Cheng5a4eb4e2009-09-14 16:00:41 -070013#include "opd_extended.h"
The Android Open Source Project10e23ee2009-03-03 19:30:30 -080014#include "oprofiled.h"
15
16#include "op_get_time.h"
17
18#include <dirent.h>
19#include <stdlib.h>
20#include <stdio.h>
21
22unsigned long opd_stats[OPD_MAX_STATS];
23
24/**
25 * print_if - print an integer value read from file filename,
26 * do nothing if the value read == -1 except if force is non-zero
27 */
28static void print_if(char const * fmt, char const * path, char const * filename, int force)
29{
30 int value = opd_read_fs_int(path, filename, 0);
31 if (value != -1 || force)
32 printf(fmt, value);
33}
34
35/**
36 * opd_print_stats - print out latest statistics
37 */
38void opd_print_stats(void)
39{
40 DIR * dir;
41 struct dirent * dirent;
42
43 printf("\n%s\n", op_get_time());
Ben Cheng5a4eb4e2009-09-14 16:00:41 -070044 printf("\n-- OProfile Statistics --\n");
The Android Open Source Project10e23ee2009-03-03 19:30:30 -080045 printf("Nr. sample dumps: %lu\n", opd_stats[OPD_DUMP_COUNT]);
46 printf("Nr. non-backtrace samples: %lu\n", opd_stats[OPD_SAMPLES]);
47 printf("Nr. kernel samples: %lu\n", opd_stats[OPD_KERNEL]);
48 printf("Nr. lost samples (no kernel/user): %lu\n", opd_stats[OPD_NO_CTX]);
49 printf("Nr. lost kernel samples: %lu\n", opd_stats[OPD_LOST_KERNEL]);
50 printf("Nr. incomplete code structs: %lu\n", opd_stats[OPD_DANGLING_CODE]);
51 printf("Nr. samples lost due to sample file open failure: %lu\n",
52 opd_stats[OPD_LOST_SAMPLEFILE]);
53 printf("Nr. samples lost due to no permanent mapping: %lu\n",
54 opd_stats[OPD_LOST_NO_MAPPING]);
55 print_if("Nr. event lost due to buffer overflow: %u\n",
56 "/dev/oprofile/stats", "event_lost_overflow", 1);
57 print_if("Nr. samples lost due to no mapping: %u\n",
58 "/dev/oprofile/stats", "sample_lost_no_mapping", 1);
59 print_if("Nr. backtraces skipped due to no file mapping: %u\n",
60 "/dev/oprofile/stats", "bt_lost_no_mapping", 0);
61 print_if("Nr. samples lost due to no mm: %u\n",
62 "/dev/oprofile/stats", "sample_lost_no_mm", 1);
63
Ben Cheng5a4eb4e2009-09-14 16:00:41 -070064 opd_ext_print_stats();
65
The Android Open Source Project10e23ee2009-03-03 19:30:30 -080066 if (!(dir = opendir("/dev/oprofile/stats/")))
67 goto out;
68 while ((dirent = readdir(dir))) {
69 int cpu_nr;
70 char path[256];
71 if (sscanf(dirent->d_name, "cpu%d", &cpu_nr) != 1)
72 continue;
73 snprintf(path, 256, "/dev/oprofile/stats/%s", dirent->d_name);
74
Ben Cheng5a4eb4e2009-09-14 16:00:41 -070075 printf("\n---- Statistics for cpu : %d\n", cpu_nr);
The Android Open Source Project10e23ee2009-03-03 19:30:30 -080076 print_if("Nr. samples lost cpu buffer overflow: %u\n",
77 path, "sample_lost_overflow", 1);
78 print_if("Nr. samples lost task exit: %u\n",
79 path, "sample_lost_task_exit", 0);
80 print_if("Nr. samples received: %u\n",
81 path, "sample_received", 1);
82 print_if("Nr. backtrace aborted: %u\n",
83 path, "backtrace_aborted", 0);
84 print_if("Nr. samples lost invalid pc: %u\n",
85 path, "sample_invalid_eip", 0);
86 }
87 closedir(dir);
88out:
89 fflush(stdout);
90}