[PATCH] apitrace: Allow multiple --calls and/or --frames input options

Lawrence L Love lawlove at gmail.com
Wed Oct 23 19:39:17 CEST 2013


Input for multiple files or ranges that seemed intuitive did not work

Only initialize CallSet list on first option call. If the option is
repeatedly used, continue adding to the same list.
e.g., apitrace trim --calls=@foo.calls --calls=0-20 --calls=...

The "CallSet::CallSet(const char *string)" constructor determined if the
option was a file or a range and then made the relative call to populate
the CallSet list. Rename that constructor to a public member function
"CallSet::merge(const char *string)" and call it from the command line
parser istead of constructing a new object each time the option is used.
In the renamed "merge" function, add a check to create the new CallSet
object only when the option is called the first time.

Modified modules that use this option: trim, dump, pickle, retrace

Signed-off-by: Lawrence L Love <lawrencex.l.love at intel.com>
---
 cli/cli_dump.cpp         |  2 +-
 cli/cli_pickle.cpp       |  2 +-
 cli/cli_trim.cpp         |  4 ++--
 common/trace_callset.cpp | 31 +++++++++++++++++++------------
 common/trace_callset.hpp |  6 ++++--
 retrace/retrace_main.cpp |  2 +-
 6 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/cli/cli_dump.cpp b/cli/cli_dump.cpp
index f37c027..abbffc8 100644
--- a/cli/cli_dump.cpp
+++ b/cli/cli_dump.cpp
@@ -115,7 +115,7 @@ command(int argc, char *argv[])
             verbose = true;
             break;
         case CALLS_OPT:
-            calls = trace::CallSet(optarg);
+            calls.merge(optarg);
             break;
         case COLOR_OPT:
             if (!optarg ||
diff --git a/cli/cli_pickle.cpp b/cli/cli_pickle.cpp
index 0605773..c237698 100644
--- a/cli/cli_pickle.cpp
+++ b/cli/cli_pickle.cpp
@@ -235,7 +235,7 @@ command(int argc, char *argv[])
             symbolic = true;
             break;
         case CALLS_OPT:
-            calls = trace::CallSet(optarg);
+            calls.merge(optarg);
             break;
         default:
             std::cerr << "error: unexpected option `" << (char)opt << "`\n";
diff --git a/cli/cli_trim.cpp b/cli/cli_trim.cpp
index 0d08c7d..0d96dbb 100644
--- a/cli/cli_trim.cpp
+++ b/cli/cli_trim.cpp
@@ -389,10 +389,10 @@ command(int argc, char *argv[])
             help();
             return 0;
         case CALLS_OPT:
-            options.calls = trace::CallSet(optarg);
+            options.calls.merge(optarg);
             break;
         case FRAMES_OPT:
-            options.frames = trace::CallSet(optarg);
+            options.frames.merge(optarg);
             break;
         case DEPS_OPT:
             options.dependency_analysis = true;
diff --git a/common/trace_callset.cpp b/common/trace_callset.cpp
index 0239028..9b683c9 100644
--- a/common/trace_callset.cpp
+++ b/common/trace_callset.cpp
@@ -223,8 +223,26 @@ public:
 };
 
 
-CallSet::CallSet(const char *string): limits(std::numeric_limits<CallNo>::min(), std::numeric_limits<CallNo>::max())
+CallSet::CallSet(CallFlags freq): limits(std::numeric_limits<CallNo>::min(), std::numeric_limits<CallNo>::max()), firstmerge(true) {
+    if (freq != FREQUENCY_NONE) {
+        CallNo start = std::numeric_limits<CallNo>::min();
+        CallNo stop = std::numeric_limits<CallNo>::max();
+        CallNo step = 1;
+        addRange(CallRange(start, stop, step, freq));
+        assert(!empty());
+    }
+}
+
+void
+CallSet::merge(const char *string)
 {
+    if (firstmerge) {
+        if (!empty()) {
+            *this = CallSet();
+        }
+        firstmerge = false;
+    }
+
     if (*string == '@') {
         FileCallSetParser parser(*this, &string[1]);
         parser.parse();
@@ -233,14 +251,3 @@ CallSet::CallSet(const char *string): limits(std::numeric_limits<CallNo>::min(),
         parser.parse();
     }
 }
-
-
-CallSet::CallSet(CallFlags freq): limits(std::numeric_limits<CallNo>::min(), std::numeric_limits<CallNo>::max()) {
-    if (freq != FREQUENCY_NONE) {
-        CallNo start = std::numeric_limits<CallNo>::min();
-        CallNo stop = std::numeric_limits<CallNo>::max();
-        CallNo step = 1;
-        addRange(CallRange(start, stop, step, freq));
-        assert(!empty());
-    }
-}
diff --git a/common/trace_callset.hpp b/common/trace_callset.hpp
index 35729c4..53bad98 100644
--- a/common/trace_callset.hpp
+++ b/common/trace_callset.hpp
@@ -104,6 +104,7 @@ namespace trace {
     {
     private:
         CallRange limits;
+        bool firstmerge;
 
     public:
         FastCallSet fast_call_set;
@@ -114,11 +115,12 @@ namespace trace {
         typedef std::list< CallRange > RangeList;
         RangeList ranges;
 
-        CallSet(): limits(std::numeric_limits<CallNo>::min(), std::numeric_limits<CallNo>::max()) {}
+        CallSet(): limits(std::numeric_limits<CallNo>::min(), std::numeric_limits<CallNo>::max()), firstmerge(true) {}
 
         CallSet(CallFlags freq);
 
-        CallSet(const char *str);
+        void
+        merge(const char *str);
 
         // Not empty set
         inline bool
diff --git a/retrace/retrace_main.cpp b/retrace/retrace_main.cpp
index bff8983..ef956da 100644
--- a/retrace/retrace_main.cpp
+++ b/retrace/retrace_main.cpp
@@ -705,7 +705,7 @@ int main(int argc, char **argv)
                 snapshotFormat = PNM_FMT;
             break;
         case 'S':
-            snapshotFrequency = trace::CallSet(optarg);
+            snapshotFrequency.merge(optarg);
             if (snapshotPrefix == NULL) {
                 snapshotPrefix = "";
             }
-- 
1.8.4.rc3



More information about the apitrace mailing list