traced_probes: Add sde/tracing_mark_write event

Change-Id: I2f255d39523824a9e5ac146aa71b4b55620d191f
diff --git a/Android.bp b/Android.bp
index a41c143..9dcfc2a 100644
--- a/Android.bp
+++ b/Android.bp
@@ -2764,6 +2764,7 @@
     "protos/perfetto/trace/ftrace/raw_syscalls.proto",
     "protos/perfetto/trace/ftrace/regulator.proto",
     "protos/perfetto/trace/ftrace/sched.proto",
+    "protos/perfetto/trace/ftrace/sde.proto",
     "protos/perfetto/trace/ftrace/signal.proto",
     "protos/perfetto/trace/ftrace/sync.proto",
     "protos/perfetto/trace/ftrace/systrace.proto",
@@ -2803,6 +2804,7 @@
     "external/perfetto/protos/perfetto/trace/ftrace/raw_syscalls.pb.cc",
     "external/perfetto/protos/perfetto/trace/ftrace/regulator.pb.cc",
     "external/perfetto/protos/perfetto/trace/ftrace/sched.pb.cc",
+    "external/perfetto/protos/perfetto/trace/ftrace/sde.pb.cc",
     "external/perfetto/protos/perfetto/trace/ftrace/signal.pb.cc",
     "external/perfetto/protos/perfetto/trace/ftrace/sync.pb.cc",
     "external/perfetto/protos/perfetto/trace/ftrace/systrace.pb.cc",
@@ -2843,6 +2845,7 @@
     "protos/perfetto/trace/ftrace/raw_syscalls.proto",
     "protos/perfetto/trace/ftrace/regulator.proto",
     "protos/perfetto/trace/ftrace/sched.proto",
+    "protos/perfetto/trace/ftrace/sde.proto",
     "protos/perfetto/trace/ftrace/signal.proto",
     "protos/perfetto/trace/ftrace/sync.proto",
     "protos/perfetto/trace/ftrace/systrace.proto",
@@ -2882,6 +2885,7 @@
     "external/perfetto/protos/perfetto/trace/ftrace/raw_syscalls.pb.h",
     "external/perfetto/protos/perfetto/trace/ftrace/regulator.pb.h",
     "external/perfetto/protos/perfetto/trace/ftrace/sched.pb.h",
+    "external/perfetto/protos/perfetto/trace/ftrace/sde.pb.h",
     "external/perfetto/protos/perfetto/trace/ftrace/signal.pb.h",
     "external/perfetto/protos/perfetto/trace/ftrace/sync.pb.h",
     "external/perfetto/protos/perfetto/trace/ftrace/systrace.pb.h",
@@ -2926,6 +2930,7 @@
     "protos/perfetto/trace/ftrace/raw_syscalls.proto",
     "protos/perfetto/trace/ftrace/regulator.proto",
     "protos/perfetto/trace/ftrace/sched.proto",
+    "protos/perfetto/trace/ftrace/sde.proto",
     "protos/perfetto/trace/ftrace/signal.proto",
     "protos/perfetto/trace/ftrace/sync.proto",
     "protos/perfetto/trace/ftrace/systrace.proto",
@@ -2966,6 +2971,7 @@
     "external/perfetto/protos/perfetto/trace/ftrace/raw_syscalls.pbzero.cc",
     "external/perfetto/protos/perfetto/trace/ftrace/regulator.pbzero.cc",
     "external/perfetto/protos/perfetto/trace/ftrace/sched.pbzero.cc",
+    "external/perfetto/protos/perfetto/trace/ftrace/sde.pbzero.cc",
     "external/perfetto/protos/perfetto/trace/ftrace/signal.pbzero.cc",
     "external/perfetto/protos/perfetto/trace/ftrace/sync.pbzero.cc",
     "external/perfetto/protos/perfetto/trace/ftrace/systrace.pbzero.cc",
@@ -3006,6 +3012,7 @@
     "protos/perfetto/trace/ftrace/raw_syscalls.proto",
     "protos/perfetto/trace/ftrace/regulator.proto",
     "protos/perfetto/trace/ftrace/sched.proto",
