OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_TRACE_ARC_TRACE_READER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_ARC_TRACE_ARC_TRACE_READER_H_ |
| 7 |
| 8 #include <inttypes.h> |
| 9 |
| 10 #include <memory> |
| 11 #include <queue> |
| 12 #include <string> |
| 13 |
| 14 #include "base/files/scoped_file.h" |
| 15 #include "base/macros.h" |
| 16 #include "base/threading/simple_thread.h" |
| 17 #include "chromeos/trace/arc_trace_agent.h" |
| 18 |
| 19 namespace arc { |
| 20 |
| 21 // The class is for reading ARC trace data from the given socket FD, transform |
| 22 // data into the JSON format, and store it in a circular buffer. |
| 23 class ArcTraceReader : public base::DelegateSimpleThread::Delegate { |
| 24 public: |
| 25 using StopTracingCallback = |
| 26 chromeos::ArcTraceAgent::Delegate::StopTracingCallback; |
| 27 |
| 28 ArcTraceReader(); |
| 29 |
| 30 // Sets the input socket FD for reading ARC trace data. |
| 31 void SetInputFD(base::ScopedFD fd); |
| 32 |
| 33 void StartRecord(); |
| 34 |
| 35 void StopRecord(const StopTracingCallback& callback); |
| 36 |
| 37 // DelegateSimpleThread::Delegate overrides: |
| 38 void Run() override; |
| 39 |
| 40 private: |
| 41 void WriteTraceEvent(char ph, |
| 42 int pid, |
| 43 int tid, |
| 44 uint64_t ts, |
| 45 uint64_t tts, |
| 46 const std::string* name = nullptr, |
| 47 const int* count = nullptr, |
| 48 const int* id = nullptr); |
| 49 |
| 50 void ParseAndSaveData(std::string data); |
| 51 |
| 52 bool is_recording_; |
| 53 std::queue<std::string> trace_buffer_; |
| 54 int current_data_size_; |
| 55 base::ScopedFD input_fd_; |
| 56 // Thread used for reading data from the input socket. |
| 57 std::unique_ptr<base::SimpleThread> recording_thread_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(ArcTraceReader); |
| 60 }; |
| 61 |
| 62 } // namespace arc |
| 63 |
| 64 #endif // CHROME_BROWSER_CHROMEOS_ARC_TRACE_ARC_TRACE_READER_H_ |
OLD | NEW |