1 /**
2 * @file oprof_start_config.cpp
3 * GUI startup config management
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 <stdio.h>
13
14 #include <sstream>
15 #include <fstream>
16 #include <iomanip>
17 #include <sys/utsname.h>
18
19 #include "string_manip.h"
20 #include "oprof_start_config.h"
21 #include "op_config.h"
22 #include "op_config_24.h"
23
24 using namespace std;
25
event_setting()26 event_setting::event_setting()
27 :
28 count(0),
29 umask(0),
30 os_ring_count(0),
31 user_ring_count(0)
32 {
33 }
34
35
config_setting()36 config_setting::config_setting()
37 :
38 buffer_size(OP_DEFAULT_BUF_SIZE),
39 note_table_size(OP_DEFAULT_NOTE_SIZE),
40 no_kernel(false),
41 verbose(false),
42 separate_lib(false),
43 separate_kernel(false),
44 separate_cpu(false),
45 separate_thread(false),
46 callgraph_depth(0),
47 buffer_watershed(0),
48 cpu_buffer_size(0)
49 {
50 struct utsname info;
51
52 /* Guess path to vmlinux based on kernel currently running. */
53 if (uname(&info)) {
54 perror("oprof_start: Unable to determine OS release.");
55 } else {
56 string const version(info.release);
57 string const vmlinux_path("/lib/modules/" + version
58 + "/build/vmlinux");
59 kernel_filename = vmlinux_path;
60 }
61 }
62
63
load(istream & in)64 void config_setting::load(istream & in)
65 {
66 buffer_size = OP_DEFAULT_BUF_SIZE;
67 note_table_size = OP_DEFAULT_NOTE_SIZE;
68
69 string str;
70
71 while (getline(in, str)) {
72 string val = split(str, '=');
73 if (str == "BUF_SIZE") {
74 buffer_size = op_lexical_cast<unsigned int>(val);
75 if (buffer_size < OP_DEFAULT_BUF_SIZE)
76 buffer_size = OP_DEFAULT_BUF_SIZE;
77 } else if (str == "NOTE_SIZE") {
78 note_table_size = op_lexical_cast<unsigned int>(val);
79 if (note_table_size < OP_DEFAULT_NOTE_SIZE)
80 note_table_size = OP_DEFAULT_NOTE_SIZE;
81 } else if (str == "VMLINUX") {
82 if (val == "none") {
83 kernel_filename = "";
84 no_kernel = true;
85 } else if (!val.empty()) {
86 no_kernel = false;
87 kernel_filename = val;
88 }
89 } else if (str == "SEPARATE_LIB") {
90 separate_lib = op_lexical_cast<bool>(val);
91 } else if (str == "SEPARATE_KERNEL") {
92 separate_kernel = op_lexical_cast<bool>(val);
93 } else if (str == "SEPARATE_CPU") {
94 separate_cpu = op_lexical_cast<bool>(val);
95 } else if (str == "SEPARATE_THREAD") {
96 separate_thread = op_lexical_cast<bool>(val);
97 } else if (str == "CALLGRAPH") {
98 callgraph_depth = op_lexical_cast<unsigned int>(val);
99 } else if (str == "BUF_WATERSHED") {
100 buffer_watershed = op_lexical_cast<unsigned int>(val);
101 } else if (str == "CPU_BUF_SIZE") {
102 cpu_buffer_size = op_lexical_cast<unsigned int>(val);
103 }
104 }
105 }
106
107
operator >>(istream & in,config_setting & object)108 istream & operator>>(istream & in, config_setting & object)
109 {
110 object.load(in);
111 return in;
112 }
113