1 /* 2 * Copyright (c) 2024 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 PERFORMANCE_H 17 #define PERFORMANCE_H 18 19 #ifdef DRAWING_PERFORMANCE_TEST 20 #define DRAWING_PERFORMANCE_TEST_JS_RETURN(data) \ 21 if (Drawing::PerformanceCaculate::GetDrawingTestJsEnabled()) { \ 22 return (data); \ 23 } 24 #define DRAWING_PERFORMANCE_TEST_NAP_RETURN(data) \ 25 if (Drawing::PerformanceCaculate::GetDrawingTestNapiEnabled()) { \ 26 return (data); \ 27 } 28 #define DRAWING_PERFORMANCE_TEST_SKIA_RETURN(data) \ 29 if (Drawing::PerformanceCaculate::GetDrawingTestSkiaEnabled()) { \ 30 return (data); \ 31 } 32 #define DRAWING_PERFORMANCE_TEST_SKIA_NO_PARAM_RETURN \ 33 if (Drawing::PerformanceCaculate::GetDrawingTestSkiaEnabled()) { \ 34 return; \ 35 } 36 #define DRAWING_PERFORMANCE_START_CACULATE Drawing::PerformanceCaculate::SetCaculateSwitch(true) 37 #define DRAWING_PERFORMANCE_STOP_CACULATE Drawing::PerformanceCaculate::SetCaculateSwitch(false) 38 #else 39 #define DRAWING_PERFORMANCE_TEST_JS_RETURN(data) 40 #define DRAWING_PERFORMANCE_TEST_NAP_RETURN(data) 41 #define DRAWING_PERFORMANCE_TEST_SKIA_RETURN(data) 42 #define DRAWING_PERFORMANCE_TEST_SKIA_NO_PARAM_RETURN 43 #define DRAWING_PERFORMANCE_START_CACULATE 44 #define DRAWING_PERFORMANCE_STOP_CACULATE 45 #endif 46 47 namespace OHOS { 48 namespace Rosen { 49 namespace Drawing { 50 class PerformanceCaculate { 51 public: 52 enum TestFlag { 53 TSET_ALL, 54 TEST_JS, 55 TEST_NAPI, 56 TEST_SKIA, 57 TEST_RECORDING, 58 }; 59 60 static bool GetDrawingTestJsEnabled(); 61 static bool GetDrawingTestNapiEnabled(); 62 static bool GetDrawingTestSkiaEnabled(); 63 static bool GetDrawingTestRecordingEnabled(); 64 65 static long long GetUpTime(bool addCount = true); 66 67 static void SetCaculateSwitch(bool start = true); 68 69 static bool GetDrawingFlushPrint(); 70 static void ResetCaculateTimeCount(); 71 72 private: 73 74 static bool performanceCaculateSwitch_; 75 static TestFlag drawingTestFlag_; 76 static int caculateTimeCount_; 77 }; 78 } // namespace Drawing 79 } // namespace Rosen 80 } // namespace OHOS 81 #endif