Merge "Do not report errors for unsupported trace points"
diff --git a/src/trace_processor/proto_trace_parser.cc b/src/trace_processor/proto_trace_parser.cc
index 9f96676..e52e2ab 100644
--- a/src/trace_processor/proto_trace_parser.cc
+++ b/src/trace_processor/proto_trace_parser.cc
@@ -79,20 +79,24 @@
 // 2. B|1636|pokeUserActivity
 // 3. E|1636
 // 4. C|1636|wq:monitor|0
-bool ParseSystraceTracePoint(base::StringView str, SystraceTracePoint* out) {
+SystraceParseResult ParseSystraceTracePoint(base::StringView str,
+                                            SystraceTracePoint* out) {
   // THIS char* IS NOT NULL TERMINATED.
   const char* s = str.data();
   size_t len = str.size();
 
   if (len < 2)
-    return false;
+    return SystraceParseResult::kFailure;
 
   // If str matches '[BEC]\|[0-9]+[\|\n]' set tgid_length to the length of
-  // the number. Otherwise return false.
+  // the number. Otherwise return kFailure.
   if (s[1] != '|' && s[1] != '\n')
-    return false;
-  if (s[0] != 'B' && s[0] != 'E' && s[0] != 'C')
-    return false;
+    return SystraceParseResult::kFailure;
+  if (s[0] != 'B' && s[0] != 'E' && s[0] != 'C') {
+    // TODO: support android async slices
+    return s[0] == 'S' || s[0] == 'F' ? SystraceParseResult::kUnsupported
+                                      : SystraceParseResult::kFailure;
+  }
   size_t tgid_length = 0;
   for (size_t i = 2; i < len; i++) {
     if (s[i] == '|' || s[i] == '\n') {
@@ -100,7 +104,7 @@
       break;
     }
     if (s[i] < '0' || s[i] > '9')
-      return false;
+      return SystraceParseResult::kFailure;
   }
 
   if (tgid_length == 0) {
@@ -116,10 +120,10 @@
       size_t name_index = 2 + tgid_length + 1;
       out->name = base::StringView(
           s + name_index, len - name_index - (s[len - 1] == '\n' ? 1 : 0));
-      return true;
+      return SystraceParseResult::kSuccess;
     }
     case 'E': {
-      return true;
+      return SystraceParseResult::kSuccess;
     }
     case 'C': {
       size_t name_index = 2 + tgid_length + 1;
@@ -136,15 +140,15 @@
       size_t value_len = len - value_index;
       char value_str[32];
       if (value_len >= sizeof(value_str)) {
-        return false;
+        return SystraceParseResult::kFailure;
       }
       memcpy(value_str, s + value_index, value_len);
       value_str[value_len] = 0;
       out->value = std::stod(value_str);
-      return true;
+      return SystraceParseResult::kSuccess;
     }
     default:
-      return false;
+      return SystraceParseResult::kFailure;
   }
 }
 
@@ -780,8 +784,11 @@
                                   ConstBytes blob) {
   protos::pbzero::PrintFtraceEvent::Decoder evt(blob.data, blob.size);
   SystraceTracePoint point{};
-  if (!ParseSystraceTracePoint(evt.buf(), &point)) {
-    context_->storage->IncrementStats(stats::systrace_parse_failure);
+  auto r = ParseSystraceTracePoint(evt.buf(), &point);
+  if (r != SystraceParseResult::kSuccess) {
+    if (r == SystraceParseResult::kFailure) {
+      context_->storage->IncrementStats(stats::systrace_parse_failure);
+    }
     return;
   }
 
diff --git a/src/trace_processor/proto_trace_parser.h b/src/trace_processor/proto_trace_parser.h
index 73dd6f9..e0ea463 100644
--- a/src/trace_processor/proto_trace_parser.h
+++ b/src/trace_processor/proto_trace_parser.h
@@ -51,7 +51,10 @@
          std::tie(y.phase, y.tgid, y.name, y.value);
 }
 
-bool ParseSystraceTracePoint(base::StringView, SystraceTracePoint* out);
+enum class SystraceParseResult { kFailure = 0, kUnsupported, kSuccess };
+
+SystraceParseResult ParseSystraceTracePoint(base::StringView,
+                                            SystraceTracePoint* out);
 
 class ProtoTraceParser : public TraceParser {
  public:
diff --git a/src/trace_processor/proto_trace_parser_unittest.cc b/src/trace_processor/proto_trace_parser_unittest.cc
index 27cf617..78a84e1 100644
--- a/src/trace_processor/proto_trace_parser_unittest.cc
+++ b/src/trace_processor/proto_trace_parser_unittest.cc
@@ -505,17 +505,23 @@
 TEST(SystraceParserTest, SystraceEvent) {
   SystraceTracePoint result{};
 
-  ASSERT_FALSE(ParseSystraceTracePoint(base::StringView(""), &result));
+  ASSERT_EQ(ParseSystraceTracePoint(base::StringView(""), &result),
+            SystraceParseResult::kFailure);
 
-  ASSERT_TRUE(ParseSystraceTracePoint(base::StringView("B|1|foo"), &result));
+  ASSERT_EQ(ParseSystraceTracePoint(base::StringView("B|1|foo"), &result),
+            SystraceParseResult::kSuccess);
   EXPECT_EQ(result, (SystraceTracePoint{'B', 1, base::StringView("foo"), 0}));
 
-  ASSERT_TRUE(ParseSystraceTracePoint(base::StringView("B|42|Bar"), &result));
+  ASSERT_EQ(ParseSystraceTracePoint(base::StringView("B|42|Bar"), &result),
+            SystraceParseResult::kSuccess);
   EXPECT_EQ(result, (SystraceTracePoint{'B', 42, base::StringView("Bar"), 0}));
 
-  ASSERT_TRUE(
-      ParseSystraceTracePoint(base::StringView("C|543|foo|8"), &result));
+  ASSERT_EQ(ParseSystraceTracePoint(base::StringView("C|543|foo|8"), &result),
+            SystraceParseResult::kSuccess);
   EXPECT_EQ(result, (SystraceTracePoint{'C', 543, base::StringView("foo"), 8}));
+
+  ASSERT_EQ(ParseSystraceTracePoint(base::StringView("S|"), &result),
+            SystraceParseResult::kUnsupported);
 }
 
 // TODO(eseckler): Add tests for TrackEvent tokenization + parsing once they are