!21300 ace_engine动效事件进行异步trace打点,增加isReportInteractionEvent和isAnimationTrace事件上报

Merge pull request !21300 from duqian/master
This commit is contained in:
openharmony_ci 2023-11-06 08:07:08 +00:00 committed by Gitee
commit 43b7e8609e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 73 additions and 20 deletions

View File

@ -41,18 +41,26 @@ void AceTraceEnd()
FinishTrace(HITRACE_TAG_ACE);
}
void AceAsyncTraceBegin(int32_t taskId, const char* name)
void AceAsyncTraceBegin(int32_t taskId, const char* name, bool isAnimationTrace)
{
CHECK_NULL_VOID(name);
std::string nameStr(name);
StartAsyncTrace(HITRACE_TAG_ACE, nameStr, taskId);
if (isAnimationTrace) {
StartAsyncTrace(HITRACE_TAG_ANIMATION, nameStr, taskId);
} else {
StartAsyncTrace(HITRACE_TAG_ACE, nameStr, taskId);
}
}
void AceAsyncTraceEnd(int32_t taskId, const char* name)
void AceAsyncTraceEnd(int32_t taskId, const char* name, bool isAnimationTrace)
{
CHECK_NULL_VOID(name);
std::string nameStr(name);
FinishAsyncTrace(HITRACE_TAG_ACE, nameStr, taskId);
if (isAnimationTrace) {
FinishAsyncTrace(HITRACE_TAG_ANIMATION, nameStr, taskId);
} else {
FinishAsyncTrace(HITRACE_TAG_ACE, nameStr, taskId);
}
}
void AceCountTrace(const char *key, int32_t count)

View File

@ -30,11 +30,11 @@ void AceTraceEnd()
{
}
void AceAsyncTraceBegin(int32_t taskId, const char* name)
void AceAsyncTraceBegin(int32_t taskId, const char* name, bool isAnimationTrace)
{
}
void AceAsyncTraceEnd(int32_t taskId, const char* name)
void AceAsyncTraceEnd(int32_t taskId, const char* name, bool isAnimationTrace)
{
}

View File

