[PATCH] tracedump: add --help and --function-histogram
Alon Levy
alevy at redhat.com
Wed Sep 7 02:21:53 PDT 2011
---
trace_parser.cpp | 11 +++++++++++
trace_parser.hpp | 5 +++++
tracedump.cpp | 20 ++++++++++++++++++--
3 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/trace_parser.cpp b/trace_parser.cpp
index 44d1786..22f4049 100644
--- a/trace_parser.cpp
+++ b/trace_parser.cpp
@@ -128,6 +128,14 @@ Call *Parser::parse_call(void) {
}
+void Parser::print_function_histogram(void) {
+ std::map<std::string, int>::iterator it;
+
+ for (it = function_histogram.begin(); it != function_histogram.end(); ++it) {
+ std::cout << it->first << " " << it->second << "\n";
+ }
+}
+
/**
* Helper function to lookup an ID in a vector, resizing the vector if it doesn't fit.
*/
@@ -157,6 +165,9 @@ void Parser::parse_enter(void) {
}
sig->arg_names = arg_names;
functions[id] = sig;
+ function_histogram[sig->name] = 1;
+ } else {
+ function_histogram[sig->name] += 1;
}
assert(sig);
diff --git a/trace_parser.hpp b/trace_parser.hpp
index 4fff9ad..fe7c3c6 100644
--- a/trace_parser.hpp
+++ b/trace_parser.hpp
@@ -29,6 +29,7 @@
#include <iostream>
#include <list>
+#include <map>
#include "trace_format.hpp"
#include "trace_model.hpp"
@@ -60,6 +61,8 @@ protected:
unsigned next_call_no;
+ std::map<std::string, int> function_histogram;
+
public:
unsigned long long version;
@@ -73,6 +76,8 @@ public:
Call *parse_call(void);
+ void print_function_histogram(void);
+
protected:
void parse_enter(void);
diff --git a/tracedump.cpp b/tracedump.cpp
index c210a0c..b47754c 100644
--- a/tracedump.cpp
+++ b/tracedump.cpp
@@ -42,8 +42,11 @@ static void usage(void) {
"Usage: tracedump [OPTION] [TRACE...]\n"
"Dump TRACE to standard output.\n"
"\n"
+ " -h / --help show this help\n"
" --no-color no colored syntax highlightint\n"
" --no-colour alias for --no-color\n"
+ " --function-histogram\n"
+ " only show a function histogram\n"
;
}
@@ -51,6 +54,8 @@ static void usage(void) {
int main(int argc, char **argv)
{
int i;
+ bool function_histogram = false;
+ bool dump = true;
for (i = 1; i < argc; ++i) {
const char *arg = argv[i];
@@ -61,9 +66,16 @@ int main(int argc, char **argv)
if (!strcmp(arg, "--")) {
break;
+ } else if (!strcmp(arg, "--help") ||
+ !strcmp(arg, "-h")) {
+ usage();
+ return 1;
} else if (!strcmp(arg, "--no-color") ||
!strcmp(arg, "--no-colour")) {
color = false;
+ } else if (!strcmp(arg, "--function-histogram")) {
+ function_histogram = true;
+ dump = false;
} else {
std::cerr << "error: unknown option " << arg << "\n";
usage();
@@ -81,10 +93,14 @@ int main(int argc, char **argv)
Trace::Call *call;
while ((call = p.parse_call())) {
- call->dump(std::cout, color);
+ if (dump) {
+ call->dump(std::cout, color);
+ }
delete call;
}
+ if (function_histogram) {
+ p.print_function_histogram();
+ }
}
-
return 0;
}
--
1.7.6.1
More information about the apitrace
mailing list