OSDN Git Service

ANRdaemon: move trace result from /sdcard to /data am: d93aa41807
[android-x86/system-extras.git] / simpleperf / record.h
index 58c72b0..a94a917 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <sys/types.h>
 
+#include <memory>
 #include <queue>
 #include <string>
 #include <vector>
@@ -124,6 +125,7 @@ struct SampleId {
   // Write the binary format of sample_id to the buffer pointed by p.
   void WriteToBinaryFormat(char*& p) const;
   void Dump(size_t indent) const;
+  size_t Size() const;
 };
 
 // Usually one record contains the following three parts in order in binary format:
@@ -172,6 +174,7 @@ struct MmapRecord : public Record {
 
   MmapRecord(const perf_event_attr& attr, const perf_event_header* pheader);
   std::vector<char> BinaryFormat() const override;
+  void AdjustSizeBasedOnData();
 
  protected:
   void DumpData(size_t indent) const override;
@@ -196,6 +199,7 @@ struct Mmap2Record : public Record {
 
   Mmap2Record(const perf_event_attr& attr, const perf_event_header* pheader);
   std::vector<char> BinaryFormat() const override;
+  void AdjustSizeBasedOnData();
 
  protected:
   void DumpData(size_t indent) const override;
@@ -327,16 +331,27 @@ class RecordCache {
   std::vector<std::unique_ptr<Record>> PopAll();
 
  private:
+  struct RecordWithSeq {
+    uint32_t seq;
+    Record *record;
+
+    bool IsHappensBefore(const RecordWithSeq& other) const;
+  };
+
   struct RecordComparator {
-    bool operator()(const Record* r1, const Record* r2);
+    bool operator()(const RecordWithSeq& r1, const RecordWithSeq& r2);
   };
 
+  RecordWithSeq CreateRecordWithSeq(Record *r);
+
   const perf_event_attr attr_;
   bool has_timestamp_;
   size_t min_cache_size_;
   uint64_t min_time_diff_in_ns_;
   uint64_t last_time_;
-  std::priority_queue<Record*, std::vector<Record*>, RecordComparator> queue_;
+  uint32_t cur_seq_;
+  std::priority_queue<RecordWithSeq, std::vector<RecordWithSeq>,
+      RecordComparator> queue_;
 };
 
 std::vector<std::unique_ptr<Record>> ReadRecordsFromBuffer(const perf_event_attr& attr,