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 #pragma once 18 19 #include <SkString.h> 20 #include <SkTraceMemoryDump.h> 21 22 #include <string> 23 #include <unordered_map> 24 #include <utility> 25 26 namespace android { 27 namespace uirenderer { 28 namespace skiapipeline { 29 30 class ATraceMemoryDump : public SkTraceMemoryDump { 31 public: 32 ATraceMemoryDump(); ~ATraceMemoryDump()33 ~ATraceMemoryDump() override {} 34 35 void dumpNumericValue(const char* dumpName, const char* valueName, const char* units, 36 uint64_t value) override; 37 38 void dumpStringValue(const char* dumpName, const char* valueName, const char* value) override; 39 getRequestedDetails()40 LevelOfDetail getRequestedDetails() const override { 41 return SkTraceMemoryDump::kLight_LevelOfDetail; 42 } 43 shouldDumpWrappedObjects()44 bool shouldDumpWrappedObjects() const override { return false; } 45 46 void setMemoryBacking(const char* dumpName, const char* backingType, 47 const char* backingObjectId) override; 48 setDiscardableMemoryBacking(const char *,const SkDiscardableMemory &)49 void setDiscardableMemoryBacking(const char*, const SkDiscardableMemory&) override {} 50 51 void startFrame(); 52 53 void logTraces(); 54 55 private: 56 std::string mLastDumpName; 57 58 uint64_t mLastDumpValue; 59 60 uint64_t mLastPurgeableDumpValue; 61 62 std::string mCategory; 63 64 struct TraceValue { 65 uint64_t memory; 66 uint64_t purgeableMemory; 67 }; 68 69 // keys are define in sResourceMap 70 std::unordered_map<std::string, TraceValue> mCurrentValues; 71 72 void recordAndResetCountersIfNeeded(const char* dumpName); 73 74 void resetCurrentCounter(const char* dumpName); 75 }; 76 77 } /* namespace skiapipeline */ 78 } /* namespace uirenderer */ 79 } /* namespace android */