summaryrefslogtreecommitdiffstats
path: root/meta/packages/oprofile/oprofile/cg_collection.patch
blob: a87ec7247701ae0edb274d1d7737c6baf4269747 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
 ChangeLog                     |   12 ++++++++++++
 libpp/callgraph_container.cpp |   21 +++++++++++++--------
 libpp/callgraph_container.h   |    7 ++++---
 libpp/format_output.cpp       |   22 +++++++++++-----------
 libpp/format_output.h         |    2 +-
 libpp/symbol.h                |   14 ++++++++------
 libpp/symbol_sort.cpp         |   17 -----------------
 libpp/symbol_sort.h           |    6 ------
 pp/opreport.cpp               |    3 ++-
 9 files changed, 51 insertions(+), 53 deletions(-)

Index: oprofile/libpp/callgraph_container.cpp
===================================================================
--- oprofile.orig/libpp/callgraph_container.cpp
+++ oprofile/libpp/callgraph_container.cpp
@@ -379,12 +379,15 @@ process(count_array_t total, double thre
 
 		process_children(sym, threshold);
 
-		cg_syms.push_back(sym);
+		cg_syms_objs.push_back(sym);
 	}
+
+	for (unsigned int i = 0; i < cg_syms_objs.size(); i++)
+		cg_syms.push_back(&cg_syms_objs[i]);
 }
 
 
-cg_collection arc_recorder::get_symbols() const
+symbol_collection arc_recorder::get_symbols() const
 {
 	return cg_syms;
 }
@@ -580,12 +583,14 @@ column_flags callgraph_container::output
 	column_flags output_hints = cf_none;
 
 	// FIXME: costly: must we access directly recorder map ?
-	cg_collection syms = recorder.get_symbols();
+	symbol_collection syms = recorder.get_symbols();
 
-	cg_collection::const_iterator it;
-	cg_collection::const_iterator const end = syms.end();
-	for (it = syms.begin(); it != end; ++it)
-		output_hints = it->output_hint(output_hints);
+	symbol_collection::iterator it;
+	symbol_collection::iterator const end = syms.end();
+	for (it = syms.begin(); it != end; ++it) {
+		cg_symbol const *cg_symb = dynamic_cast<const cg_symbol *>(*it);
+		output_hints = cg_symb->output_hint(output_hints);
+	}
 
 	return output_hints;
 }
@@ -597,7 +602,7 @@ count_array_t callgraph_container::sampl
 }
 
 
-cg_collection callgraph_container::get_symbols() const
+symbol_collection callgraph_container::get_symbols() const
 {
 	return recorder.get_symbols();
 }
Index: oprofile/libpp/callgraph_container.h
===================================================================
--- oprofile.orig/libpp/callgraph_container.h
+++ oprofile/libpp/callgraph_container.h
@@ -53,7 +53,7 @@ public:
 	         count_array_t const & arc_count);
 
 	/// return all the cg symbols
-	cg_collection get_symbols() const;
+	symbol_collection get_symbols() const;
 
 	/**
 	 * After population, build the final output, and do
@@ -91,7 +91,8 @@ private:
 	map_t sym_map;
 
 	/// final output data
-	cg_collection cg_syms;
+	symbol_collection cg_syms;
+	cg_collection_objs cg_syms_objs;
 };
 
 
@@ -126,7 +127,7 @@ public:
 	count_array_t samples_count() const;
 
 	// return all the cg symbols
-	cg_collection get_symbols() const;
+	symbol_collection get_symbols() const;
 
 private:
 	/**
Index: oprofile/libpp/format_output.cpp
===================================================================
--- oprofile.orig/libpp/format_output.cpp
+++ oprofile/libpp/format_output.cpp
@@ -489,7 +489,7 @@ cg_formatter::cg_formatter(callgraph_con
 }
 
 
-void cg_formatter::output(ostream & out, cg_collection const & syms)
+void cg_formatter::output(ostream & out, symbol_collection const & syms)
 {
 	// amount of spacing prefixing child and parent lines
 	string const child_parent_prefix("  ");
@@ -498,37 +498,37 @@ void cg_formatter::output(ostream & out,
 
 	out << string(79, '-') << endl;
 
-	cg_collection::const_iterator it;
-	cg_collection::const_iterator end = syms.end();
+	symbol_collection::const_iterator it;
+	symbol_collection::const_iterator end = syms.end();
 
 	for (it = syms.begin(); it < end; ++it) {
-		cg_symbol const & sym = *it;
+		cg_symbol const *sym = dynamic_cast<const cg_symbol *>(*it);
 
 		cg_symbol::children::const_iterator cit;
-		cg_symbol::children::const_iterator cend = sym.callers.end();
+		cg_symbol::children::const_iterator cend = sym->callers.end();
 
 		counts_t c;
 		if (global_percent)
 			c.total = counts.total;
 		else
-			c.total = sym.total_caller_count;
+			c.total = sym->total_caller_count;
 
-		for (cit = sym.callers.begin(); cit != cend; ++cit) {
+		for (cit = sym->callers.begin(); cit != cend; ++cit) {
 			out << child_parent_prefix;
 			do_output(out, *cit, cit->sample, c);
 		}
 
-		do_output(out, sym, sym.sample, counts);
+		do_output(out, *sym, sym->sample, counts);
 
 		c = counts_t();
 		if (global_percent)
 			c.total = counts.total;
 		else
-			c.total = sym.total_callee_count;
+			c.total = sym->total_callee_count;
 
-		cend = sym.callees.end();
+		cend = sym->callees.end();
 
-		for (cit = sym.callees.begin(); cit != cend; ++cit) {
+		for (cit = sym->callees.begin(); cit != cend; ++cit) {
 			out << child_parent_prefix;
 			do_output(out, *cit, cit->sample, c);
 		}
Index: oprofile/libpp/symbol.h
===================================================================
--- oprofile.orig/libpp/symbol.h
+++ oprofile/libpp/symbol.h
@@ -56,8 +56,11 @@ struct sample_entry {
 
 
 /// associate a symbol with a file location, samples count and vma address
-struct symbol_entry {
+class symbol_entry {
+public:
 	symbol_entry() : size(0) {}
+	virtual ~symbol_entry() {}
+
 	/// which image this symbol belongs to
 	image_name_id image_name;
 	/// owning application name: identical to image name if profiling
@@ -93,7 +96,8 @@ typedef std::vector<symbol_entry const *
  * the sample counts replaced with the relevant arc counts, whilst
  * the cg_symbol retains its self count.
  */
