Merge "simpleperf: fix parsing perf.data generated by --trace-offcpu option."
diff --git a/simpleperf/report_lib_interface.cpp b/simpleperf/report_lib_interface.cpp
index c7a606c..e3af8a8 100644
--- a/simpleperf/report_lib_interface.cpp
+++ b/simpleperf/report_lib_interface.cpp
@@ -285,8 +285,13 @@
         event_attrs_.push_back(attr);
       }
     }
-    size_t attr_index =
-        record_file_reader_->GetAttrIndexOfRecord(current_record_.get());
+    size_t attr_index;
+    if (trace_offcpu_) {
+      // For trace-offcpu, we don't want to show event sched:sched_switch.
+      attr_index = 0;
+    } else {
+      attr_index = record_file_reader_->GetAttrIndexOfRecord(current_record_.get());
+    }
     current_event_.name = event_attrs_[attr_index].name.c_str();
     update_flag_ |= UPDATE_FLAG_OF_EVENT;
   }
diff --git a/simpleperf/scripts/test.py b/simpleperf/scripts/test.py
index ab9a6b3..9924e99 100644
--- a/simpleperf/scripts/test.py
+++ b/simpleperf/scripts/test.py
@@ -868,6 +868,7 @@
                 if callchain.entries[i].symbol.symbol_name == sleep_function_name:
                     sleep_function_period += sample.period
                     break
+            self.assertEqual(self.report_lib.GetEventOfCurrentSample().name, 'cpu-cycles')
         sleep_percentage = float(sleep_function_period) / total_period
         self.assertGreater(sleep_percentage, 0.30)