[PATCH 3/6] apitrace: Allow comma separated lists in --calls and --frames options

Lawrence L Love lawlove at gmail.com
Fri Oct 11 15:05:56 PDT 2013


Allow a single comma-separated mixed list of files or ranges insted of
using multiple option calls for each one.
e.g., apitrace trim --calls=@foo.calls,0-20,100-150, at goo.calls,..

"CallSet::merge" parses for comma-delimited tokens in the input option
string and adds them to CallSet list

Signed-off-by: Lawrence L Love <lawrencex.l.love at intel.com>
---
 common/trace_callset.cpp | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/common/trace_callset.cpp b/common/trace_callset.cpp
index bb14595..1d50720 100644
--- a/common/trace_callset.cpp
+++ b/common/trace_callset.cpp
@@ -26,6 +26,7 @@
 
 #include <assert.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <limits>
 #include <fstream>
@@ -240,12 +241,26 @@ CallSet::merge(const char *string)
        *this = CallSet();
     }
 
-    if (*str == '@') {
-        FileCallSetParser parser(*this, &str[1]);
-        parser.parse();
-    } else {
-        StringCallSetParser parser(*this, str);
-        parser.parse();
-    }
+    /*
+     * Parse a comma-separated list of files or ranges
+     */
+
+    /* make writable copy of string to parse */
+    char *str = strdupa(string);
+
+    /* Use re-entrant version of strtok */
+    char *str_save;
+    str = strtok_r(str, ",", &str_save);
+
+    do {
+        if (*str == '@') {
+            FileCallSetParser parser(*this, &str[1]);
+            parser.parse();
+        } else {
+            StringCallSetParser parser(*this, str);
+            parser.parse();
+        }
+    } while ((str = strtok_r(NULL, ",", &str_save)) != NULL);
+    free((void*) str);
 }
 
-- 
1.8.4.rc3



More information about the apitrace mailing list