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

Lawrence L Love lawrencex.l.love at intel.com
Thu Oct 24 01:50:41 CEST 2013


From: Lawrence L Love <lawlove at gmail.com>

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 | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/common/trace_callset.cpp b/common/trace_callset.cpp
index 9b683c9..7b62ced 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>
@@ -243,11 +244,26 @@ CallSet::merge(const char *string)
         firstmerge = false;
     }
 
-    if (*string == '@') {
-        FileCallSetParser parser(*this, &string[1]);
-        parser.parse();
-    } else {
-        StringCallSetParser parser(*this, string);
-        parser.parse();
-    }
+    /*
+     * Parse a comma-separated list of files or ranges
+     */
+
+    /* make writable copy of string to parse */
+    char *str = strdupa(string);
+
+    /* 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