1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef HTRACE_JS_CPU_PERFILER_PARSER_H 16 #define HTRACE_JS_CPU_PERFILER_PARSER_H 17 #include <cstdint> 18 #include <string> 19 #include <vector> 20 #include "common_types.h" 21 #include "event_parser_base.h" 22 #include "htrace_plugin_time_parser.h" 23 #include "json.hpp" 24 #include "trace_streamer_config.h" 25 #include "trace_streamer_filters.h" 26 using json = nlohmann::json; 27 28 namespace SysTuning { 29 namespace TraceStreamer { 30 class HtraceJsCpuProfilerParser : public EventParserBase, public HtracePluginTimeParser { 31 public: 32 HtraceJsCpuProfilerParser(TraceDataCache *dataCache, const TraceStreamerFilters *ctx); ~HtraceJsCpuProfilerParser()33 ~HtraceJsCpuProfilerParser(){}; 34 void ParseJsCpuProfiler(std::string result, uint64_t startTimeSnap, uint64_t endTimeSnap); GetUpdateJson()35 auto GetUpdateJson() 36 { 37 return updatedJson_; 38 } 39 40 private: 41 void ParseNodeData(const json &jMessage); 42 void DataProcessing(const json &jMessage, 43 uint64_t &sampleEndTime, 44 uint64_t &startTime, 45 uint64_t &dur, 46 uint32_t &sample); 47 uint32_t ParseSampleData(const json &jMessage, 48 uint64_t &sampleEndTime, 49 uint64_t &startTime, 50 uint64_t startTimeSnap, 51 uint64_t endTimeSnap); 52 53 private: 54 json updatedJson_; 55 uint64_t startTime_ = INVALID_UINT64; 56 }; 57 } // namespace TraceStreamer 58 } // namespace SysTuning 59 60 #endif // HTRACE_JS_CPU_PERFILER_PARSER_H 61