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 FOUNDATION_ACE_FRAMEWORKS_BRIDGE_JS_FRONTEND_ENGINE_COMMON_JS_API_PERF_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_JS_FRONTEND_ENGINE_COMMON_JS_API_PERF_H 18 19 #include <map> 20 #include <stack> 21 #include <string> 22 #include <vector> 23 24 #include "base/utils/macros.h" 25 #include "base/utils/noncopyable.h" 26 27 namespace OHOS::Ace::Framework { 28 29 struct TimeStamp { 30 std::string name; 31 int64_t startTime = 0; 32 }; 33 34 class ACE_EXPORT JsApiPerf : public NonCopyable { 35 public: 36 static JsApiPerf& GetInstance(); 37 38 void InsertJsBeginLog(const std::string& functionName, int64_t timeStamp = 0); 39 void InsertJsEndLog(const std::string& functionName, int64_t timeStamp = 0); 40 41 std::string PrintToLogs() const; 42 43 private: 44 void InsertPerfLog(const std::string& functionName, int64_t timeConsumed); 45 46 std::map<std::string, std::vector<int64_t>> data_; 47 std::stack<TimeStamp> startTimeData_; 48 static JsApiPerf instance_; 49 }; 50 51 } // namespace OHOS::Ace::Framework 52 53 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_JS_FRONTEND_ENGINE_COMMON_JS_API_PERF_H 54