1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 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 16 #ifndef TRACE_DATA_CACHE_H 17 #define TRACE_DATA_CACHE_H 18 19 #include <memory> 20 #include "trace_data_cache_reader.h" 21 #include "trace_data_cache_writer.h" 22 #include "trace_data_db.h" 23 24 namespace SysTuning { 25 namespace TraceStreamer { 26 using namespace TraceStdtype; 27 class TraceDataCache : public TraceDataCacheReader, public TraceDataCacheWriter, public TraceDataDB { 28 public: 29 TraceDataCache(); 30 TraceDataCache(const TraceDataCache* dataCache) = delete; 31 TraceDataCache* operator=(const TraceDataCache* dataCache) = delete; 32 ~TraceDataCache() override; 33 34 bool AnimationTraceEnabled() const; 35 void UpdateAnimationTraceStatus(bool status); 36 bool TaskPoolTraceEnabled() const; 37 void UpdateTaskPoolTraceStatus(bool status); 38 bool AppStartTraceEnabled() const; 39 void UpdateAppStartTraceStatus(bool status); 40 bool BinderRunnableTraceEnabled() const; 41 void UpdateBinderRunnableTraceStatus(bool status); 42 uint64_t SplitFileMaxTime(); 43 uint64_t SplitFileMinTime(); 44 void SetSplitFileMaxTime(uint64_t maxTs); 45 void SetSplitFileMinTime(uint64_t minTs); 46 std::deque<std::unique_ptr<std::string>>& HookCommProtos(); 47 void ClearHookCommProtos(); 48 int32_t ExportPerfReadableText(const std::string& outputName, TraceDataDB::ResultCallBack resultCallBack = nullptr); 49 int32_t ExportHookReadableText(const std::string& outputName, TraceDataDB::ResultCallBack resultCallBack = nullptr); 50 int32_t ExportEbpfReadableText(const std::string& outputName, TraceDataDB::ResultCallBack resultCallBack = nullptr); 51 void ClearAllPrevCacheData(); 52 void UpdateAllPrevSize(); 53 54 private: 55 void InitDB(); 56 void ExportPerfCallChaninText(uint32_t callChainId, std::string& bufferLine); 57 void ExportHookCallChaninText(uint32_t callChainId, std::string& bufferLine); 58 bool ExportHookDataReadableText(int32_t fd, std::string& bufferLine); 59 bool ExportHookStatisticReadableText(int32_t fd, std::string& bufferLine); 60 using EbpfEventTypeMap = std::map<uint32_t /* type */, std::string_view /* name */>; 61 bool ExportEbpfFileSystemReadableText(int32_t fd, 62 std::string& bufferLine, 63 const EbpfEventTypeMap& ebpfEventTypeMap); 64 bool ExportEbpfPagedMemReadableText(int32_t fd, std::string& bufferLine, const EbpfEventTypeMap& ebpfEventTypeMap); 65 bool ExportEbpfBIOReadableText(int32_t fd, std::string& bufferLine, const EbpfEventTypeMap& ebpfEventTypeMap); 66 void ExportEbpfCallChaninText(uint32_t callChainId, std::string& bufferLine); 67 void InitBaseDB(); 68 void InitEbpfDB(); 69 void InitNativeMemoryDB(); 70 void InitArkTsDB(); 71 void InitHiperfDB(); 72 void InitMeasureDB(); 73 void InitTemplateDB(); 74 void InitRenderServiceDB(); 75 void InitMemoryDB(); 76 void InitHisysEventDB(); 77 void ExportPerfSampleToFile(std::string& perfBufferLine, 78 int32_t perfFd, 79 const std::string& outputName, 80 uint64_t row); 81 82 private: 83 bool dbInited_ = false; 84 bool animationTraceEnabled_ = false; 85 bool taskPoolTraceEnabled_ = false; 86 bool appStartTraceEnabled_ = false; 87 bool binderRunnableTraceEnabled_ = false; 88 uint64_t splitFileMinTs_ = INVALID_UINT64; 89 uint64_t splitFileMaxTs_ = INVALID_UINT64; 90 std::deque<std::unique_ptr<std::string>> hookCommProtos_; 91 }; 92 } // namespace TraceStreamer 93 } // namespace SysTuning 94 95 #endif // TRACE_DATA_CACHE_H 96