update the profiler tools

Signed-off-by: sunfei <sunfei.sun@huawei.com>
Change-Id:  I05d8057ad051af6a185ce7dcdf71e9ab2513dc8f
This commit is contained in:
yanshuifeng
2021-12-25 21:47:20 +08:00
committed by sunfei
parent d48b4ae178
commit 617ac57c6b
15 changed files with 282 additions and 9 deletions
+1
View File
@@ -36,6 +36,7 @@ template("ace_base_source_set") {
"geometry/transform_util.cpp",
"json/json_util.cpp",
"log/ace_trace.cpp",
"log/ace_tracker.cpp",
"log/dump_log.cpp",
"memory/memory_monitor.cpp",
"thread/background_task_executor.cpp",
+5
View File
@@ -232,6 +232,11 @@ bool JsonValue::Put(const char* key, int32_t value)
return true;
}
bool JsonValue::Put(const char* key, int64_t value)
{
return Put(key, static_cast<double>(value));
}
bool JsonValue::Put(const char* key, double value)
{
if (key == nullptr) {
+1
View File
@@ -73,6 +73,7 @@ public:
bool Put(const char* key, const char* value);
bool Put(const char* key, size_t value);
bool Put(const char* key, int32_t value);
bool Put(const char* key, int64_t value);
bool Put(const char* key, double value);
bool Put(const char* key, bool value);
bool Put(const char* key, const std::unique_ptr<JsonValue>& value);
+55
View File
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2021 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 "base/log/ace_tracker.h"
#include "base/log/log.h"
#include "base/utils/time_util.h"
namespace OHOS::Ace {
std::unique_ptr<JsonValue> AceTracker::trackInfo_ = nullptr;
void AceTracker::Start()
{
trackInfo_ = JsonUtil::Create(true);
}
std::string AceTracker::Stop()
{
if (trackInfo_) {
auto info = trackInfo_->ToString();
trackInfo_.reset(nullptr);
return info;
}
return "{}";
}
AceScopedTracker::AceScopedTracker(const std::string& tag) : tag_(tag)
{
if (AceTracker::trackInfo_) {
// micro sec.
markTime_ = GetMicroTickCount();
}
}
AceScopedTracker::~AceScopedTracker()
{
if (AceTracker::trackInfo_) {
// convert micro sec to ms with 1000.
AceTracker::trackInfo_->Put(tag_.c_str(), (GetMicroTickCount() - markTime_) / 1000.0);
}
}
} // namespace OHOS::Ace
+63
View File
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2021 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.
*/
#ifndef FOUNDATION_ACE_FRAMEWORKS_BASE_LOG_ACE_TRACKER_H
#define FOUNDATION_ACE_FRAMEWORKS_BASE_LOG_ACE_TRACKER_H
#include <cstdarg>
#include <cstdint>
#include <cstdio>
#include <string>
#include "base/json/json_util.h"
#include "base/utils/macros.h"
#include "base/utils/noncopyable.h"
#define ACE_FUNCTION_TRACK() AceScopedTracker aceScopedTracker(__func__)
namespace OHOS::Ace {
class ACE_EXPORT AceTracker final {
public:
static void Start();
static std::string Stop();
private:
AceTracker() = default;
~AceTracker() = default;
static std::unique_ptr<JsonValue> trackInfo_;
friend class AceScopedTracker;
ACE_DISALLOW_COPY_AND_MOVE(AceTracker);
};
class ACE_EXPORT AceScopedTracker final {
public:
explicit AceScopedTracker(const std::string& tag);
~AceScopedTracker();
private:
std::string tag_;
// micro sec
int64_t markTime_ = 0;
ACE_DISALLOW_COPY_AND_MOVE(AceScopedTracker);
};
} // namespace OHOS::Ace
#endif // FOUNDATION_ACE_FRAMEWORKS_BASE_LOG_ACE_TRACKER_H
@@ -112,6 +112,7 @@ template("declarative_js_engine") {
"engine/functions/js_pan_function.cpp",
"engine/functions/js_touch_function.cpp",
"engine/js_types.cpp",
"interfaces/profiler/js_profiler.cpp",
"jsview/action_sheet/js_action_sheet.cpp",
"jsview/dialog/js_alert_dialog.cpp",
"jsview/dialog/js_custom_dialog_controller.cpp",
@@ -35,10 +35,9 @@ public:
void Execute();
void Execute(const std::vector<std::string>& keys, const std::string& param);
void ExecuteNew(const std::vector<std::string>& keys, const std::string& param);
protected:
JSRef<JSVal> ExecuteJS(int argc = 0, JSRef<JSVal>* argv = nullptr);
protected:
JSRef<JSFunc> jsFunction_;
JSWeak<JSVal> jsThis_;
};
@@ -15,6 +15,7 @@
#include "base/i18n/localization.h"
#include "base/log/log.h"
#include "bridge/declarative_frontend/interfaces/profiler/js_profiler.h"
#include "bridge/declarative_frontend/jsview/js_canvas_image_data.h"
#include "frameworks/bridge/declarative_frontend/engine/functions/js_drag_function.h"
#include "frameworks/bridge/declarative_frontend/engine/js_object_template.h"
@@ -879,6 +880,8 @@ void JsRegisterViews(BindingTarget globalObj)
JSPersistent::JSBind(globalObj);
JSScroller::JSBind(globalObj);
JSProfiler::JSBind(globalObj);
auto delegate = JsGetFrontendDelegate();
std::string jsModules;
if (delegate && delegate->GetAssetContent("component_collection.txt", jsModules)) {
@@ -18,6 +18,7 @@
#include "base/i18n/localization.h"
#include "base/log/log.h"
#include "bridge/common/accessibility/js_accessibility_manager.h"
#include "bridge/declarative_frontend/interfaces/profiler/js_profiler.h"
#include "bridge/declarative_frontend/jsview/js_canvas_image_data.h"
#include "core/components/common/layout/constants.h"
#include "frameworks/bridge/declarative_frontend/engine/functions/js_drag_function.h"
@@ -836,6 +837,8 @@ void JsRegisterViews(BindingTarget globalObj)
JsDragFunction::JSBind(globalObj);
JSProfiler::JSBind(globalObj);
JSObjectTemplate mainAxisAlign;
mainAxisAlign.Constant("Start", 1);
mainAxisAlign.Constant("Center", 2);
@@ -15,6 +15,7 @@
#include "base/i18n/localization.h"
#include "base/log/log.h"
#include "bridge/declarative_frontend/interfaces/profiler/js_profiler.h"
#include "bridge/declarative_frontend/jsview/js_canvas_image_data.h"
#include "frameworks/bridge/declarative_frontend/engine/functions/js_drag_function.h"
#include "frameworks/bridge/declarative_frontend/engine/js_object_template.h"
@@ -754,6 +755,8 @@ void JsRegisterViews(BindingTarget globalObj)
JSPersistent::JSBind(globalObj);
JSClipboard::JSBind(globalObj);
JSProfiler::JSBind(globalObj);
auto delegate =
static_cast<RefPtr<FrontendDelegate>*>(isolate->GetData(V8DeclarativeEngineInstance::FRONTEND_DELEGATE));
std::string jsModules;
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2021 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 "bridge/declarative_frontend/interfaces/profiler/js_profiler.h"
#include <memory>
#include "bridge/declarative_frontend/engine/bindings.h"
#include "bridge/declarative_frontend/engine/functions/js_function.h"
#include "bridge/declarative_frontend/engine/js_ref_ptr.h"
#include "bridge/declarative_frontend/engine/js_types.h"
#include "core/common/container.h"
namespace OHOS::Ace::Framework {
void JSProfiler::JSBind(BindingTarget globalObj)
{
JSClass<JSProfiler>::Declare("Profiler");
JSClass<JSProfiler>::StaticMethod("registerVsyncCallback", &JSProfiler::JsRegisterVsyncCallback);
JSClass<JSProfiler>::StaticMethod("unregisterVsyncCallback", &JSProfiler::JsUnregisterVsyncCallback);
JSClass<JSProfiler>::Bind<>(globalObj);
}
void JSProfiler::JsRegisterVsyncCallback(const JSCallbackInfo& args)
{
if (!args[0]->IsFunction()) {
LOGE("fail to register callback due to args is not function");
return;
}
auto container = Container::Current();
auto pipelineContext = container ? container->GetPipelineContext() : nullptr;
if (!pipelineContext) {
LOGE("fail to register callback due to pipeline is null");
return;
}
auto onVsyncJsFunc = AceType::MakeRefPtr<JsFunction>(JSRef<JSFunc>::Cast(args[0]));
auto onVsyncFunc = [execCtx = args.GetExecutionContext(), func = std::move(onVsyncJsFunc)](
const std::string& value) {
JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
JSRef<JSVal> params[1];
params[0] = JSRef<JSVal>::Make(ToJSValue(value));
func->ExecuteJS(1, params);
};
pipelineContext->SetOnVsyncProfiler(onVsyncFunc);
}
void JSProfiler::JsUnregisterVsyncCallback()
{
auto container = Container::Current();
auto pipelineContext = container ? container->GetPipelineContext() : nullptr;
if (!pipelineContext) {
LOGE("fail to unregister callback due to pipeline is null");
return;
}
pipelineContext->ResetOnVsyncProfiler();
}
} // namespace OHOS::Ace::Framework
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2021 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.
*/
#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_INTERFACES_PROFILER_JS_PROFILER_H
#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_INTERFACES_PROFILER_JS_PROFILER_H
#include "bridge/declarative_frontend/engine/bindings_defines.h"
namespace OHOS::Ace::Framework {
class JSProfiler {
public:
static void JSBind(BindingTarget globalObj);
static void JsRegisterVsyncCallback(const JSCallbackInfo& args);
static void JsUnregisterVsyncCallback();
};
} // namespace OHOS::Ace::Framework
#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_INTERFACES_PROFILER_JS_PROFILER_H
@@ -29,6 +29,7 @@ namespace OHOS::Ace {
enum class SliderMode {
OUTSET, // block on track, track is thin
INSET, // block inside track, track is rough
// TODO: delete this mode.
CAPSULE, // capsule slider.
};
+28 -3
View File
@@ -25,6 +25,7 @@
#endif
#include "base/log/ace_trace.h"
#include "base/log/ace_tracker.h"
#include "base/log/dump_log.h"
#include "base/log/event_report.h"
#include "base/log/log.h"
@@ -65,8 +66,8 @@
#include "core/components/stage/stage_component.h"
#include "core/components/stage/stage_element.h"
#include "core/components/theme/app_theme.h"
#include "core/components_v2/inspector/shape_composed_element.h"
#include "core/components_v2/inspector/inspector_composed_element.h"
#include "core/components_v2/inspector/shape_composed_element.h"
#include "core/image/image_provider.h"
#include "core/pipeline/base/composed_element.h"
#include "core/pipeline/base/factories/flutter_render_factory.h"
@@ -189,6 +190,7 @@ void PipelineContext::FlushPipelineWithoutAnimation()
void PipelineContext::FlushMessages()
{
ACE_FUNCTION_TRACK();
#ifdef ENABLE_ROSEN_BACKEND
if (SystemProperties::GetRosenBackendEnabled() && rsUIDirector_) {
rsUIDirector_->SendMessages();
@@ -198,8 +200,9 @@ void PipelineContext::FlushMessages()
void PipelineContext::FlushBuild()
{
ACE_FUNCTION_TRACE();
CHECK_RUN_ON(UI);
ACE_FUNCTION_TRACK();
ACE_FUNCTION_TRACE();
isRebuildFinished_ = false;
if (dirtyElements_.empty()) {
@@ -248,6 +251,7 @@ void PipelineContext::FlushPredictLayout(int64_t targetTimestamp)
void PipelineContext::FlushFocus()
{
CHECK_RUN_ON(UI);
ACE_FUNCTION_TRACK();
if (dirtyFocusNode_) {
dirtyFocusNode_->RequestFocusImmediately();
dirtyFocusNode_.Reset();
@@ -276,6 +280,7 @@ void PipelineContext::FlushFocus()
void PipelineContext::FireVisibleChangeEvent()
{
ACE_FUNCTION_TRACK();
auto accessibilityManager = GetAccessibilityManager();
if (accessibilityManager) {
accessibilityManager->TriggerVisibleChangeEvent();
@@ -406,6 +411,7 @@ void PipelineContext::CreateGeometryTransition()
void PipelineContext::FlushLayout()
{
CHECK_RUN_ON(UI);
ACE_FUNCTION_TRACK();
ACE_FUNCTION_TRACE();
if (dirtyLayoutNodes_.empty()) {
@@ -471,6 +477,7 @@ void PipelineContext::CorrectPosition()
void PipelineContext::FlushRender()
{
CHECK_RUN_ON(UI);
ACE_FUNCTION_TRACK();
ACE_FUNCTION_TRACE();
if (dirtyRenderNodes_.empty() && dirtyRenderNodesInOverlay_.empty() && !needForcedRefresh_) {
@@ -538,6 +545,7 @@ void PipelineContext::FlushRender()
void PipelineContext::FlushRenderFinish()
{
CHECK_RUN_ON(UI);
ACE_FUNCTION_TRACK();
ACE_FUNCTION_TRACE();
if (!needPaintFinishNodes_.empty()) {
@@ -551,6 +559,7 @@ void PipelineContext::FlushRenderFinish()
void PipelineContext::FlushAnimation(uint64_t nanoTimestamp)
{
CHECK_RUN_ON(UI);
ACE_FUNCTION_TRACK();
ACE_FUNCTION_TRACE();
flushAnimationTimestamp_ = nanoTimestamp;
isFlushingAnimation_ = true;
@@ -570,6 +579,7 @@ void PipelineContext::FlushAnimation(uint64_t nanoTimestamp)
void PipelineContext::FlushPostAnimation()
{
CHECK_RUN_ON(UI);
ACE_FUNCTION_TRACK();
ACE_FUNCTION_TRACE();
if (postAnimationFlushListeners_.empty()) {
@@ -596,6 +606,7 @@ void PipelineContext::FlushPageUpdateTasks()
void PipelineContext::FlushAnimationTasks()
{
CHECK_RUN_ON(UI);
ACE_FUNCTION_TRACK();
if (animationCallback_) {
taskExecutor_->PostTask(animationCallback_, TaskExecutor::TaskType::JS);
}
@@ -629,6 +640,7 @@ void PipelineContext::ProcessPreFlush()
void PipelineContext::ProcessPostFlush()
{
CHECK_RUN_ON(UI);
ACE_FUNCTION_TRACK();
ACE_FUNCTION_TRACE();
if (postFlushListeners_.empty()) {
@@ -1511,7 +1523,19 @@ void PipelineContext::OnVsyncEvent(uint64_t nanoTimestamp, uint32_t frameCount)
{
CHECK_RUN_ON(UI);
ACE_FUNCTION_TRACE();
if (onVsyncProfiler_) {
AceTracker::Start();
}
FlushVsync(nanoTimestamp, frameCount);
if (onVsyncProfiler_) {
onVsyncProfiler_(AceTracker::Stop());
}
}
void PipelineContext::FlushVsync(uint64_t nanoTimestamp, uint32_t frameCount)
{
CHECK_RUN_ON(UI);
ACE_FUNCTION_TRACK();
#if defined(ENABLE_NATIVE_VIEW)
if (frameCount_ < 2) {
frameCount_++;
@@ -1522,7 +1546,6 @@ void PipelineContext::OnVsyncEvent(uint64_t nanoTimestamp, uint32_t frameCount)
rsUIDirector_->SetTimeStamp(nanoTimestamp);
}
#endif
if (isSurfaceReady_) {
FlushAnimation(GetTimeFromExternalTimer());
FlushPipelineWithoutAnimation();
@@ -2474,6 +2497,7 @@ void PipelineContext::AddDeactivateElement(const int32_t id, const RefPtr<Elemen
void PipelineContext::ClearDeactivateElements()
{
CHECK_RUN_ON(UI);
ACE_FUNCTION_TRACK();
for (auto iter = deactivateElements_.begin(); iter != deactivateElements_.end();) {
auto element = iter->second;
RefPtr<RenderNode> render = element ? element->GetRenderNode() : nullptr;
@@ -2607,6 +2631,7 @@ bool PipelineContext::ProcessDragEvent(int action, double windowX, double window
void PipelineContext::FlushWindowBlur()
{
CHECK_RUN_ON(UI);
ACE_FUNCTION_TRACK();
if (!updateWindowBlurRegionHandler_) {
return;
+16 -4
View File
@@ -721,8 +721,7 @@ public:
bool CloseImplicitAnimation();
void AddKeyFrame(float fraction, const RefPtr<Curve>& curve,
const std::function<void()>& propertyCallback);
void AddKeyFrame(float fraction, const RefPtr<Curve>& curve, const std::function<void()>& propertyCallback);
void AddKeyFrame(float fraction, const std::function<void()>& propertyCallback);
@@ -901,7 +900,7 @@ public:
{
surfaceChangedCallbackMap_.erase(callbackId);
}
void StartSystemDrag(const std::string &str, const RefPtr<PixelMap>& pixmap);
void StartSystemDrag(const std::string& str, const RefPtr<PixelMap>& pixmap);
void InitDragListener();
bool ProcessDragEvent(int action, double windowX, double windowY, const std::string& data);
void SetPreTargetRenderNode(const RefPtr<RenderNode>& preTargetRenderNode);
@@ -968,7 +967,18 @@ public:
const std::shared_ptr<OHOS::Rosen::RSUIDirector>& GetRSUIDirector();
void SetOnVsyncProfiler(const std::function<void(const std::string&)> callback)
{
onVsyncProfiler_ = callback;
}
void ResetOnVsyncProfiler()
{
onVsyncProfiler_ = nullptr;
}
private:
void FlushVsync(uint64_t nanoTimestamp, uint32_t frameCount);
void FlushPipelineWithoutAnimation();
void FlushLayout();
void FlushGeometryProperties();
@@ -1172,11 +1182,13 @@ private:
SurfaceChangedCallbackMap surfaceChangedCallbackMap_;
std::vector<WeakPtr<PipelineContext>> touchPluginPipelineContext_;
Offset pluginOffset_ {0, 0};
Offset pluginOffset_ { 0, 0 };
bool isRebuildFinished_ = false;
std::shared_ptr<OHOS::Rosen::RSUIDirector> rsUIDirector_;
std::function<void(const std::string&)> onVsyncProfiler_;
ACE_DISALLOW_COPY_AND_MOVE(PipelineContext);
};