+    "protos/perfetto/trace/ftrace/sde.proto",
     "protos/perfetto/trace/ftrace/signal.proto",
     "protos/perfetto/trace/ftrace/sync.proto",
     "protos/perfetto/trace/ftrace/systrace.proto",
@@ -3046,6 +3053,7 @@
     "external/perfetto/protos/perfetto/trace/ftrace/raw_syscalls.pbzero.h",
     "external/perfetto/protos/perfetto/trace/ftrace/regulator.pbzero.h",
     "external/perfetto/protos/perfetto/trace/ftrace/sched.pbzero.h",
+    "external/perfetto/protos/perfetto/trace/ftrace/sde.pbzero.h",
     "external/perfetto/protos/perfetto/trace/ftrace/signal.pbzero.h",
     "external/perfetto/protos/perfetto/trace/ftrace/sync.pbzero.h",
     "external/perfetto/protos/perfetto/trace/ftrace/systrace.pbzero.h",
diff --git a/BUILD b/BUILD
index 30d9281..5924c7b 100644
--- a/BUILD
+++ b/BUILD
@@ -1880,6 +1880,7 @@
         "protos/perfetto/trace/ftrace/raw_syscalls.proto",
         "protos/perfetto/trace/ftrace/regulator.proto",
         "protos/perfetto/trace/ftrace/sched.proto",
+        "protos/perfetto/trace/ftrace/sde.proto",
         "protos/perfetto/trace/ftrace/signal.proto",
         "protos/perfetto/trace/ftrace/sync.proto",
         "protos/perfetto/trace/ftrace/systrace.proto",
diff --git a/protos/perfetto/trace/ftrace/all_protos.gni b/protos/perfetto/trace/ftrace/all_protos.gni
index b6278b8..a8ae6b4 100644
--- a/protos/perfetto/trace/ftrace/all_protos.gni
+++ b/protos/perfetto/trace/ftrace/all_protos.gni
@@ -42,6 +42,7 @@
   "raw_syscalls.proto",
   "regulator.proto",
   "sched.proto",
+  "sde.proto",
   "signal.proto",
   "sync.proto",
   "systrace.proto",
diff --git a/protos/perfetto/trace/ftrace/ftrace_event.proto b/protos/perfetto/trace/ftrace/ftrace_event.proto
index c953f36..e3d8bef 100644
--- a/protos/perfetto/trace/ftrace/ftrace_event.proto
+++ b/protos/perfetto/trace/ftrace/ftrace_event.proto
@@ -27,6 +27,7 @@
 import "protos/perfetto/trace/ftrace/raw_syscalls.proto";
 import "protos/perfetto/trace/ftrace/regulator.proto";
 import "protos/perfetto/trace/ftrace/sched.proto";
+import "protos/perfetto/trace/ftrace/sde.proto";
 import "protos/perfetto/trace/ftrace/signal.proto";
 import "protos/perfetto/trace/ftrace/sync.proto";
 import "protos/perfetto/trace/ftrace/systrace.proto";
@@ -395,5 +396,6 @@
     SysExitFtraceEvent sys_exit = 330;
     ZeroFtraceEvent zero = 331;
     GpuFrequencyFtraceEvent gpu_frequency = 332;
+    SdeTracingMarkWriteFtraceEvent sde_tracing_mark_write = 333;
   }
 }
diff --git a/protos/perfetto/trace/ftrace/sde.proto b/protos/perfetto/trace/ftrace/sde.proto
new file mode 100644
index 0000000..aafa486
--- /dev/null
+++ b/protos/perfetto/trace/ftrace/sde.proto
@@ -0,0 +1,14 @@
+// Autogenerated by:
+// ../../tools/ftrace_proto_gen/ftrace_proto_gen.cc
+// Do not edit.
+
+syntax = "proto2";
+option optimize_for = LITE_RUNTIME;
+package perfetto.protos;
+
+message SdeTracingMarkWriteFtraceEvent {
+  optional int32 pid = 1;
+  optional string trace_name = 2;
+  optional uint32 trace_type = 3;
+  optional int32 value = 4;
+}
diff --git a/protos/perfetto/trace/perfetto_trace.proto b/protos/perfetto/trace/perfetto_trace.proto
index 1df23ca..dd63bea 100644
--- a/protos/perfetto/trace/perfetto_trace.proto
+++ b/protos/perfetto/trace/perfetto_trace.proto
@@ -2295,6 +2295,7 @@
     SysExitFtraceEvent sys_exit = 330;
     ZeroFtraceEvent zero = 331;
     GpuFrequencyFtraceEvent gpu_frequency = 332;
