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 #ifdef ROSEN_OHOS 16 #include <parameter.h> 17 #include <parameters.h> 18 #include <sys/time.h> 19 #include <sys/timerfd.h> 20 #endif 21 #include "utils/performanceCaculate.h" 22 23 namespace OHOS { 24 namespace Rosen { 25 namespace Drawing { 26 27 #ifdef ROSEN_OHOS 28 const int SECOND_TO_NANO = 1000000000; 29 #endif 30 const int DRAWING_FLUSH_NUM = 4; 31 32 bool PerformanceCaculate::performanceCaculateSwitch_ = false; 33 34 #ifdef ROSEN_OHOS 35 PerformanceCaculate::TestFlag PerformanceCaculate::drawingTestFlag_ = static_cast<PerformanceCaculate::TestFlag> ( 36 std::atoi(OHOS::system::GetParameter("persist.sys.graphic.drawing.test", "0").c_str())); 37 #else 38 PerformanceCaculate::TestFlag PerformanceCaculate::drawingTestFlag_ = PerformanceCaculate::TestFlag::TSET_ALL; 39 #endif 40 41 int PerformanceCaculate::caculateTimeCount_ = 0; 42 GetDrawingTestJsEnabled()43bool PerformanceCaculate::GetDrawingTestJsEnabled() 44 { 45 return performanceCaculateSwitch_ && drawingTestFlag_ == PerformanceCaculate::TestFlag::TEST_JS; 46 } 47 GetDrawingTestNapiEnabled()48bool PerformanceCaculate::GetDrawingTestNapiEnabled() 49 { 50 return performanceCaculateSwitch_ && drawingTestFlag_ == PerformanceCaculate::TestFlag::TEST_NAPI; 51 } 52 GetDrawingTestSkiaEnabled()53bool PerformanceCaculate::GetDrawingTestSkiaEnabled() 54 { 55 return performanceCaculateSwitch_ && drawingTestFlag_ == PerformanceCaculate::TestFlag::TEST_SKIA; 56 } 57 GetDrawingTestRecordingEnabled()58bool PerformanceCaculate::GetDrawingTestRecordingEnabled() 59 { 60 return (drawingTestFlag_ == PerformanceCaculate::TestFlag::TEST_RECORDING || 61 drawingTestFlag_ == PerformanceCaculate::TestFlag::TEST_SKIA); 62 } 63 GetUpTime(bool addCount)64long long PerformanceCaculate::GetUpTime(bool addCount) 65 { 66 long long time = 0; 67 #ifdef ROSEN_OHOS 68 struct timespec tv {}; 69 if (clock_gettime(CLOCK_BOOTTIME, &tv) >= 0) { 70 time = tv.tv_sec * SECOND_TO_NANO + tv.tv_nsec; 71 } 72 if (addCount) { 73 caculateTimeCount_++; 74 } 75 #endif 76 return time; 77 } 78 GetDrawingFlushPrint()79bool PerformanceCaculate::GetDrawingFlushPrint() 80 { 81 return caculateTimeCount_ == DRAWING_FLUSH_NUM; 82 } 83 ResetCaculateTimeCount()84void PerformanceCaculate::ResetCaculateTimeCount() 85 { 86 caculateTimeCount_ = 0; 87 } 88 SetCaculateSwitch(bool start)89void PerformanceCaculate::SetCaculateSwitch(bool start) 90 { 91 performanceCaculateSwitch_ = start; 92 #ifdef ROSEN_OHOS 93 if (performanceCaculateSwitch_) { 94 drawingTestFlag_ = static_cast<PerformanceCaculate::TestFlag> ( 95 std::atoi(OHOS::system::GetParameter("persist.sys.graphic.drawing.test", "0").c_str())); 96 } 97 #endif 98 } 99 100 } // namespace Drawing 101 } // namespace Rosen 102 } // namespace OHOS