@ -44,13 +44,13 @@ namespace OHOS::Ace {
bool ACE_EXPORT AceTraceEnabled();
bool ACE_EXPORT AceAsyncTraceEnable();
void ACE_EXPORT AceTraceBegin(const char* name);
void ACE_EXPORT AceAsyncTraceBegin(int32_t taskId, const char* name);
void ACE_EXPORT AceAsyncTraceBegin(int32_t taskId, const char* name, bool isAnimationTrace = false);
bool ACE_EXPORT AceTraceBeginWithArgs(const char* format, ...) __attribute__((__format__(printf, 1, 2)));
std::string ACE_EXPORT AceAsyncTraceBeginWithArgs(int32_t taskId, char* format, ...);
bool ACE_EXPORT AceTraceBeginWithArgv(const char* format, va_list args);
std::string ACE_EXPORT AceAsyncTraceBeginWithArgv(int32_t taskId, const char* format, va_list args);
void ACE_EXPORT AceTraceEnd();
void ACE_EXPORT AceAsyncTraceEnd(int32_t taskId, const char* name);
void ACE_EXPORT AceAsyncTraceEnd(int32_t taskId, const char* name, bool isAnimationTrace = false);
void ACE_EXPORT AceCountTrace(const char *key, int32_t count);
void ACE_EXPORT AceCountTraceWidthArgs(int32_t count, const char* format, ...);

View File

@ -101,6 +101,8 @@ void ConvertToRsData(OHOS::Rosen::DataBaseRs &dataRs, DataBase& data)
dataRs.pageUrl = data.baseInfo.pageUrl;
dataRs.sourceType = GetSourceTypeName(data.sourceType);
dataRs.note = data.baseInfo.note;
dataRs.isAnimationTrace = data.isAnimationTrace;
dataRs.isReportInteractionEvent = data.isReportInteractionEvent;
}
void ReportPerfEventToRS(DataBase& data)
@ -216,6 +218,8 @@ void SceneRecord::Reset()
totalFrames = 0;
isSuccessive = false;
isFirstFrame = false;
isAnimationTrace = false;
isReportInteractionEvent = true;
sceneId = "";
actionType = UNKNOWN_ACTION;
sourceType = UNKNOWN_SOURCE;
@ -230,9 +234,10 @@ PerfMonitor* PerfMonitor::GetPerfMonitor()
return pMonitor;
}
void PerfMonitor::Start(const std::string& sceneId, PerfActionType type, const std::string& note)
void PerfMonitor::Start(const std::string& sceneId, PerfActionType type, const std::string& note,
bool isReportInteractionEvent, bool isAnimationTrace)
{
AceAsyncTraceBegin(0, sceneId.c_str());
AceAsyncTraceBegin(0, sceneId.c_str(), isAnimationTrace);
std::lock_guard<std::mutex> Lock(mMutex);
// inactive animator start on inputtime
if (GetInputTime(type) <= 0) {
@ -243,15 +248,19 @@ void PerfMonitor::Start(const std::string& sceneId, PerfActionType type, const s
if (record != nullptr) {
record->Reset();
record->InitRecord(sceneId, type, mSourceType, note, inputTime);
record->isReportInteractionEvent = isReportInteractionEvent;
record->isAnimationTrace = isAnimationTrace;
} else {
record = new SceneRecord();
record->InitRecord(sceneId, type, mSourceType, note, inputTime);
record->isReportInteractionEvent = isReportInteractionEvent;
record->isAnimationTrace = isAnimationTrace;
mRecords.insert(std::pair<std::string, SceneRecord*> (sceneId, record));
}
RecordBaseInfo(record);
}
void PerfMonitor::End(const std::string& sceneId, bool isRsRender)
void PerfMonitor::End(const std::string& sceneId, bool isRsRender, bool isAnimationTrace)
{
std::lock_guard<std::mutex> Lock(mMutex);
SceneRecord* record = GetRecord(sceneId);
@ -260,7 +269,7 @@ void PerfMonitor::End(const std::string& sceneId, bool isRsRender)
record->Report(sceneId, mVsyncTime, isRsRender);
ReportAnimateEnd(sceneId, record, !isRsRender);
RemoveRecord(sceneId);
AceAsyncTraceEnd(0, sceneId.c_str());
AceAsyncTraceEnd(0, sceneId.c_str(), isAnimationTrace);
}
}
@ -422,6 +431,8 @@ void PerfMonitor::FlushDataBase(SceneRecord* record, DataBase& data, bool needCo
data.totalMissed = record->totalMissed;
data.totalFrames = record->totalFrames;
data.needReportToRS = needCompleteTime;
data.isAnimationTrace = record->isAnimationTrace;
data.isReportInteractionEvent = record->isReportInteractionEvent;
data.sourceType = record->sourceType;
data.actionType = record->actionType;
data.baseInfo = baseInfo;

View File

@ -71,6 +71,8 @@ struct DataBase {
int64_t beginVsyncTime {0};
int64_t endVsyncTime {0};
bool needReportToRS {false};
bool isAnimationTrace {false};
bool isReportInteractionEvent {true};
PerfSourceType sourceType {UNKNOWN_SOURCE};
PerfActionType actionType {UNKNOWN_ACTION};
PerfEventType eventType {UNKNOWN_EVENT};
@ -105,6 +107,8 @@ public:
int32_t seqMissFrames {0};
bool isSuccessive {false};
bool isFirstFrame {false};
bool isAnimationTrace {false};
bool isReportInteractionEvent {true};
std::string sceneId {""};
PerfActionType actionType {UNKNOWN_ACTION};
PerfSourceType sourceType {UNKNOWN_SOURCE};
@ -113,8 +117,9 @@ public:
class ACE_FORCE_EXPORT PerfMonitor {
public:
void Start(const std::string& sceneId, PerfActionType type, const std::string& note);
void End(const std::string& sceneId, bool isJsApi);
void Start(const std::string& sceneId, PerfActionType type, const std::string& note,
bool isReportInteractionEvent = true, bool isAnimationTrace = false);
void End(const std::string& sceneId, bool isJsApi, bool isAnimationTrace = false);
void RecordInputEvent(PerfActionType type, PerfSourceType sourceType, int64_t time);
int64_t GetInputTime(PerfActionType type);
void SetFrameTime(int64_t vsyncTime, int64_t duration, double jank);

View File

@ -15,9 +15,15 @@
#include "bridge/declarative_frontend/jsview/js_view_context.h"
#include <atomic>
#include <cstdint>
#include <functional>
#include <memory>
#include <sstream>
#include "base/log/ace_trace.h"
#include "base/log/jank_frame_report.h"
#include "base/perfmonitor/perf_monitor.h"
#include "base/utils/system_properties.h"
#include "bridge/common/utils/engine_helper.h"
#include "bridge/common/utils/utils.h"
@ -35,7 +41,7 @@ namespace OHOS::Ace {
std::unique_ptr<ViewContextModel> ViewContextModel::instance_ = nullptr;
std::mutex ViewContextModel::mutex_;
std::atomic<int32_t> g_animationId = 0;
ViewContextModel* ViewContextModel::GetInstance()
{
if (!instance_) {
@ -132,6 +138,12 @@ int64_t GetFormAnimationTimeInterval(const RefPtr<PipelineBase>& pipelineContext
return (GetMicroTickCount() - pipelineContext->GetFormAnimationStartTime()) / MICROSEC_TO_MILLISEC;
}
bool CheckIfSetFormAnimationDuration(RefPtr<PipelineBase>& pipelineContext, AnimationOption& option)
{
CHECK_NULL_RETURN(pipelineContext, false);
return pipelineContext->IsFormAnimationFinishCallback() && pipelineContext->IsFormRender() &&
option.GetDuration() > (DEFAULT_DURATION - GetFormAnimationTimeInterval(pipelineContext));
}
} // namespace
const AnimationOption JSViewContext::CreateAnimation(
@ -314,13 +326,20 @@ void JSViewContext::JSAnimateTo(const JSCallbackInfo& info)
JSRef<JSObject> obj = JSRef<JSObject>::Cast(info[0]);
JSRef<JSVal> onFinish = obj->GetProperty("onFinish");
std::function<void()> onFinishEvent;
uint32_t animationId = g_animationId.fetch_add(1, std::memory_order_relaxed);
auto traceStreamPtr = std::make_shared<std::stringstream>();
if (onFinish->IsFunction()) {
RefPtr<JsFunction> jsFunc = AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(onFinish));
onFinishEvent = [execCtx = info.GetExecutionContext(), func = std::move(jsFunc),
id = Container::CurrentId()]() {
id = Container::CurrentId(), traceStreamPtr]() {
ContainerScope scope(id);
JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
func->Execute();
PerfMonitor::GetPerfMonitor()->End(traceStreamPtr->str(), true, true);
};
} else {
onFinishEvent = [traceStreamPtr]() {
PerfMonitor::GetPerfMonitor()->End(traceStreamPtr->str(), true, true);
};
}
@ -331,8 +350,17 @@ void JSViewContext::JSAnimateTo(const JSCallbackInfo& info)
AnimationOption option =
CreateAnimation(animationArgs, ParseCallBackFunction(obj), pipelineContext->IsFormRender());
if (pipelineContext->IsFormAnimationFinishCallback() && pipelineContext->IsFormRender() &&
option.GetDuration() > (DEFAULT_DURATION - GetFormAnimationTimeInterval(pipelineContext))) {
*traceStreamPtr << "AnimateTo, Options"
<< ",animationId:" << animationId
<< ",duration:" << option.GetDuration()
<< ",iteration:" << option.GetIteration()
<< ",delay:" << option.GetDelay()
<< ",tempo:" << option.GetTempo()
<< ",direction:" << (uint32_t) option.GetAnimationDirection()
<< ",curve:" << (option.GetCurve() ? option.GetCurve()->ToString().c_str() : "");
PerfMonitor::GetPerfMonitor()->Start(traceStreamPtr->str(), PerfActionType::LAST_UP, "", false, true);
if (CheckIfSetFormAnimationDuration(pipelineContext, option)) {
option.SetDuration(DEFAULT_DURATION - GetFormAnimationTimeInterval(pipelineContext));
TAG_LOGW(AceLogTag::ACE_FORM, "[Form animation] Form animation SetDuration: %{public}lld ms",
static_cast<long long>(DEFAULT_DURATION - GetFormAnimationTimeInterval(pipelineContext)));

View File

@ -34,9 +34,10 @@ PerfMonitor* PerfMonitor::GetPerfMonitor()
return nullptr;
}
void PerfMonitor::Start(const std::string& sceneId, PerfActionType type, const std::string& note) {}
void PerfMonitor::Start(const std::string& sceneId, PerfActionType type, const std::string& note,
bool isReportInteractionEvent, bool isAnimationTrace) {}
void PerfMonitor::End(const std::string& sceneId, bool isJsApi) {}
void PerfMonitor::End(const std::string& sceneId, bool isJsApi, bool isAnimationTrace) {}
void PerfMonitor::SetPageUrl(const std::string& pageUrl) {}