+    // removed field with id 333
   }
 }
 
diff --git a/src/protozero/test/example_proto/test_messages.descriptor.h b/src/protozero/test/example_proto/test_messages.descriptor.h
index 9d0affc..6e0ff15 100644
--- a/src/protozero/test/example_proto/test_messages.descriptor.h
+++ b/src/protozero/test/example_proto/test_messages.descriptor.h
@@ -209,19 +209,19 @@
      0x72, 0x42, 0x61, 0x7a, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x72, 0x42,
      0x61, 0x7a, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x62, 0x61,
      0x72, 0x42, 0x61, 0x7a, 0x12, 0x16, 0x0a, 0x06, 0x4d, 0x6f, 0x6f, 0x4d,
-     0x6f, 0x6f, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x6d, 0x6f,
+     0x6f, 0x6f, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x4d, 0x6f,
      0x6f, 0x4d, 0x6f, 0x6f, 0x12, 0x1e, 0x0a, 0x0a, 0x55, 0x52, 0x4c, 0x45,
      0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08,
-     0x52, 0x0a, 0x75, 0x52, 0x4c, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72,
+     0x52, 0x0a, 0x55, 0x52, 0x4c, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72,
      0x12, 0x12, 0x0a, 0x04, 0x58, 0x4d, 0x61, 0x70, 0x18, 0x05, 0x20, 0x01,
-     0x28, 0x08, 0x52, 0x04, 0x78, 0x4d, 0x61, 0x70, 0x12, 0x21, 0x0a, 0x0d,
+     0x28, 0x08, 0x52, 0x04, 0x58, 0x4d, 0x61, 0x70, 0x12, 0x21, 0x0a, 0x0d,
      0x55, 0x72, 0x4c, 0x45, 0x5f, 0x6e, 0x63, 0x6f, 0x5f, 0x5f, 0x64, 0x65,
-     0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x75, 0x72, 0x4c,
+     0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x55, 0x72, 0x4c,
      0x45, 0x4e, 0x63, 0x6f, 0x44, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x09, 0x5f,
      0x5f, 0x62, 0x69, 0x67, 0x42, 0x61, 0x6e, 0x67, 0x18, 0x07, 0x20, 0x01,
-     0x28, 0x08, 0x52, 0x07, 0x62, 0x69, 0x67, 0x42, 0x61, 0x6e, 0x67, 0x12,
+     0x28, 0x08, 0x52, 0x07, 0x42, 0x69, 0x67, 0x42, 0x61, 0x6e, 0x67, 0x12,
      0x0e, 0x0a, 0x02, 0x55, 0x32, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, 0x52,
-     0x02, 0x75, 0x32, 0x12, 0x1a, 0x0a, 0x09, 0x62, 0x61, 0x6e, 0x67, 0x42,
+     0x02, 0x55, 0x32, 0x12, 0x1a, 0x0a, 0x09, 0x62, 0x61, 0x6e, 0x67, 0x42,
      0x69, 0x67, 0x5f, 0x5f, 0x18, 0x09, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07,
      0x62, 0x61, 0x6e, 0x67, 0x42, 0x69, 0x67, 0x22, 0x8f, 0x01, 0x0a, 0x14,
      0x50, 0x61, 0x63, 0x6b, 0x65, 0x64, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74,
