1 /* 2 * Copyright (C) 2020 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_JSON_JSON_TRACKER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_JSON_JSON_TRACKER_H_ 19 20 #include "src/trace_processor/importers/json/json_utils.h" 21 #include "src/trace_processor/types/destructible.h" 22 #include "src/trace_processor/types/trace_processor_context.h" 23 24 namespace Json { 25 class Value; 26 } 27 28 namespace perfetto { 29 namespace trace_processor { 30 31 class JsonTracker : public Destructible { 32 public: 33 JsonTracker(const JsonTracker&) = delete; 34 JsonTracker& operator=(const JsonTracker&) = delete; 35 explicit JsonTracker(TraceProcessorContext*); 36 ~JsonTracker() override; 37 GetOrCreate(TraceProcessorContext * context)38 static JsonTracker* GetOrCreate(TraceProcessorContext* context) { 39 if (!context->json_tracker) { 40 context->json_tracker.reset(new JsonTracker(context)); 41 } 42 return static_cast<JsonTracker*>(context->json_tracker.get()); 43 } 44 SetTimeUnit(json::TimeUnit time_unit)45 void SetTimeUnit(json::TimeUnit time_unit) { time_unit_ = time_unit; } 46 CoerceToTs(const Json::Value & value)47 base::Optional<int64_t> CoerceToTs(const Json::Value& value) { 48 return json::CoerceToTs(time_unit_, value); 49 } 50 51 private: 52 json::TimeUnit time_unit_ = json::TimeUnit::kUs; 53 }; 54 55 } // namespace trace_processor 56 } // namespace perfetto 57 58 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_JSON_JSON_TRACKER_H_ 59