opd_stats.c revision 10e23eebca4175a8dfe3a788b2bebacb1fcfce54
1/**
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",
54	       "/dev/oprofile/stats", "event_lost_overflow", 1);
55	print_if("Nr. samples lost due to no mapping: %u\n",
56	       "/dev/oprofile/stats", "sample_lost_no_mapping", 1);
57	print_if("Nr. backtraces skipped due to no file mapping: %u\n",
58	       "/dev/oprofile/stats", "bt_lost_no_mapping", 0);
59	print_if("Nr. samples lost due to no mm: %u\n",
60	       "/dev/oprofile/stats", "sample_lost_no_mm", 1);
61
62	if (!(dir = opendir("/dev/oprofile/stats/")))
63		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;
69		snprintf(path, 256, "/dev/oprofile/stats/%s", dirent->d_name);
70
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);
79		print_if("Nr. samples lost invalid pc: %u\n",
80		     path, "sample_invalid_eip", 0);
81	}
82	closedir(dir);
83out:
84	fflush(stdout);
85}
86