diff --git a/src/trace_processor/importers/ftrace/ftrace_descriptors.cc b/src/trace_processor/importers/ftrace/ftrace_descriptors.cc
index 4c49442..38b23a1 100644
--- a/src/trace_processor/importers/ftrace/ftrace_descriptors.cc
+++ b/src/trace_processor/importers/ftrace/ftrace_descriptors.cc
@@ -8,7 +8,7 @@
 namespace trace_processor {
 namespace {
 
-std::array<MessageDescriptor, 333> descriptors{{
+std::array<MessageDescriptor, 334> descriptors{{
     {nullptr, 0, {}},
     {nullptr, 0, {}},
     {nullptr, 0, {}},
@@ -3537,6 +3537,17 @@
             {"state", ProtoSchemaType::kUint32},
         },
     },
+    {
+        "sde_tracing_mark_write",
+        4,
+        {
+            {},
+            {"pid", ProtoSchemaType::kInt32},
+            {"trace_name", ProtoSchemaType::kString},
+            {"trace_type", ProtoSchemaType::kUint32},
+            {"value", ProtoSchemaType::kInt32},
+        },
+    },
 }};
 
 }  // namespace
diff --git a/src/trace_processor/importers/ftrace/ftrace_parser.cc b/src/trace_processor/importers/ftrace/ftrace_parser.cc
index fdd3828..2882a06 100644
--- a/src/trace_processor/importers/ftrace/ftrace_parser.cc
+++ b/src/trace_processor/importers/ftrace/ftrace_parser.cc
@@ -38,6 +38,7 @@
 #include "protos/perfetto/trace/ftrace/power.pbzero.h"
 #include "protos/perfetto/trace/ftrace/raw_syscalls.pbzero.h"
 #include "protos/perfetto/trace/ftrace/sched.pbzero.h"
+#include "protos/perfetto/trace/ftrace/sde.pbzero.h"
 #include "protos/perfetto/trace/ftrace/signal.pbzero.h"
 #include "protos/perfetto/trace/ftrace/systrace.pbzero.h"
 #include "protos/perfetto/trace/ftrace/task.pbzero.h"
@@ -260,11 +261,11 @@
         break;
       }
       case FtraceEvent::kPrintFieldNumber: {
-        ParsePrint(cpu, ts, pid, data);
+        ParsePrint(ts, pid, data);
         break;
       }
       case FtraceEvent::kZeroFieldNumber: {
-        ParseZero(cpu, ts, pid, data);
+        ParseZero(ts, pid, data);
         break;
       }
       case FtraceEvent::kRssStatFieldNumber: {
@@ -339,6 +340,10 @@
         ParseBinderLocked(ts, pid, data);
         break;
       }
+      case FtraceEvent::kSdeTracingMarkWriteFieldNumber: {
+        ParseSdeTracingMarkWrite(ts, pid, data);
+        break;
+      }
       default:
         break;
     }
@@ -516,24 +521,29 @@
   context_->event_tracker->PushCounter(ts, new_state, track);
 }
 
