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

Lawrence L Love lawlove at gmail.com
Fri Oct 11 15:05:55 PDT 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 | 29 +++++++++++++++++------------
 common/trace_callset.hpp |  3 ++-
 retrace/retrace_main.cpp |  2 +-
 6 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/cli/cli_dump.cpp b/cli/cli_dump.cpp
index 1b53256..66949a2 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 3a9129f..8f57fc5 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 `" << opt << "`\n";
diff --git a/cli/cli_trim.cpp b/cli/cli_trim.cpp
index 59642d7..561328b 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..bb14595 100644
--- a/common/trace_callset.cpp
+++ b/common/trace_callset.cpp
@@ -223,18 +223,6 @@ public:
 };
 
 
-CallSet::CallSet(const char *string): limits(std::numeric_limits<CallNo>::min(), std::numeric_limits<CallNo>::max())
-{
-    if (*string == '@') {
-        FileCallSetParser parser(*this, &string[1]);
-        parser.parse();
-    } else {
-        StringCallSetParser parser(*this, string);
-        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();
@@ -244,3 +232,20 @@ CallSet::CallSet(CallFlags freq): limits(std::numeric_limits<CallNo>::min(), std
         assert(!empty());
     }
 }
+
+void
+CallSet::merge(const char *string)
+{
+    if (empty()) {
+       *this = CallSet();
+    }
+
+    if (*str == '@') {
+        FileCallSetParser parser(*this, &str[1]);
+        parser.parse();
+    } else {
+        StringCallSetParser parser(*this, str);
+        parser.parse();
+    }
+}
+
diff --git a/common/trace_callset.hpp b/common/trace_callset.hpp
index 35729c4..aa4860e 100644
--- a/common/trace_callset.hpp
+++ b/common/trace_callset.hpp
@@ -118,7 +118,8 @@ namespace trace {
 
         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