From 5972432dc15bd2215a60cc767c3a815e1982f384 Mon Sep 17 00:00:00 2001 From: chenqiang Date: Fri, 9 Sep 2022 15:30:36 +0800 Subject: [PATCH] =?UTF-8?q?Signed-off-by:=20chenqiang2022=20=20Display=20node=20geomerty=20info=20by=20tra?= =?UTF-8?q?ce,=E5=88=A0=E9=99=A4AnimationLog=E5=86=97=E4=BD=99=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/pipeline/rs_main_thread.cpp | 4 + rosen/modules/render_service_base/BUILD.gn | 2 +- .../animation/rs_render_property_animation.h | 12 - .../include/pipeline/rs_render_node.h | 2 +- .../platform/common/rs_system_properties.h | 1 + .../rs_property_trace.h} | 47 +- .../src/animation/rs_animation_log.cpp | 469 ------------------ .../rs_render_property_animation.cpp | 40 -- .../src/pipeline/rs_canvas_render_node.cpp | 1 + .../src/pipeline/rs_display_render_node.cpp | 1 + .../src/pipeline/rs_proxy_render_node.cpp | 1 + .../src/pipeline/rs_render_node.cpp | 9 + .../src/pipeline/rs_root_render_node.cpp | 1 + .../src/pipeline/rs_surface_render_node.cpp | 1 + .../platform/ohos/rs_system_properties.cpp | 6 + .../src/property/rs_property_trace.cpp | 151 ++++++ .../core/pipeline/rs_render_thread.cpp | 4 + 17 files changed, 204 insertions(+), 548 deletions(-) rename rosen/modules/render_service_base/include/{animation/rs_animation_log.h => property/rs_property_trace.h} (54%) delete mode 100644 rosen/modules/render_service_base/src/animation/rs_animation_log.cpp create mode 100644 rosen/modules/render_service_base/src/property/rs_property_trace.cpp diff --git a/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp b/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp index a84dd0f2ae..620f7d66c3 100644 --- a/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp +++ b/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp @@ -31,6 +31,7 @@ #include "platform/common/rs_log.h" #include "platform/common/rs_innovation.h" #include "platform/drawing/rs_vsync_client.h" +#include "property/rs_property_trace.h" #include "screen_manager/rs_screen_manager.h" #include "transaction/rs_transaction_proxy.h" #include "accessibility_config.h" @@ -505,6 +506,9 @@ void RSMainThread::Render() return; } + if (RSSystemProperties::GetRenderNodeTraceEnabled()) { + RSPropertyTrace::GetInstance().RefreshNodeTraceInfo(); + } RS_LOGD("RSMainThread::Render isUni:%d", IfUseUniVisitor()); std::shared_ptr visitor; if (IfUseUniVisitor()) { diff --git a/rosen/modules/render_service_base/BUILD.gn b/rosen/modules/render_service_base/BUILD.gn index a3f41510e4..521e6b36b5 100644 --- a/rosen/modules/render_service_base/BUILD.gn +++ b/rosen/modules/render_service_base/BUILD.gn @@ -39,7 +39,6 @@ ohos_shared_library("librender_service_base") { sources = [ #animation "src/animation/rs_animation_fraction.cpp", - "src/animation/rs_animation_log.cpp", "src/animation/rs_animation_manager.cpp", "src/animation/rs_interpolator.cpp", "src/animation/rs_render_animation.cpp", @@ -118,6 +117,7 @@ ohos_shared_library("librender_service_base") { #property "src/property/rs_properties.cpp", "src/property/rs_properties_painter.cpp", + "src/property/rs_property_trace.cpp", #render "src/render/rs_blur_filter.cpp", diff --git a/rosen/modules/render_service_base/include/animation/rs_render_property_animation.h b/rosen/modules/render_service_base/include/animation/rs_render_property_animation.h index 8cbd9f9d47..de4973527c 100644 --- a/rosen/modules/render_service_base/include/animation/rs_render_property_animation.h +++ b/rosen/modules/render_service_base/include/animation/rs_render_property_animation.h @@ -16,7 +16,6 @@ #ifndef RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_PROPERTY_ANIMATION_H #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_PROPERTY_ANIMATION_H -#include "animation/rs_animation_log.h" #include "animation/rs_render_animation.h" #include "common/rs_common_def.h" @@ -60,13 +59,6 @@ protected: void OnRemoveOnCompletion() override; - void WriteAnimationValueToLog(const std::shared_ptr& value); - - void WriteAnimationInfoToLog(const std::shared_ptr& startValue, - const std::shared_ptr& endValue); - - void UpdateNeedWriteLog(const NodeId id); - virtual void InitValueEstimator() {} protected: @@ -78,10 +70,6 @@ protected: private: bool isAdditive_ { true }; - bool hasUpdateNeedWriteLog_ { false }; - bool needWriteToLog_ { false }; - bool hasWriteInfo_ { false }; - inline static std::shared_ptr animationLog_ = std::make_shared(); }; } // namespace Rosen } // namespace OHOS diff --git a/rosen/modules/render_service_base/include/pipeline/rs_render_node.h b/rosen/modules/render_service_base/include/pipeline/rs_render_node.h index e18580d498..ae80e946b0 100644 --- a/rosen/modules/render_service_base/include/pipeline/rs_render_node.h +++ b/rosen/modules/render_service_base/include/pipeline/rs_render_node.h @@ -62,7 +62,7 @@ public: virtual void ProcessRenderBeforeChildren(RSPaintFilterCanvas& canvas); virtual void ProcessRenderContents(RSPaintFilterCanvas& canvas) {} virtual void ProcessRenderAfterChildren(RSPaintFilterCanvas& canvas); - + void RenderTraceDebug() const; bool HasDisappearingTransition(bool recursive) const override { return (disappearingTransitionCount_ > 0) || RSBaseRenderNode::HasDisappearingTransition(recursive); diff --git a/rosen/modules/render_service_base/include/platform/common/rs_system_properties.h b/rosen/modules/render_service_base/include/platform/common/rs_system_properties.h index cb8efa5a28..33b5a96085 100644 --- a/rosen/modules/render_service_base/include/platform/common/rs_system_properties.h +++ b/rosen/modules/render_service_base/include/platform/common/rs_system_properties.h @@ -50,6 +50,7 @@ public: // used by clients static bool GetUniRenderEnabled(); + static bool GetRenderNodeTraceEnabled(); static DirtyRegionDebugType GetDirtyRegionDebugType(); static PartialRenderType GetPartialRenderEnabled(); static PartialRenderType GetUniPartialRenderEnabled(); diff --git a/rosen/modules/render_service_base/include/animation/rs_animation_log.h b/rosen/modules/render_service_base/include/property/rs_property_trace.h similarity index 54% rename from rosen/modules/render_service_base/include/animation/rs_animation_log.h rename to rosen/modules/render_service_base/include/property/rs_property_trace.h index 4801a8cec2..b5208f12ba 100644 --- a/rosen/modules/render_service_base/include/animation/rs_animation_log.h +++ b/rosen/modules/render_service_base/include/property/rs_property_trace.h @@ -13,55 +13,52 @@ * limitations under the License. */ -#ifndef RENDER_SERVICE_BASE_ANIMATION_RS_ANIMATION_LOG_H -#define RENDER_SERVICE_BASE_ANIMATION_RS_ANIMATION_LOG_H +#ifndef RENDER_SERVICE_BASE_COMMON_RS_PROPERTY_TRACE_H +#define RENDER_SERVICE_BASE_COMMON_RS_PROPERTY_TRACE_H -#include #include #include +#include #include "common/rs_common_def.h" +#include "common/rs_obj_abs_geometry.h" #include "modifier/rs_modifier_type.h" #include "platform/common/rs_log.h" namespace OHOS { namespace Rosen { -class RSAnimationLog { +class RSPropertyTrace { public: - RSAnimationLog(); - ~RSAnimationLog(); + static RSPropertyTrace &GetInstance() + { + return instance_; + }; + + void PropertiesDisplayByTrace(const NodeId& id, const std::shared_ptr& boundsGeometry); + void RefreshNodeTraceInfo(); +private: + RSPropertyTrace() = default; + ~RSPropertyTrace() = default; void InitNodeAndPropertyInfo(); void ClearNodeAndPropertyInfo(); - bool IsNeedWriteLog(const PropertyId& propertyId, const NodeId& id); - - template - void WriteAnimationValueToLog(const T& value, const PropertyId& propertyId, const NodeId& id); - - template - void WriteAnimationInfoToLog(const PropertyId& propertyId, const AnimationId& id, - const T& startValue, const T& endValue); - -private: - void PreProcessLogFile(const std::string& logFilePath); + bool IsNeedPropertyTrace(const NodeId& id); void DealConfigInputInfo(const std::string& info); - uint64_t GetNowTime(); + bool IsNeedRefreshConfig(); - void WriteString(const std::string& log); - - int WriteLog(const char* format, ...); + void AddTraceFlag(const std::string& str); bool needWriteAllNode_ {false}; - bool needWriteAllProperty_ {false}; - std::ofstream logFile_; + static RSPropertyTrace instance_; std::set nodeIdSet_; - std::set propertySet_; + std::string propertyFileLastModifyTime; }; + } // namespace Rosen } // namespace OHOS -#endif // RENDER_SERVICE_BASE_ANIMATION_RS_ANIMATION_LOG_H \ No newline at end of file +#endif // RENDER_SERVICE_BASE_COMMON_RS_PROPERTY_TRACE_H \ No newline at end of file diff --git a/rosen/modules/render_service_base/src/animation/rs_animation_log.cpp b/rosen/modules/render_service_base/src/animation/rs_animation_log.cpp deleted file mode 100644 index a4915aa7cf..0000000000 --- a/rosen/modules/render_service_base/src/animation/rs_animation_log.cpp +++ /dev/null @@ -1,469 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "animation/rs_animation_log.h" - -#include -#include -#include -#include - -#include "render/rs_blur_filter.h" -#include "common/rs_color.h" -#include "common/rs_matrix3.h" -#include "common/rs_vector4.h" -#include "render/rs_filter.h" -#include "modifier/rs_render_property.h" - -namespace OHOS { -namespace Rosen { -const std::string ANIMATION_LOG_PATH = "/etc/rosen/"; -const std::string ANIMATION_LOG_FILE_NAME = "Animation"; -const std::string ANIMATION_LOG_FILE_TYPE = ".log"; -const std::string CONFIG_FILE_NAME = "property.config"; -const std::string COLON_SEPARATOR = ":"; -const std::string COMMA_SEPARATOR = ","; -const std::string SEMICOLON_SEPARATOR = ";"; -const std::string PROPERTY_TAG = "PROPERTY"; -const std::string NODE_ID_TAG = "ID"; -const std::string ALL_NEED_TAG = "all"; -static constexpr int MIN_INFO_SIZE = 2; -static constexpr int DATA_INDEX_ZERO = 0; -static constexpr int DATA_INDEX_ONE = 1; -static constexpr int DATA_INDEX_TWO = 2; -static constexpr int DATA_INDEX_THREE = 3; -static constexpr int DATA_INDEX_FOUR = 4; -static constexpr int DATA_INDEX_FIVE = 5; -static constexpr int DATA_INDEX_SIX = 6; -static constexpr int DATA_INDEX_SEVEN = 7; -static constexpr int DATA_INDEX_EIGHT = 8; -static constexpr int DATA_ARRAY_SIZE = 9; -static constexpr int MAX_LOG_LENGTH = 2048; -static constexpr size_t LOG_FILE_MAX_SIZE = 10485760; - -std::vector SplitStringBySeparator(const std::string& str, - const std::string& separator) -{ - std::regex re(separator); - std::sregex_token_iterator pos(str.begin(), str.end(), re, -1); - std::sregex_token_iterator endPos; - std::vector result; - while (pos != endPos) { - result.emplace_back(*pos++); - } - return result; -} - -RSAnimationLog::RSAnimationLog() -{ - std::string logFilePath = ANIMATION_LOG_PATH + ANIMATION_LOG_FILE_NAME + ANIMATION_LOG_FILE_TYPE; - PreProcessLogFile(logFilePath); - logFile_ = std::ofstream(logFilePath, std::ios::app); - if (!logFile_.is_open()) { - ROSEN_LOGI("Open file error:[%s]", logFilePath.c_str()); - logFile_.close(); - return; - } - - InitNodeAndPropertyInfo(); -} - -RSAnimationLog::~RSAnimationLog() -{ - logFile_.close(); -} - -void RSAnimationLog::PreProcessLogFile(const std::string& logFilePath) -{ - std::ifstream logFile = std::ifstream(logFilePath.c_str(), std::ios::binary); - if (!logFile) { - ROSEN_LOGI("Open file err:[%s]", logFilePath.c_str()); - logFile.close(); - return; - } - - logFile.seekg(0, logFile.end); - long logFileSize = logFile.tellg(); - if (logFileSize > 0 && (static_cast(logFileSize) >= LOG_FILE_MAX_SIZE)) { - std::string timestampPath = ANIMATION_LOG_PATH + ANIMATION_LOG_FILE_NAME + std::to_string(GetNowTime()) - + ANIMATION_LOG_FILE_TYPE; - std::rename(logFilePath.c_str(), timestampPath.c_str()); - } - logFile.close(); -} - -void RSAnimationLog::InitNodeAndPropertyInfo() -{ - std::string configFilePath = ANIMATION_LOG_PATH + CONFIG_FILE_NAME; - char newpath[PATH_MAX + 1] = { 0x00 }; - if (strlen(configFilePath.c_str()) > PATH_MAX || realpath(configFilePath.c_str(), newpath) == nullptr) { - return; - } - std::ifstream configFile(newpath); - if (!configFile.is_open()) { - return; - } - - std::string info; - while (std::getline(configFile, info)) { - std::vector infos = SplitStringBySeparator(info, SEMICOLON_SEPARATOR); - if (infos.empty()) { - continue; - } - DealConfigInputInfo(infos.front()); - } - configFile.close(); -} - -void RSAnimationLog::DealConfigInputInfo(const std::string& info) -{ - std::vector splitResult = SplitStringBySeparator(info, COLON_SEPARATOR); - if (splitResult.size() != MIN_INFO_SIZE) { - return; - } - - std::string tag = splitResult.front(); - if (tag == PROPERTY_TAG) { - std::vector props = - SplitStringBySeparator(splitResult.back(), COMMA_SEPARATOR); - for (std::string prop: props) { - if (prop == ALL_NEED_TAG) { - needWriteAllProperty_ = true; - return; - } - PropertyId propertyId = - static_cast(strtoull(prop.c_str(), NULL, 10)); - propertySet_.insert(propertyId); - } - } - - if (tag == NODE_ID_TAG) { - std::vector nodeIds = - SplitStringBySeparator(splitResult.back(), COMMA_SEPARATOR); - for (std::string nodeId : nodeIds) { - if (nodeId == ALL_NEED_TAG) { - needWriteAllNode_ = true; - return; - } - auto id = atoll(nodeId.c_str()); - nodeIdSet_.insert(id); - } - } -} - -void RSAnimationLog::ClearNodeAndPropertyInfo() -{ - propertySet_.clear(); - nodeIdSet_.clear(); -} - -bool RSAnimationLog::IsNeedWriteLog(const PropertyId& propertyId, const NodeId& id) -{ - auto itrp = propertySet_.find(propertyId); - if (itrp == propertySet_.end() && !needWriteAllProperty_) { - return false; - } - - auto itrn = nodeIdSet_.find(id); - if (itrn == nodeIdSet_.end() && !needWriteAllNode_) { - return false; - } - - return true; -} - -uint64_t RSAnimationLog::GetNowTime() -{ - struct timeval start = {}; - gettimeofday(&start, nullptr); - constexpr uint32_t secToUsec = 1000 * 1000; - return static_cast(start.tv_sec) * secToUsec + static_cast(start.tv_usec); -} - -void RSAnimationLog::WriteString(const std::string& log) -{ - if (logFile_.is_open()) { - logFile_.write(log.c_str(), log.size()); - logFile_.flush(); - } -} - -int RSAnimationLog::WriteLog(const char* format, ...) -{ - char logStr[MAX_LOG_LENGTH] = {0}; - va_list args; - va_start(args, format); - int ret = vsprintf_s(logStr, MAX_LOG_LENGTH, format, args); - if (ret == -1) { - va_end(args); - return -1; - } - - WriteString(logStr); - va_end(args); - return 0; -} - -#define WRITE_LOG(format, ...) \ - do { \ - WriteLog(format, ##__VA_ARGS__); \ - } while (0) - -template<> -void RSAnimationLog::WriteAnimationValueToLog(const int& value, - const PropertyId& propertyId, const NodeId& id) -{ - WRITE_LOG("RSAnimationValueLog NodeId:{%" PRIu64 "} time:{%" PRIu64 "} property:{%" PRIu64 "} value:{%d}\n", - id, GetNowTime(), propertyId, value); -} - -template<> -void RSAnimationLog::WriteAnimationInfoToLog(const PropertyId& propertyId, - const AnimationId& id, const int& startValue, const int& endValue) -{ - WRITE_LOG("RSAnimationInfoLog AnimationId:{%" PRIu64 "} time:{%" PRIu64 "} property:{%" PRIu64 "} " - "startValue:{%d} endValue:{%d}\n", id, GetNowTime(), propertyId, startValue, endValue); -} - -template<> -void RSAnimationLog::WriteAnimationValueToLog(const float& value, - const PropertyId& propertyId, const NodeId& id) -{ - WRITE_LOG("RSAnimationValueLog NodeId:{%" PRIu64 "} time:{%" PRIu64 "} property:{%" PRIu64 "} value:{%f}\n", - id, GetNowTime(), propertyId, value); -} - -template<> -void RSAnimationLog::WriteAnimationInfoToLog(const PropertyId& propertyId, - const AnimationId& id, const float& startValue, const float& endValue) -{ - WRITE_LOG("RSAnimationInfoLog AnimationId:{%" PRIu64 "} time:{%" PRIu64 "} property:{%" PRIu64 "} " - "startValue:{%f} endValue:{%f}\n", id, GetNowTime(), propertyId, startValue, endValue); -} - -template<> -void RSAnimationLog::WriteAnimationValueToLog(const Color& value, - const PropertyId& propertyId, const NodeId& id) -{ - WRITE_LOG("RSAnimationValueLog NodeId:{%" PRIu64 "} time:{%" PRIu64 "} property:{%" PRIu64 "} " - "value:{%d %d %d %d}\n", id, GetNowTime(), propertyId, value.GetRed(), - value.GetGreen(), value.GetBlue(), value.GetAlpha()); -} - -template<> -void RSAnimationLog::WriteAnimationInfoToLog(const PropertyId& propertyId, - const AnimationId& id, const Color& startValue, const Color& endValue) -{ - WRITE_LOG("RSAnimationInfoLog AnimationId:{%" PRIu64 "} time:{%" PRIu64 "} property:{%" PRIu64 "} " - "startValue:{%d %d %d %d} endValue:{%d %d %d %d}\n", id, GetNowTime(), propertyId, - startValue.GetRed(), startValue.GetGreen(), startValue.GetBlue(), - startValue.GetAlpha(), endValue.GetRed(), endValue.GetGreen(), endValue.GetBlue(), - endValue.GetAlpha()); -} - -template<> -void RSAnimationLog::WriteAnimationValueToLog(const Matrix3f& value, - const PropertyId& propertyId, const NodeId& id) -{ - auto data = value.GetConstData(); - if ((DATA_INDEX_ZERO < DATA_ARRAY_SIZE) && (DATA_INDEX_ONE < DATA_ARRAY_SIZE) && - (DATA_INDEX_TWO < DATA_ARRAY_SIZE) && (DATA_INDEX_THREE < DATA_ARRAY_SIZE) && - (DATA_INDEX_FOUR < DATA_ARRAY_SIZE) && (DATA_INDEX_FIVE < DATA_ARRAY_SIZE) && - (DATA_INDEX_SIX < DATA_ARRAY_SIZE) && (DATA_INDEX_SEVEN < DATA_ARRAY_SIZE) && - (DATA_INDEX_EIGHT < DATA_ARRAY_SIZE)) { - WRITE_LOG("RSAnimationValueLog NodeId:{%" PRIu64 "} time:{%" PRIu64 "} property:{%" PRIu64 "} " - "value:{%d %d %d %d %d %d %d %d %d}\n", id, GetNowTime(), propertyId, - data[DATA_INDEX_ZERO], data[DATA_INDEX_ONE], data[DATA_INDEX_TWO], - data[DATA_INDEX_THREE], data[DATA_INDEX_FOUR], data[DATA_INDEX_FIVE], - data[DATA_INDEX_SIX], data[DATA_INDEX_SEVEN], data[DATA_INDEX_EIGHT]); - } -} - -template<> -void RSAnimationLog::WriteAnimationInfoToLog(const PropertyId& propertyId, - const AnimationId& id, const Matrix3f& startValue, const Matrix3f& endValue) -{ - auto startData = startValue.GetConstData(); - auto endData = endValue.GetConstData(); - if ((DATA_INDEX_ZERO < DATA_ARRAY_SIZE) && (DATA_INDEX_ONE < DATA_ARRAY_SIZE) && - (DATA_INDEX_TWO < DATA_ARRAY_SIZE) && (DATA_INDEX_THREE < DATA_ARRAY_SIZE) && - (DATA_INDEX_FOUR < DATA_ARRAY_SIZE) && (DATA_INDEX_FIVE < DATA_ARRAY_SIZE) && - (DATA_INDEX_SIX < DATA_ARRAY_SIZE) && (DATA_INDEX_SEVEN < DATA_ARRAY_SIZE) && - (DATA_INDEX_EIGHT < DATA_ARRAY_SIZE)) { - WRITE_LOG("RSAnimationInfoLog AnimationId:{%" PRIu64 "} time:{%" PRIu64 "} property:{%" PRIu64 "} " - "startValue:{%d %d %d %d %d %d %d %d %d} endValue:{%d %d %d %d %d %d %d %d %d}\n", - id, GetNowTime(), propertyId, startData[DATA_INDEX_ZERO], startData[DATA_INDEX_ONE], - startData[DATA_INDEX_TWO], startData[DATA_INDEX_THREE], startData[DATA_INDEX_FOUR], - startData[DATA_INDEX_FIVE], startData[DATA_INDEX_SIX], startData[DATA_INDEX_SEVEN], - startData[DATA_INDEX_EIGHT], endData[DATA_INDEX_ZERO], endData[DATA_INDEX_ONE], - endData[DATA_INDEX_TWO], endData[DATA_INDEX_THREE], endData[DATA_INDEX_FOUR], - endData[DATA_INDEX_FIVE], endData[DATA_INDEX_SIX], endData[DATA_INDEX_SEVEN], - endData[DATA_INDEX_EIGHT]); - } -} - -template<> -void RSAnimationLog::WriteAnimationValueToLog(const Vector2f& value, - const PropertyId& propertyId, const NodeId& id) -{ - WRITE_LOG("RSAnimationValueLog NodeId:{%" PRIu64 "} time:{%" PRIu64 "} property:{%" PRIu64 "} " - "value:{%f %f}\n", id, GetNowTime(), propertyId, value.x_, value.y_); -} - -template<> -void RSAnimationLog::WriteAnimationInfoToLog(const PropertyId& propertyId, - const AnimationId& id, const Vector2f& startValue, const Vector2f& endValue) -{ - WRITE_LOG("RSAnimationInfoLog AnimationId:{%" PRIu64 "} time:{%" PRIu64 "} property:{%" PRIu64 "} " - "startValue:{%f %f} endValue:{%f %f}\n", id, GetNowTime(), propertyId, - startValue.x_, startValue.y_, endValue.x_, endValue.y_); -} - -template<> -void RSAnimationLog::WriteAnimationValueToLog(const Vector4f& value, - const PropertyId& propertyId, const NodeId& id) -{ - auto data = value; - WRITE_LOG("RSAnimationValueLog NodeId:{%" PRIu64 "} time:{%" PRIu64 "} property:{%" PRIu64 "} " - "value:{%f %f %f %f}\n", id, GetNowTime(), propertyId, data[DATA_INDEX_ZERO], - data[DATA_INDEX_ONE], data[DATA_INDEX_TWO], data[DATA_INDEX_THREE]); -} - -template<> -void RSAnimationLog::WriteAnimationInfoToLog(const PropertyId& propertyId, - const AnimationId& id, const Vector4f& startValue, const Vector4f& endValue) -{ - auto startData = startValue; - auto endData = endValue; - WRITE_LOG("RSAnimationInfoLog AnimationId:{%" PRIu64 "} time:{%" PRIu64 "} property:{%" PRIu64 "} " - "startValue:{%f %f %f %f} endValue:{%f %f %f %f}\n", id, GetNowTime(), propertyId, - startData[DATA_INDEX_ZERO], startData[DATA_INDEX_ONE], startData[DATA_INDEX_TWO], - startData[DATA_INDEX_THREE], endData[DATA_INDEX_ZERO], endData[DATA_INDEX_ONE], - endData[DATA_INDEX_TWO], endData[DATA_INDEX_THREE]); -} - -template<> -void RSAnimationLog::WriteAnimationValueToLog(const Quaternion& value, - const PropertyId& propertyId, const NodeId& id) -{ - auto data = value; - WRITE_LOG("RSAnimationValueLog NodeId:{%" PRIu64 "} time:{%" PRIu64 "} property:{%" PRIu64 "} " - "value:{%f %f %f %f}\n", id, GetNowTime(), propertyId, data[DATA_INDEX_ZERO], - data[DATA_INDEX_ONE], data[DATA_INDEX_TWO], data[DATA_INDEX_THREE]); -} - -template<> -void RSAnimationLog::WriteAnimationInfoToLog(const PropertyId& propertyId, - const AnimationId& id, const Quaternion& startValue, const Quaternion& endValue) -{ - auto startData = startValue; - auto endData = endValue; - WRITE_LOG("RSAnimationInfoLog AnimationId:{%" PRIu64 "} time:{%" PRIu64 "} property:{%" PRIu64 "} " - "startValue:{%f %f %f %f} endValue:{%f %f %f %f}\n", id, GetNowTime(), propertyId, - startData[DATA_INDEX_ZERO], startData[DATA_INDEX_ONE], startData[DATA_INDEX_TWO], - startData[DATA_INDEX_THREE], endData[DATA_INDEX_ZERO], endData[DATA_INDEX_ONE], - endData[DATA_INDEX_TWO], endData[DATA_INDEX_THREE]); -} - -template<> -void RSAnimationLog::WriteAnimationValueToLog(const std::shared_ptr& value, - const PropertyId& propertyId, const NodeId& id) -{ - auto filter = std::static_pointer_cast(value); - if (filter == nullptr) { - WRITE_LOG("RSAnimationValueLog NodeId:{%" PRIu64 "} time:{%" PRIu64 "} property:{%" PRIu64 "} " - "value:{nullptr}\n", id, GetNowTime(), propertyId); - return; - } - WRITE_LOG("RSAnimationValueLog NodeId:{%" PRIu64 "} time:{%" PRIu64 "} property:{%" PRIu64 "} value:{%f %f}\n", - id, GetNowTime(), propertyId, filter->GetBlurRadiusX(), filter->GetBlurRadiusY()); -} - -template<> -void RSAnimationLog::WriteAnimationInfoToLog(const PropertyId& propertyId, - const AnimationId& id, const std::shared_ptr& startValue, - const std::shared_ptr& endValue) -{ - auto startFilter = std::static_pointer_cast(startValue); - auto endFilter = std::static_pointer_cast(endValue); - if (startFilter == nullptr || endFilter == nullptr) { - WRITE_LOG("RSAnimationValueLog NodeId:{%" PRIu64 "} time:{%" PRIu64 "} property:{%" PRIu64 "} " - "startValue:{nullptr} endValue:{nullptr}\n", id, GetNowTime(), propertyId); - return; - } - WRITE_LOG("RSAnimationInfoLog AnimationId:{%" PRIu64 "} time:{%" PRIu64 "} property:{%" PRIu64 "} " - "startValue:{%f %f} endValue:{%f %f}\n", id, GetNowTime(), propertyId, - startFilter->GetBlurRadiusX(), startFilter->GetBlurRadiusY(), - endFilter->GetBlurRadiusX(), endFilter->GetBlurRadiusY()); -} - -template<> -void RSAnimationLog::WriteAnimationValueToLog(const Vector4& value, - const PropertyId& propertyId, const NodeId& id) -{ - auto data = value; - WRITE_LOG("RSAnimationValueLog NodeId:{%" PRIu64 "} time:{%" PRIu64 "} property:{%" PRIu64 "} " - "value:{%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d}\n", id, GetNowTime(), - propertyId, data[DATA_INDEX_ZERO].GetRed(), data[DATA_INDEX_ZERO].GetGreen(), - data[DATA_INDEX_ZERO].GetBlue(), data[DATA_INDEX_ZERO].GetAlpha(), - data[DATA_INDEX_ONE].GetRed(), data[DATA_INDEX_ONE].GetGreen(), - data[DATA_INDEX_ONE].GetBlue(), data[DATA_INDEX_ONE].GetAlpha(), - data[DATA_INDEX_TWO].GetRed(), data[DATA_INDEX_TWO].GetGreen(), - data[DATA_INDEX_TWO].GetBlue(), data[DATA_INDEX_TWO].GetAlpha(), - data[DATA_INDEX_THREE].GetRed(), data[DATA_INDEX_THREE].GetGreen(), - data[DATA_INDEX_THREE].GetBlue(), data[DATA_INDEX_THREE].GetAlpha()); -} - -template<> -void RSAnimationLog::WriteAnimationInfoToLog(const PropertyId& propertyId, - const AnimationId& id, const Vector4& startValue, const Vector4& endValue) -{ - auto startData = startValue; - auto endData = endValue; - WRITE_LOG("RSAnimationInfoLog AnimationId:{%" PRIu64 "} time:{%" PRIu64 "} property:{%" PRIu64 "} " - "startValue:{%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d} " - "endValue:{%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d}\n", id, GetNowTime(), propertyId, - startData[DATA_INDEX_ZERO].GetRed(), startData[DATA_INDEX_ZERO].GetGreen(), - startData[DATA_INDEX_ZERO].GetBlue(), startData[DATA_INDEX_ZERO].GetAlpha(), - startData[DATA_INDEX_ONE].GetRed(), startData[DATA_INDEX_ONE].GetGreen(), - startData[DATA_INDEX_ONE].GetBlue(), startData[DATA_INDEX_ONE].GetAlpha(), - startData[DATA_INDEX_TWO].GetRed(), startData[DATA_INDEX_TWO].GetGreen(), - startData[DATA_INDEX_TWO].GetBlue(), startData[DATA_INDEX_TWO].GetAlpha(), - startData[DATA_INDEX_THREE].GetRed(), startData[DATA_INDEX_THREE].GetGreen(), - startData[DATA_INDEX_THREE].GetBlue(), startData[DATA_INDEX_THREE].GetAlpha(), - endData[DATA_INDEX_ZERO].GetRed(), endData[DATA_INDEX_ZERO].GetGreen(), - endData[DATA_INDEX_ZERO].GetBlue(), endData[DATA_INDEX_ZERO].GetAlpha(), - endData[DATA_INDEX_ONE].GetRed(), endData[DATA_INDEX_ONE].GetGreen(), - endData[DATA_INDEX_ONE].GetBlue(), endData[DATA_INDEX_ONE].GetAlpha(), - endData[DATA_INDEX_TWO].GetRed(), endData[DATA_INDEX_TWO].GetGreen(), - endData[DATA_INDEX_TWO].GetBlue(), endData[DATA_INDEX_TWO].GetAlpha(), - endData[DATA_INDEX_THREE].GetRed(), endData[DATA_INDEX_THREE].GetGreen(), - endData[DATA_INDEX_THREE].GetBlue(), endData[DATA_INDEX_THREE].GetAlpha()); -} - -template<> -void RSAnimationLog::WriteAnimationValueToLog(const std::shared_ptr& value, - const PropertyId& propertyId, const NodeId& id) -{ -} - -template<> -void RSAnimationLog::WriteAnimationInfoToLog(const PropertyId& propertyId, - const AnimationId& id, const std::shared_ptr& startValue, - const std::shared_ptr& endValue) -{ -} -} // namespace Rosen -} // namespace OHOS \ No newline at end of file diff --git a/rosen/modules/render_service_base/src/animation/rs_render_property_animation.cpp b/rosen/modules/render_service_base/src/animation/rs_render_property_animation.cpp index 3bd4016cc3..ea74ef6377 100644 --- a/rosen/modules/render_service_base/src/animation/rs_render_property_animation.cpp +++ b/rosen/modules/render_service_base/src/animation/rs_render_property_animation.cpp @@ -151,45 +151,5 @@ void RSRenderPropertyAnimation::OnRemoveOnCompletion() SetPropertyValue(backwardValue); } - -void RSRenderPropertyAnimation::WriteAnimationValueToLog(const std::shared_ptr& value) -{ - auto node = GetTarget(); - if (node == nullptr) { - return; - } - - UpdateNeedWriteLog(node->GetId()); - if (needWriteToLog_) { - animationLog_->WriteAnimationValueToLog(value, propertyId_, node->GetId()); - } -} - -void RSRenderPropertyAnimation::WriteAnimationInfoToLog(const std::shared_ptr& startValue, - const std::shared_ptr& endValue) -{ - if (hasWriteInfo_) { - return; - } - - hasWriteInfo_ = true; - auto node = GetTarget(); - if (node == nullptr) { - return; - } - - UpdateNeedWriteLog(node->GetId()); - if (needWriteToLog_) { - animationLog_->WriteAnimationInfoToLog(propertyId_, GetAnimationId(), startValue, endValue); - } -} - -void RSRenderPropertyAnimation::UpdateNeedWriteLog(const NodeId id) -{ - if (!hasUpdateNeedWriteLog_) { - hasUpdateNeedWriteLog_ = true; - needWriteToLog_ = animationLog_->IsNeedWriteLog(propertyId_, id); - } -} } // namespace Rosen } // namespace OHOS diff --git a/rosen/modules/render_service_base/src/pipeline/rs_canvas_render_node.cpp b/rosen/modules/render_service_base/src/pipeline/rs_canvas_render_node.cpp index e4e1446c4f..e3ff27b2e7 100644 --- a/rosen/modules/render_service_base/src/pipeline/rs_canvas_render_node.cpp +++ b/rosen/modules/render_service_base/src/pipeline/rs_canvas_render_node.cpp @@ -64,6 +64,7 @@ void RSCanvasRenderNode::Process(const std::shared_ptr& visitor) if (!visitor) { return; } + RSRenderNode::RenderTraceDebug(); visitor->ProcessCanvasRenderNode(*this); } diff --git a/rosen/modules/render_service_base/src/pipeline/rs_display_render_node.cpp b/rosen/modules/render_service_base/src/pipeline/rs_display_render_node.cpp index 75e2b94d77..42898fd03d 100644 --- a/rosen/modules/render_service_base/src/pipeline/rs_display_render_node.cpp +++ b/rosen/modules/render_service_base/src/pipeline/rs_display_render_node.cpp @@ -54,6 +54,7 @@ void RSDisplayRenderNode::Process(const std::shared_ptr& visitor) if (!visitor) { return; } + RSRenderNode::RenderTraceDebug(); visitor->ProcessDisplayRenderNode(*this); } diff --git a/rosen/modules/render_service_base/src/pipeline/rs_proxy_render_node.cpp b/rosen/modules/render_service_base/src/pipeline/rs_proxy_render_node.cpp index 7810273b1c..8ce3cf90e3 100644 --- a/rosen/modules/render_service_base/src/pipeline/rs_proxy_render_node.cpp +++ b/rosen/modules/render_service_base/src/pipeline/rs_proxy_render_node.cpp @@ -45,6 +45,7 @@ void RSProxyRenderNode::Process(const std::shared_ptr& visitor) if (!visitor) { return; } + RSRenderNode::RenderTraceDebug(); visitor->ProcessProxyRenderNode(*this); } diff --git a/rosen/modules/render_service_base/src/pipeline/rs_render_node.cpp b/rosen/modules/render_service_base/src/pipeline/rs_render_node.cpp index 466147fd03..ac4b3e1372 100644 --- a/rosen/modules/render_service_base/src/pipeline/rs_render_node.cpp +++ b/rosen/modules/render_service_base/src/pipeline/rs_render_node.cpp @@ -22,6 +22,7 @@ #include "pipeline/rs_context.h" #include "pipeline/rs_surface_render_node.h" #include "platform/common/rs_log.h" +#include "property/rs_property_trace.h" #ifdef ROSEN_OHOS #include "pipeline/rs_paint_filter_canvas.h" #include "property/rs_properties_painter.h" @@ -146,6 +147,14 @@ void RSRenderNode::UpdateRenderStatus(RectI& dirtyRegion, bool isPartialRenderEn } } +void RSRenderNode::RenderTraceDebug() const +{ + if (RSSystemProperties::GetRenderNodeTraceEnabled()) { + RSPropertyTrace::GetInstance().PropertiesDisplayByTrace(GetId(), + std::static_pointer_cast(GetRenderProperties().GetBoundsGeometry())); + } +} + void RSRenderNode::ProcessRenderBeforeChildren(RSPaintFilterCanvas& canvas) { #ifdef ROSEN_OHOS diff --git a/rosen/modules/render_service_base/src/pipeline/rs_root_render_node.cpp b/rosen/modules/render_service_base/src/pipeline/rs_root_render_node.cpp index ba2fe2b7bf..cbab527c27 100644 --- a/rosen/modules/render_service_base/src/pipeline/rs_root_render_node.cpp +++ b/rosen/modules/render_service_base/src/pipeline/rs_root_render_node.cpp @@ -78,6 +78,7 @@ void RSRootRenderNode::Process(const std::shared_ptr& visitor) if (!visitor) { return; } + RSRenderNode::RenderTraceDebug(); visitor->ProcessRootRenderNode(*this); } } // namespace Rosen diff --git a/rosen/modules/render_service_base/src/pipeline/rs_surface_render_node.cpp b/rosen/modules/render_service_base/src/pipeline/rs_surface_render_node.cpp index 07d9894504..069b86b941 100644 --- a/rosen/modules/render_service_base/src/pipeline/rs_surface_render_node.cpp +++ b/rosen/modules/render_service_base/src/pipeline/rs_surface_render_node.cpp @@ -203,6 +203,7 @@ void RSSurfaceRenderNode::Process(const std::shared_ptr& visitor) if (!visitor) { return; } + RSRenderNode::RenderTraceDebug(); visitor->ProcessSurfaceRenderNode(*this); } diff --git a/rosen/modules/render_service_base/src/platform/ohos/rs_system_properties.cpp b/rosen/modules/render_service_base/src/platform/ohos/rs_system_properties.cpp index 81ad56b41b..8c55ef3330 100644 --- a/rosen/modules/render_service_base/src/platform/ohos/rs_system_properties.cpp +++ b/rosen/modules/render_service_base/src/platform/ohos/rs_system_properties.cpp @@ -37,6 +37,12 @@ bool RSSystemProperties::GetUniRenderEnabled() return isUniRenderEnabled_; } +bool RSSystemProperties::GetRenderNodeTraceEnabled() +{ + static bool isNeedTrace = system::GetParameter("persist.rosen.rendernodetrace.enabled", "0") != "0"; + return isNeedTrace; +} + bool RSSystemProperties::IsUniRenderMode() { return isUniRenderMode_; diff --git a/rosen/modules/render_service_base/src/property/rs_property_trace.cpp b/rosen/modules/render_service_base/src/property/rs_property_trace.cpp new file mode 100644 index 0000000000..cace5d66eb --- /dev/null +++ b/rosen/modules/render_service_base/src/property/rs_property_trace.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "property/rs_property_trace.h" + +#include +#include +#include +#include +#include + +#include "rs_trace.h" + +namespace OHOS { +namespace Rosen { +const std::string ANIMATION_LOG_PATH = "/etc/rosen/"; +const std::string CONFIG_FILE_NAME = "property.config"; +const std::string COLON_SEPARATOR = ":"; +const std::string COMMA_SEPARATOR = ","; +const std::string SEMICOLON_SEPARATOR = ";"; +const std::string NODE_ID_TAG = "ID"; +const std::string ALL_NEED_TAG = "all"; +static constexpr int MIN_INFO_SIZE = 2; +RSPropertyTrace RSPropertyTrace::instance_; + +void RSPropertyTrace::PropertiesDisplayByTrace(const NodeId& id, + const std::shared_ptr& boundsGeometry) +{ + if (IsNeedPropertyTrace(id)) { + auto rectI = boundsGeometry->GetAbsRect(); + AddTraceFlag(std::to_string(id) + " Geometry Rect: " + rectI.ToString()); + } +} + +void RSPropertyTrace::RefreshNodeTraceInfo() +{ + if (IsNeedRefreshConfig()) { + InitNodeAndPropertyInfo(); + } +} + +void RSPropertyTrace::AddTraceFlag(const std::string& str) +{ + ROSEN_TRACE_BEGIN(HITRACE_TAG_GRAPHIC_AGP, str.c_str()); + ROSEN_TRACE_END(HITRACE_TAG_GRAPHIC_AGP); +} + +std::vector SplitStringBySeparator(const std::string& str, + const std::string& separator) +{ + std::regex re(separator); + std::sregex_token_iterator pos(str.begin(), str.end(), re, -1); + std::sregex_token_iterator endPos; + std::vector result; + while (pos != endPos) { + result.emplace_back(*pos++); + } + return result; +} + +void RSPropertyTrace::InitNodeAndPropertyInfo() +{ + std::string configFilePath = ANIMATION_LOG_PATH + CONFIG_FILE_NAME; + char newpath[PATH_MAX + 1] = { 0x00 }; + if (strlen(configFilePath.c_str()) > PATH_MAX || realpath(configFilePath.c_str(), newpath) == nullptr) { + ROSEN_LOGE("Render node trace config file is nullptr!"); + return; + } + std::ifstream configFile(newpath); + if (!configFile.is_open()) { + ROSEN_LOGE("Open render node trace config file failed!"); + return; + } + + std::string info; + while (std::getline(configFile, info)) { + std::vector infos = SplitStringBySeparator(info, SEMICOLON_SEPARATOR); + if (infos.empty()) { + continue; + } + DealConfigInputInfo(infos.front()); + } + configFile.close(); +} + +void RSPropertyTrace::DealConfigInputInfo(const std::string& info) +{ + std::vector splitResult = SplitStringBySeparator(info, COLON_SEPARATOR); + if (splitResult.size() != MIN_INFO_SIZE) { + ROSEN_LOGE("Render node trace config file size error!"); + return; + } + + std::string tag = splitResult.front(); + if (tag == NODE_ID_TAG) { + std::vector nodeIds = + SplitStringBySeparator(splitResult.back(), COMMA_SEPARATOR); + for (std::string nodeId : nodeIds) { + if (nodeId == ALL_NEED_TAG) { + needWriteAllNode_ = true; + return; + } + auto id = atoll(nodeId.c_str()); + nodeIdSet_.insert(id); + } + } +} + +void RSPropertyTrace::ClearNodeAndPropertyInfo() +{ + nodeIdSet_.clear(); +} + +bool RSPropertyTrace::IsNeedRefreshConfig() +{ + struct stat configFileStatus = {}; + std::string configFilePath = ANIMATION_LOG_PATH + CONFIG_FILE_NAME; + if (stat(configFilePath.c_str(), &configFileStatus)) { + return false; + } + + std::string curent(ctime(&configFileStatus.st_mtime)); + if (curent != propertyFileLastModifyTime) { + propertyFileLastModifyTime = curent; + return true; + } + return false; +} + +bool RSPropertyTrace::IsNeedPropertyTrace(const NodeId& id) +{ + auto itrn = nodeIdSet_.find(id); + if (itrn == nodeIdSet_.end() && !needWriteAllNode_) { + return false; + } + return true; +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/rosen/modules/render_service_client/core/pipeline/rs_render_thread.cpp b/rosen/modules/render_service_client/core/pipeline/rs_render_thread.cpp index 24a5a8782f..6b93f8dc19 100644 --- a/rosen/modules/render_service_client/core/pipeline/rs_render_thread.cpp +++ b/rosen/modules/render_service_client/core/pipeline/rs_render_thread.cpp @@ -30,6 +30,7 @@ #include "pipeline/rs_surface_render_node.h" #include "platform/common/rs_log.h" #include "platform/common/rs_system_properties.h" +#include "property/rs_property_trace.h" #include "transaction/rs_render_service_client.h" #include "ui/rs_surface_extractor.h" #include "ui/rs_surface_node.h" @@ -425,6 +426,9 @@ void RSRenderThread::Render() if (!needRender_) { return; } + if (RSSystemProperties::GetRenderNodeTraceEnabled()) { + RSPropertyTrace::GetInstance().RefreshNodeTraceInfo(); + } ROSEN_TRACE_BEGIN(HITRACE_TAG_GRAPHIC_AGP, "RSRenderThread::Render"); if (RsFrameReport::GetInstance().GetEnable()) { RsFrameReport::GetInstance().RenderStart(); -- Gitee