opd_stats.c

Go to the documentation of this file.
00001 
00012 #include "opd_stats.h"
00013 #include "opd_extended.h"
00014 #include "oprofiled.h"
00015 
00016 #include "op_get_time.h"
00017 
00018 #include <dirent.h>
00019 #include <stdlib.h>
00020 #include <stdio.h>
00021 
00022 unsigned long opd_stats[OPD_MAX_STATS];
00023 
00028 static void print_if(char const * fmt, char const * path, char const * filename, int force)
00029 {
00030     int value = opd_read_fs_int(path, filename, 0);
00031     if (value != -1 || force)
00032         printf(fmt, value);
00033 }
00034 
00038 void opd_print_stats(void)
00039 {
00040     DIR * dir;
00041     struct dirent * dirent;
00042 
00043     printf("\n%s\n", op_get_time());
00044     printf("\n-- OProfile Statistics --\n");
00045     printf("Nr. sample dumps: %lu\n", opd_stats[OPD_DUMP_COUNT]);
00046     printf("Nr. non-backtrace samples: %lu\n", opd_stats[OPD_SAMPLES]);
00047     printf("Nr. kernel samples: %lu\n", opd_stats[OPD_KERNEL]);
00048     printf("Nr. lost samples (no kernel/user): %lu\n", opd_stats[OPD_NO_CTX]);
00049     printf("Nr. lost kernel samples: %lu\n", opd_stats[OPD_LOST_KERNEL]);
00050     printf("Nr. incomplete code structs: %lu\n", opd_stats[OPD_DANGLING_CODE]);
00051     printf("Nr. samples lost due to sample file open failure: %lu\n",
00052         opd_stats[OPD_LOST_SAMPLEFILE]);
00053     printf("Nr. samples lost due to no permanent mapping: %lu\n",
00054         opd_stats[OPD_LOST_NO_MAPPING]);
00055     printf("Nr. user context kernel samples lost due to no app info available: %lu\n",
00056            opd_stats[OPD_NO_APP_KERNEL_SAMPLE]);
00057     print_if("Nr. samples lost due to buffer overflow: %u\n",
00058            "/dev/oprofile/stats", "event_lost_overflow", 1);
00059     print_if("Nr. samples lost due to no mapping: %u\n",
00060            "/dev/oprofile/stats", "sample_lost_no_mapping", 1);
00061     print_if("Nr. backtraces skipped due to no file mapping: %u\n",
00062            "/dev/oprofile/stats", "bt_lost_no_mapping", 0);
00063     print_if("Nr. samples lost due to no mm: %u\n",
00064            "/dev/oprofile/stats", "sample_lost_no_mm", 1);
00065 
00066     opd_ext_print_stats();
00067 
00068     if (!(dir = opendir("/dev/oprofile/stats/")))
00069         goto out;
00070     while ((dirent = readdir(dir))) {
00071         int cpu_nr;
00072         char path[256];
00073         if (sscanf(dirent->d_name, "cpu%d", &cpu_nr) != 1)
00074             continue;
00075         snprintf(path, 256, "/dev/oprofile/stats/%s", dirent->d_name);
00076 
00077         printf("\n---- Statistics for cpu : %d\n", cpu_nr);
00078         print_if("Nr. samples lost cpu buffer overflow: %u\n",
00079              path, "sample_lost_overflow", 1);
00080         print_if("Nr. samples lost task exit: %u\n",
00081              path, "sample_lost_task_exit", 0);
00082         print_if("Nr. samples received: %u\n",
00083              path, "sample_received", 1);
00084         print_if("Nr. backtrace aborted: %u\n", 
00085              path, "backtrace_aborted", 0);
00086         print_if("Nr. samples lost invalid pc: %u\n", 
00087              path, "sample_invalid_eip", 0);
00088     }
00089     closedir(dir);
00090 out:
00091     fflush(stdout);
00092 }

Generated on 8 Nov 2012 for Oprofile by  doxygen 1.6.1