-void FtraceParser::ParsePrint(uint32_t,
-                              int64_t ts,
-                              uint32_t pid,
-                              ConstBytes blob) {
+void FtraceParser::ParsePrint(int64_t ts, uint32_t pid, ConstBytes blob) {
   protos::pbzero::PrintFtraceEvent::Decoder evt(blob.data, blob.size);
   context_->systrace_parser->ParsePrintEvent(ts, pid, evt.buf());
 }
 
-void FtraceParser::ParseZero(uint32_t,
-                             int64_t ts,
-                             uint32_t pid,
-                             ConstBytes blob) {
+void FtraceParser::ParseZero(int64_t ts, uint32_t pid, ConstBytes blob) {
   protos::pbzero::ZeroFtraceEvent::Decoder evt(blob.data, blob.size);
   uint32_t tgid = static_cast<uint32_t>(evt.pid());
   context_->systrace_parser->ParseZeroEvent(ts, pid, evt.flag(), evt.name(),
                                             tgid, evt.value());
 }
 
+void FtraceParser::ParseSdeTracingMarkWrite(int64_t ts,
+                                            uint32_t pid,
+                                            ConstBytes blob) {
+  protos::pbzero::SdeTracingMarkWriteFtraceEvent::Decoder evt(blob.data,
+                                                              blob.size);
+  uint32_t tgid = static_cast<uint32_t>(evt.pid());
+  context_->systrace_parser->ParseSdeTracingMarkWrite(
+      ts, pid, static_cast<char>(evt.trace_type()), evt.trace_name(),
+      tgid, evt.value());
+}
+
 void FtraceParser::ParseRssStat(int64_t ts, uint32_t pid, ConstBytes blob) {
   protos::pbzero::RssStatFtraceEvent::Decoder rss(blob.data, blob.size);
   const auto kRssStatUnknown = static_cast<uint32_t>(rss_members_.size()) - 1;
diff --git a/src/trace_processor/importers/ftrace/ftrace_parser.h b/src/trace_processor/importers/ftrace/ftrace_parser.h
index 3d7138b..15bc2ef 100644
--- a/src/trace_processor/importers/ftrace/ftrace_parser.h
+++ b/src/trace_processor/importers/ftrace/ftrace_parser.h
@@ -53,14 +53,11 @@
   void ParseCpuFreq(int64_t timestamp, protozero::ConstBytes);
   void ParseGpuFreq(int64_t timestamp, protozero::ConstBytes);
   void ParseCpuIdle(int64_t timestamp, protozero::ConstBytes);
-  void ParsePrint(uint32_t cpu,
-                  int64_t timestamp,
-                  uint32_t pid,
-                  protozero::ConstBytes);
-  void ParseZero(uint32_t cpu,
-                 int64_t timestamp,
-                 uint32_t pid,
-                 protozero::ConstBytes);
+  void ParsePrint(int64_t timestamp, uint32_t pid, protozero::ConstBytes);
+  void ParseZero(int64_t timestamp, uint32_t pid, protozero::ConstBytes);
+  void ParseSdeTracingMarkWrite(int64_t timestamp,
+                                uint32_t pid,
+                                protozero::ConstBytes);
   void ParseRssStat(int64_t ts, uint32_t pid, protozero::ConstBytes);
   void ParseIonHeapGrowOrShrink(int64_t ts,
                                 uint32_t pid,
diff --git a/src/trace_processor/importers/systrace/systrace_parser.cc b/src/trace_processor/importers/systrace/systrace_parser.cc
index 9e336a6..f99a29d 100644
--- a/src/trace_processor/importers/systrace/systrace_parser.cc
+++ b/src/trace_processor/importers/systrace/systrace_parser.cc
@@ -74,6 +74,26 @@
   context_->systrace_parser->ParseSystracePoint(ts, pid, point);
 }
 
+void SystraceParser::ParseSdeTracingMarkWrite(int64_t ts,
+                                              uint32_t pid,
+                                              char trace_type,
+                                              base::StringView trace_name,
+                                              uint32_t tgid,
+                                              int64_t value) {
+  systrace_utils::SystraceTracePoint point{};
+  point.name = trace_name;
+  point.tgid = tgid;
+  point.value = value;
+  point.phase = trace_type;
+
+  if (trace_type != 'B' && trace_type != 'E' && trace_type != 'C') {
+    context_->storage->IncrementStats(stats::systrace_parse_failure);
+    return;
+  }
+
+  context_->systrace_parser->ParseSystracePoint(ts, pid, point);
+}
+
 void SystraceParser::ParseSystracePoint(
     int64_t ts,
     uint32_t pid,
diff --git a/src/trace_processor/importers/systrace/systrace_parser.h b/src/trace_processor/importers/systrace/systrace_parser.h
index 569efd0..2dc7ea9 100644
--- a/src/trace_processor/importers/systrace/systrace_parser.h
+++ b/src/trace_processor/importers/systrace/systrace_parser.h
@@ -193,6 +193,13 @@
 
   void ParsePrintEvent(int64_t ts, uint32_t pid, base::StringView event);
 
+  void ParseSdeTracingMarkWrite(int64_t ts,
+                                uint32_t pid,
+                                char trace_type,
+                                base::StringView trace_name,
+                                uint32_t tgid,
+                                int64_t value);
+
   void ParseZeroEvent(int64_t ts,
                       uint32_t pid,
                       int32_t flag,
diff --git a/src/traced/probes/ftrace/event_info.cc b/src/traced/probes/ftrace/event_info.cc
index 6cd0e03..8fac8f6 100644
--- a/src/traced/probes/ftrace/event_info.cc
+++ b/src/traced/probes/ftrace/event_info.cc
@@ -5896,6 +5896,25 @@
        kUnsetFtraceId,
        242,
        kUnsetSize},
+      {"tracing_mark_write",
+       "sde",
+       {
+           {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
+            "pid", 1, ProtoSchemaType::kInt32,
+            TranslationStrategy::kInvalidTranslationStrategy},
+           {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
+            "trace_name", 2, ProtoSchemaType::kString,
+            TranslationStrategy::kInvalidTranslationStrategy},
+           {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
+            "trace_type", 3, ProtoSchemaType::kUint32,
+            TranslationStrategy::kInvalidTranslationStrategy},
+           {kUnsetOffset, kUnsetSize, FtraceFieldType::kInvalidFtraceFieldType,
+            "value", 4, ProtoSchemaType::kInt32,
+            TranslationStrategy::kInvalidTranslationStrategy},
+       },
+       kUnsetFtraceId,
+       333,
+       kUnsetSize},
       {"signal_deliver",
        "signal",
        {
diff --git a/src/traced/probes/ftrace/test/data/synthetic/available_events b/src/traced/probes/ftrace/test/data/synthetic/available_events
index 28798fa..500dcb2 100644
--- a/src/traced/probes/ftrace/test/data/synthetic/available_events
+++ b/src/traced/probes/ftrace/test/data/synthetic/available_events
@@ -6,3 +6,4 @@
 clk:clk_enable
 clk:clk_disable
 clk:clk_set_rate
+sde:tracing_mark_write
diff --git a/src/traced/probes/ftrace/test/data/synthetic/events/sde/tracing_mark_write/format b/src/traced/probes/ftrace/test/data/synthetic/events/sde/tracing_mark_write/format
new file mode 100644
index 0000000..a3c50cb
--- /dev/null
+++ b/src/traced/probes/ftrace/test/data/synthetic/events/sde/tracing_mark_write/format
@@ -0,0 +1,14 @@
+name: tracing_mark_write
+ID: 638
+format:
+	field:unsigned short common_type;	offset:0;	size:2;	signed:0;
+	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;
+	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;
+	field:int common_pid;	offset:4;	size:4;	signed:1;
+
+	field:char trace_type;	offset:8;	size:1;	signed:0;
+	field:int pid;	offset:12;	size:4;	signed:1;
+	field:__data_loc char[] trace_name;	offset:16;	size:4;	signed:0;
+	field:int value;	offset:20;	size:4;	signed:1;
+
+print fmt: "%c|%d|%s|%d", REC->trace_type, REC->pid, __get_str(trace_name), REC->value
diff --git a/tools/ftrace_proto_gen/event_whitelist b/tools/ftrace_proto_gen/event_whitelist
index e0662ce..c788314 100644
--- a/tools/ftrace_proto_gen/event_whitelist
+++ b/tools/ftrace_proto_gen/event_whitelist
@@ -327,3 +327,4 @@
 raw_syscalls/sys_exit
 systrace/0
 power/gpu_frequency
+sde/tracing_mark_write
diff --git a/tools/ftrace_proto_gen/ftrace_proto_gen.cc b/tools/ftrace_proto_gen/ftrace_proto_gen.cc
index e6c9ebd..51bc970 100644
--- a/tools/ftrace_proto_gen/ftrace_proto_gen.cc
+++ b/tools/ftrace_proto_gen/ftrace_proto_gen.cc
@@ -34,12 +34,18 @@
 using base::StartsWith;
 using base::Contains;
 
-std::string EventNameToProtoFieldName(const std::string& name) {
-  return (name == "0") ? "zero" : name;
+std::string EventNameToProtoFieldName(const std::string& group,
+                                      const std::string& name) {
+  std::string event_name = (name == "0") ? "zero" : name;
+  if (group == "sde") {
+    event_name = "sde_" + event_name;
+  }
+  return event_name;
 }
 
-std::string EventNameToProtoName(const std::string& name) {
-  return ToCamelCase(EventNameToProtoFieldName(name)) + "FtraceEvent";
+std::string EventNameToProtoName(const std::string& group,
+                                 const std::string& name) {
+  return ToCamelCase(EventNameToProtoFieldName(group, name)) + "FtraceEvent";
 }
 
 std::vector<FtraceEventName> ReadWhitelist(const std::string& filename) {
@@ -57,8 +63,10 @@
   return lines;
 }
 
-bool GenerateProto(const FtraceEvent& format, Proto* proto_out) {
-  proto_out->name = EventNameToProtoName(format.name);
+bool GenerateProto(const std::string& group,
+                   const FtraceEvent& format,
+                   Proto* proto_out) {
+  proto_out->name = EventNameToProtoName(group, format.name);
   proto_out->event_name = format.name;
   std::set<std::string> seen;
   // TODO(hjd): We should be cleverer about id assignment.
@@ -125,8 +133,9 @@
       continue;
     }
 
-    std::string field_name = EventNameToProtoFieldName(event.name());
-    std::string type_name = EventNameToProtoName(event.name());
+    std::string field_name =
+        EventNameToProtoFieldName(event.group(), event.name());
+    std::string type_name = EventNameToProtoName(event.group(), event.name());
 
     // "    " (indent) + TypeName + " " + field_name + " = " + 123 + ";"
     if (4 + type_name.size() + 1 + field_name.size() + 3 + 3 + 1 <= 80) {
diff --git a/tools/ftrace_proto_gen/ftrace_proto_gen.h b/tools/ftrace_proto_gen/ftrace_proto_gen.h
index 7258737..f9faed4 100644
--- a/tools/ftrace_proto_gen/ftrace_proto_gen.h
+++ b/tools/ftrace_proto_gen/ftrace_proto_gen.h
@@ -29,8 +29,14 @@
 
 namespace perfetto {
 
-std::string EventNameToProtoName(const std::string&);
-std::string EventNameToProtoFieldName(const std::string&);
+bool GenerateProto(const std::string& group,
+                   const FtraceEvent& format,
+                   Proto* proto_out);
+
+std::string EventNameToProtoName(const std::string& group,
+                                 const std::string& name);
+std::string EventNameToProtoFieldName(const std::string& group,
+                                      const std::string& name);
 
 std::vector<FtraceEventName> ReadWhitelist(const std::string& filename);
 void GenerateFtraceEventProto(const std::vector<FtraceEventName>& raw_whitelist,
diff --git a/tools/ftrace_proto_gen/ftrace_proto_gen_unittest.cc b/tools/ftrace_proto_gen/ftrace_proto_gen_unittest.cc
index 6d0d46d..8237929 100644
--- a/tools/ftrace_proto_gen/ftrace_proto_gen_unittest.cc
+++ b/tools/ftrace_proto_gen/ftrace_proto_gen_unittest.cc
@@ -62,7 +62,7 @@
   Proto output;
   input.name = "the_snake_case_name";
 
-  GenerateProto(input, &output);
+  GenerateProto("group", input, &output);
 
   EXPECT_EQ(output.name, "TheSnakeCaseNameFtraceEvent");
 }
diff --git a/tools/ftrace_proto_gen/main.cc b/tools/ftrace_proto_gen/main.cc
index 65f2e2d..d051c4a 100644
--- a/tools/ftrace_proto_gen/main.cc
+++ b/tools/ftrace_proto_gen/main.cc
@@ -162,7 +162,8 @@
       if (!event.valid())
         continue;
 
-      std::string proto_name = perfetto::EventNameToProtoName(event.name());
+      std::string proto_name =
+          perfetto::EventNameToProtoName(group, event.name());
       perfetto::Proto proto;
       proto.name = proto_name;
       proto.event_name = event.name();
@@ -190,7 +191,7 @@
         }
 
         perfetto::Proto event_proto;
-        if (!perfetto::GenerateProto(format, &event_proto)) {
+        if (!perfetto::GenerateProto(group, format, &event_proto)) {
           fprintf(stderr, "Could not generate proto for file %s\n",
                   input_path.c_str());
           return 1;
diff --git a/tools/ftrace_proto_gen/proto_gen_utils.h b/tools/ftrace_proto_gen/proto_gen_utils.h
index 2d558ca..805c402 100644
--- a/tools/ftrace_proto_gen/proto_gen_utils.h
+++ b/tools/ftrace_proto_gen/proto_gen_utils.h
@@ -90,7 +90,6 @@
 std::string ToCamelCase(const std::string& s);
 ProtoType GetCommon(ProtoType one, ProtoType other);
 std::string ProtoHeader();
-bool GenerateProto(const FtraceEvent& format, Proto* proto_out);
 ProtoType InferProtoType(const FtraceEvent::Field& field);
 
 }  // namespace perfetto