blob: 499342ad7bb5b71ded1e3edc9e319d39b728d4b3 [file] [log] [blame]
Deepanjan Roy01994ca2019-04-02 11:05:34 -07001/*
2 * Copyright (C) 2019 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_JSON_TRACE_TOKENIZER_H_
18#define SRC_TRACE_PROCESSOR_JSON_TRACE_TOKENIZER_H_
19
20#include <stdint.h>
21
22#include "src/trace_processor/chunked_trace_reader.h"
23#include "src/trace_processor/trace_sorter.h"
24#include "src/trace_processor/trace_storage.h"
25
26namespace Json {
27class Value;
28}
29
30namespace perfetto {
31namespace trace_processor {
32
33class TraceProcessorContext;
34
Hector Dearmanfcbc5e22019-04-08 13:12:28 +010035// Visible for testing.
36enum ReadDictRes { kFoundDict, kNeedsMoreData, kEndOfTrace, kFatalError };
37
38// Visible for testing.
39ReadDictRes ReadOneJsonDict(const char* start,
40 const char* end,
41 Json::Value* value,
42 const char** next);
43
Deepanjan Roy01994ca2019-04-02 11:05:34 -070044// Reads a JSON trace in chunks and extracts top level json objects.
45class JsonTraceTokenizer : public ChunkedTraceReader {
46 public:
47 explicit JsonTraceTokenizer(TraceProcessorContext*);
48 ~JsonTraceTokenizer() override;
49
50 // ChunkedTraceReader implementation.
Lalit Magantid71a9452019-05-09 15:13:24 +010051 util::Status Parse(std::unique_ptr<uint8_t[]>, size_t) override;
Deepanjan Roy01994ca2019-04-02 11:05:34 -070052
53 private:
54 TraceProcessorContext* const context_;
55
56 uint64_t offset_ = 0;
57 // Used to glue together JSON objects that span across two (or more)
58 // Parse boundaries.
59 std::vector<char> buffer_;
60};
61
62} // namespace trace_processor
63} // namespace perfetto
64
65#endif // SRC_TRACE_PROCESSOR_JSON_TRACE_TOKENIZER_H_