• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_SYSTRACE_SYSTRACE_TRACE_PARSER_H_
18 #define SRC_TRACE_PROCESSOR_IMPORTERS_SYSTRACE_SYSTRACE_TRACE_PARSER_H_
19 
20 #include <deque>
21 #include <regex>
22 
23 #include "src/trace_processor/importers/common/chunked_trace_reader.h"
24 #include "src/trace_processor/importers/systrace/systrace_line_parser.h"
25 #include "src/trace_processor/importers/systrace/systrace_line_tokenizer.h"
26 #include "src/trace_processor/storage/trace_storage.h"
27 #include "src/trace_processor/types/trace_processor_context.h"
28 
29 namespace perfetto {
30 namespace trace_processor {
31 
32 class SystraceTraceParser : public ChunkedTraceReader {
33  public:
34   explicit SystraceTraceParser(TraceProcessorContext*);
35   ~SystraceTraceParser() override;
36 
37   // ChunkedTraceReader implementation.
38   util::Status Parse(std::unique_ptr<uint8_t[]>, size_t size) override;
39   void NotifyEndOfFile() override;
40 
41  private:
42   enum ParseState {
43     kBeforeParse,
44     kHtmlBeforeSystrace,
45     kTraceDataSection,
46     kSystrace,
47     kProcessDumpLong,
48     kProcessDumpShort,
49     kCgroupDump,
50     kEndOfSystrace,
51   };
52 
53   ParseState state_ = ParseState::kBeforeParse;
54 
55   // Used to glue together trace packets that span across two (or more)
56   // Parse() boundaries.
57   std::deque<uint8_t> partial_buf_;
58 
59   SystraceLineTokenizer line_tokenizer_;
60   SystraceLineParser line_parser_;
61   TraceProcessorContext* ctx_;
62 };
63 
64 }  // namespace trace_processor
65 }  // namespace perfetto
66 
67 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_SYSTRACE_SYSTRACE_TRACE_PARSER_H_
68