oprof_start_config.cpp
Go to the documentation of this file.00001
00012 #include <stdio.h>
00013
00014 #include <sstream>
00015 #include <fstream>
00016 #include <iomanip>
00017 #include <sys/utsname.h>
00018
00019 #include "string_manip.h"
00020 #include "oprof_start_config.h"
00021 #include "op_config.h"
00022 #include "op_config_24.h"
00023
00024 using namespace std;
00025
00026 event_setting::event_setting()
00027 :
00028 count(0),
00029 umask(0),
00030 os_ring_count(0),
00031 user_ring_count(0)
00032 {
00033 }
00034
00035
00036 config_setting::config_setting()
00037 :
00038 buffer_size(OP_DEFAULT_BUF_SIZE),
00039 note_table_size(OP_DEFAULT_NOTE_SIZE),
00040 no_kernel(false),
00041 verbose(false),
00042 separate_lib(false),
00043 separate_kernel(false),
00044 separate_cpu(false),
00045 separate_thread(false),
00046 callgraph_depth(0),
00047 buffer_watershed(0),
00048 cpu_buffer_size(0)
00049 {
00050 struct utsname info;
00051
00052
00053 if (uname(&info)) {
00054 perror("oprof_start: Unable to determine OS release.");
00055 } else {
00056 string const version(info.release);
00057 string const vmlinux_path("/lib/modules/" + version
00058 + "/build/vmlinux");
00059 kernel_filename = vmlinux_path;
00060 }
00061 }
00062
00063
00064 void config_setting::load(istream & in)
00065 {
00066 buffer_size = OP_DEFAULT_BUF_SIZE;
00067 note_table_size = OP_DEFAULT_NOTE_SIZE;
00068
00069 string str;
00070
00071 while (getline(in, str)) {
00072 string val = split(str, '=');
00073 if (str == "BUF_SIZE") {
00074 buffer_size = op_lexical_cast<unsigned int>(val);
00075 if (buffer_size < OP_DEFAULT_BUF_SIZE)
00076 buffer_size = OP_DEFAULT_BUF_SIZE;
00077 } else if (str == "NOTE_SIZE") {
00078 note_table_size = op_lexical_cast<unsigned int>(val);
00079 if (note_table_size < OP_DEFAULT_NOTE_SIZE)
00080 note_table_size = OP_DEFAULT_NOTE_SIZE;
00081 } else if (str == "VMLINUX") {
00082 if (val == "none") {
00083 kernel_filename = "";
00084 no_kernel = true;
00085 } else if (!val.empty()) {
00086 no_kernel = false;
00087 kernel_filename = val;
00088 }
00089 } else if (str == "SEPARATE_LIB") {
00090 separate_lib = op_lexical_cast<bool>(val);
00091 } else if (str == "SEPARATE_KERNEL") {
00092 separate_kernel = op_lexical_cast<bool>(val);
00093 } else if (str == "SEPARATE_CPU") {
00094 separate_cpu = op_lexical_cast<bool>(val);
00095 } else if (str == "SEPARATE_THREAD") {
00096 separate_thread = op_lexical_cast<bool>(val);
00097 } else if (str == "CALLGRAPH") {
00098 callgraph_depth = op_lexical_cast<unsigned int>(val);
00099 } else if (str == "BUF_WATERSHED") {
00100 buffer_watershed = op_lexical_cast<unsigned int>(val);
00101 } else if (str == "CPU_BUF_SIZE") {
00102 cpu_buffer_size = op_lexical_cast<unsigned int>(val);
00103 }
00104 }
00105 }
00106
00107
00108 istream & operator>>(istream & in, config_setting & object)
00109 {
00110 object.load(in);
00111 return in;
00112 }