-struct cg_symbol : public symbol_entry {
+class cg_symbol : public symbol_entry {
+public:
 	cg_symbol(symbol_entry const & sym) : symbol_entry(sym) {}
 
 	typedef std::vector<symbol_entry> children;
@@ -109,10 +113,8 @@ struct cg_symbol : public symbol_entry {
 	count_array_t total_callee_count;
 };
 
-
-/// a collection of sorted callgraph symbols
-typedef std::vector<cg_symbol> cg_collection;
-
+/// a collection of sorted callgraph symbol objects
+typedef std::vector<cg_symbol> cg_collection_objs;
 
 /// for storing diff %ages
 typedef growable_vector<double> diff_array_t;
Index: oprofile/libpp/symbol_sort.cpp
===================================================================
--- oprofile.orig/libpp/symbol_sort.cpp
+++ oprofile/libpp/symbol_sort.cpp
@@ -146,23 +146,6 @@ sort(symbol_collection & syms, bool reve
 
 
 void sort_options::
-sort(cg_collection & syms, bool reverse_sort, bool lf) const
-{
-	long_filenames = lf;
-
-	vector<sort_order> sort_option(options);
-	for (sort_order cur = first; cur != last; cur = sort_order(cur + 1)) {
-		if (find(sort_option.begin(), sort_option.end(), cur) ==
-		    sort_option.end())
-			sort_option.push_back(cur);
-	}
-
-	stable_sort(syms.begin(), syms.end(),
-	            symbol_compare(sort_option, reverse_sort));
-}
-
-
-void sort_options::
 sort(diff_collection & syms, bool reverse_sort, bool lf) const
 {
 	long_filenames = lf;
Index: oprofile/libpp/symbol_sort.h
===================================================================
--- oprofile.orig/libpp/symbol_sort.h
+++ oprofile/libpp/symbol_sort.h
@@ -44,12 +44,6 @@ struct sort_options {
 	/**
 	 * Sort the given container by the given criteria.
 	 */
-	void sort(cg_collection & syms, bool reverse_sort,
-	          bool long_filenames) const;
-
-	/**
-	 * Sort the given container by the given criteria.
-	 */
 	void sort(diff_collection & syms, bool reverse_sort,
 	          bool long_filenames) const;
 
Index: oprofile/pp/opreport.cpp
===================================================================
--- oprofile.orig/pp/opreport.cpp
+++ oprofile/pp/opreport.cpp
@@ -445,7 +445,8 @@ void output_cg_symbols(callgraph_contain
 {
 	column_flags output_hints = cg.output_hint();
 
-	cg_collection symbols = cg.get_symbols();
+	symbol_collection symbols = cg.get_symbols();
+
 	options::sort_by.sort(symbols, options::reverse_sort,
 	                      options::long_filenames);
 
Index: oprofile/ChangeLog
===================================================================
--- oprofile.orig/ChangeLog
+++ oprofile/ChangeLog
@@ -1,5 +1,17 @@
 2007-05-09  Richard Purdie  <rpurdie@openedhand.com>
 
+	* libpp/callgraph_container.cpp:
+	* libpp/callgraph_container.h:
+	* libpp/format_output.cpp:
+	* libpp/format_output.h:
+	* libpp/symbol.h:
+	* libpp/symbol_sort.cpp:
+	* libpp/symbol_sort.h:
+	* pp/opreport.cpp: Convert cg_collection to symbol_collection and use
+	dynamic casting allowing more code reuse for callgraphs
+
+2007-05-09  Richard Purdie  <rpurdie@openedhand.com>
+
 	* oparchive.cpp:
 	* oparchive_options.cpp:
 	* oparchive_options.h: Add --list-files option to list all files that
Index: oprofile/libpp/format_output.h
===================================================================
--- oprofile.orig/libpp/format_output.h
+++ oprofile/libpp/format_output.h
@@ -201,7 +201,7 @@ public:
 
 	/** output callgraph information according to the previously format
 	 * specifier set by call(s) to add_format() */
-	void output(std::ostream & out, cg_collection const & syms);
+	void output(std::ostream & out, symbol_collection const & syms);
 };
 
 /// class to output a columned format symbols plus diff values