1 /* 2 * Copyright (C) 2024 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_PROTO_WINSCOPE_PROTOLOG_MESSAGE_DECODER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_WINSCOPE_PROTOLOG_MESSAGE_DECODER_H_ 19 20 #include <cstdint> 21 #include <optional> 22 #include <string> 23 #include <vector> 24 25 #include "perfetto/ext/base/flat_hash_map.h" 26 #include "src/trace_processor/storage/trace_storage.h" 27 #include "src/trace_processor/tables/winscope_tables_py.h" 28 #include "src/trace_processor/types/destructible.h" 29 #include "src/trace_processor/types/trace_processor_context.h" 30 31 namespace perfetto::trace_processor { 32 33 enum ProtoLogLevel : int32_t { 34 DEBUG = 1, 35 VERBOSE = 2, 36 INFO = 3, 37 WARN = 4, 38 ERROR = 5, 39 WTF = 6, 40 }; 41 42 struct DecodedMessage { 43 ProtoLogLevel log_level; 44 std::string group_tag; 45 std::string message; 46 std::optional<std::string> location; 47 }; 48 49 struct TrackedGroup { 50 std::string tag; 51 }; 52 53 struct TrackedMessage { 54 ProtoLogLevel level; 55 uint32_t group_id; 56 std::string message; 57 std::optional<std::string> location; 58 }; 59 60 class ProtoLogMessageDecoder : public Destructible { 61 public: 62 explicit ProtoLogMessageDecoder(TraceProcessorContext* context); 63 virtual ~ProtoLogMessageDecoder() override; 64 GetOrCreate(TraceProcessorContext * context)65 static ProtoLogMessageDecoder* GetOrCreate(TraceProcessorContext* context) { 66 if (!context->protolog_message_decoder) { 67 context->protolog_message_decoder.reset(new ProtoLogMessageDecoder(context)); 68 } 69 return static_cast<ProtoLogMessageDecoder*>( 70 context->protolog_message_decoder.get()); 71 } 72 73 std::optional<DecodedMessage> Decode( 74 uint64_t message_id, 75 const std::vector<int64_t>& sint64_params, 76 const std::vector<double>& double_params, 77 const std::vector<bool>& boolean_params, 78 const std::vector<std::string>& string_params); 79 80 void TrackGroup(uint32_t id, const std::string& tag); 81 82 void TrackMessage(uint64_t message_id, 83 ProtoLogLevel level, 84 uint32_t group_id, 85 const std::string& message, 86 const std::optional<std::string>& location); 87 88 private: 89 TraceProcessorContext* const context_; 90 base::FlatHashMap<uint64_t, TrackedGroup> tracked_groups_; 91 base::FlatHashMap<uint64_t, TrackedMessage> tracked_messages_; 92 }; 93 94 } // namespace perfetto::trace_processor 95 96 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_WINSCOPE_PROTOLOG_MESSAGE_DECODER_H_ 97