mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 08:03:29 +00:00
commit
818975670e
16
BUILD.gn
16
BUILD.gn
@ -514,6 +514,11 @@ if (!is_mingw && !is_mac) {
|
||||
ecma_source += [ "ecmascript/tooling/interface/file_stream.cpp" ]
|
||||
}
|
||||
|
||||
hitrace_scope_source = []
|
||||
if (is_ohos && is_standard_system && enable_hitrace) {
|
||||
hitrace_scope_source += [ "ecmascript/jobs/hitrace_scope.cpp" ]
|
||||
}
|
||||
|
||||
ecma_debugger_source = []
|
||||
if (!is_mingw && !is_mac) {
|
||||
ecma_debugger_source += [
|
||||
@ -545,6 +550,7 @@ source_set("libark_jsruntime_set") {
|
||||
sources = ecma_source
|
||||
sources += ecma_profiler_source
|
||||
sources += ecma_debugger_source
|
||||
sources += hitrace_scope_source
|
||||
|
||||
public_configs = [
|
||||
"$js_root:ark_jsruntime_common_config",
|
||||
@ -579,6 +585,11 @@ source_set("libark_jsruntime_set") {
|
||||
include_dirs += [ "//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter" ]
|
||||
cflags_cc += [ "-Wno-gnu-zero-variadic-macro-arguments" ]
|
||||
}
|
||||
if (enable_hitrace) {
|
||||
defines += [ "ENABLE_HITRACE" ]
|
||||
include_dirs +=
|
||||
[ "//base/hiviewdfx/hitrace/interfaces/native/innerkits/include" ]
|
||||
}
|
||||
if (enable_dump_in_faultlog) {
|
||||
defines += [ "ENABLE_DUMP_IN_FAULTLOG" ]
|
||||
include_dirs += [ "//base/hiviewdfx/faultloggerd/interfaces/innerkits/faultloggerd_client" ]
|
||||
@ -649,7 +660,7 @@ ohos_shared_library("libark_jsruntime") {
|
||||
}
|
||||
|
||||
if (is_ohos && is_standard_system) {
|
||||
if (enable_dump_in_faultlog || enable_bytrace) {
|
||||
if (enable_dump_in_faultlog || enable_bytrace || enable_hitrace) {
|
||||
external_deps = []
|
||||
}
|
||||
if (enable_dump_in_faultlog) {
|
||||
@ -658,6 +669,9 @@ ohos_shared_library("libark_jsruntime") {
|
||||
if (enable_bytrace) {
|
||||
external_deps += [ "hitrace_native:hitrace_meter" ]
|
||||
}
|
||||
if (enable_hitrace) {
|
||||
external_deps += [ "hitrace_native:libhitrace" ]
|
||||
}
|
||||
}
|
||||
|
||||
install_enable = true
|
||||
|
@ -2363,8 +2363,20 @@ void PendingJob::Dump(std::ostream &os) const
|
||||
{
|
||||
os << " - job: ";
|
||||
GetJob().Dump(os);
|
||||
os << "\n";
|
||||
os << " - arguments: ";
|
||||
GetArguments().Dump(os);
|
||||
#if defined(ENABLE_HITRACE)
|
||||
os << "\n";
|
||||
os << " - chainId: " << GetChainId();
|
||||
os << "\n";
|
||||
os << " - spanId: " << GetSpanId();
|
||||
os << "\n";
|
||||
os << " - parentSpanId: " << GetParentSpanId();
|
||||
os << "\n";
|
||||
os << " - flags: " << GetFlags();
|
||||
os << "\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
void CompletionRecord::Dump(std::ostream &os) const
|
||||
@ -4394,6 +4406,12 @@ void PendingJob::DumpForSnapshot(std::vector<std::pair<CString, JSTaggedValue>>
|
||||
{
|
||||
vec.push_back(std::make_pair(CString("job"), GetJob()));
|
||||
vec.push_back(std::make_pair(CString("arguments"), GetArguments()));
|
||||
#if defined(ENABLE_HITRACE)
|
||||
vec.push_back(std::make_pair(CString("chainId"), JSTaggedValue(GetChainId())));
|
||||
vec.push_back(std::make_pair(CString("spanId"), JSTaggedValue(GetChainId())));
|
||||
vec.push_back(std::make_pair(CString("parentSpanId"), JSTaggedValue(GetChainId())));
|
||||
vec.push_back(std::make_pair(CString("flags"), JSTaggedValue(GetChainId())));
|
||||
#endif
|
||||
}
|
||||
|
||||
void CompletionRecord::DumpForSnapshot(std::vector<std::pair<CString, JSTaggedValue>> &vec) const
|
||||
|
@ -42,6 +42,14 @@
|
||||
#define ECMA_BYTRACE_NAME(tag, name) HITRACE_METER_NAME(tag, name); trace::ScopedTrace scopedTrace(name)
|
||||
#endif
|
||||
|
||||
#if defined(ENABLE_HITRACE)
|
||||
#define ENQUEUE_JOB_HITRACE(pendingJob, queueType) job::EnqueueJobScope hitraceScope(pendingJob, queueType)
|
||||
#define EXECUTE_JOB_HITRACE(pendingJob) job::ExecuteJobScope hitraceScope(pendingJob)
|
||||
#else
|
||||
#define ENQUEUE_JOB_HITRACE(pendingJob, queueType)
|
||||
#define EXECUTE_JOB_HITRACE(pendingJob)
|
||||
#endif
|
||||
|
||||
/* Note: We can't statically decide the element type is a primitive or heap object, especially for */
|
||||
/* dynamically-typed languages like JavaScript. So we simply skip the read-barrier. */
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
||||
|
87
ecmascript/jobs/hitrace_scope.cpp
Normal file
87
ecmascript/jobs/hitrace_scope.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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 "ecmascript/jobs/hitrace_scope.h"
|
||||
|
||||
#include "ecmascript/jobs/pending_job.h"
|
||||
#include "hitrace/hitrace.h"
|
||||
|
||||
namespace panda::ecmascript::job {
|
||||
EnqueueJobScope::EnqueueJobScope(const JSHandle<PendingJob> &pendingJob, QueueType queueType)
|
||||
{
|
||||
HiTraceId id = HiTrace::GetId();
|
||||
if (id.IsValid() && id.IsFlagEnabled(HITRACE_FLAG_INCLUDE_ASYNC)) {
|
||||
HiTraceId childId = HiTrace::CreateSpan();
|
||||
|
||||
pendingJob->SetChainId(childId.GetChainId());
|
||||
pendingJob->SetSpanId(childId.GetSpanId());
|
||||
pendingJob->SetParentSpanId(childId.GetParentSpanId());
|
||||
pendingJob->SetFlags(childId.GetFlags());
|
||||
|
||||
if (id.IsFlagEnabled(HITRACE_FLAG_TP_INFO)) {
|
||||
if (queueType == QueueType::QUEUE_PROMISE) {
|
||||
HiTrace::Tracepoint(HITRACE_CM_THREAD, HITRACE_TP_CS,
|
||||
childId, "Queue type:%s", "Promise queue");
|
||||
} else if (queueType == QueueType::QUEUE_SCRIPT) {
|
||||
HiTrace::Tracepoint(HITRACE_CM_THREAD, HITRACE_TP_CS,
|
||||
childId, "Queue type:%s", "Script queue");
|
||||
} else {
|
||||
HiTrace::Tracepoint(HITRACE_CM_THREAD, HITRACE_TP_CS,
|
||||
childId, "Queue type:%s", "Other queue");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EnqueueJobScope::~EnqueueJobScope()
|
||||
{
|
||||
}
|
||||
|
||||
ExecuteJobScope::ExecuteJobScope(const JSHandle<PendingJob> &pendingJob)
|
||||
{
|
||||
saveId_ = HiTrace::GetId();
|
||||
if (saveId_.IsValid()) {
|
||||
HiTrace::ClearId();
|
||||
}
|
||||
if (pendingJob->GetChainId() != 0) {
|
||||
hitraceId_.SetChainId(pendingJob->GetChainId());
|
||||
hitraceId_.SetSpanId(pendingJob->GetSpanId());
|
||||
hitraceId_.SetParentSpanId(pendingJob->GetParentSpanId());
|
||||
hitraceId_.SetFlags(pendingJob->GetFlags());
|
||||
|
||||
if (hitraceId_.IsValid()) {
|
||||
HiTrace::SetId(hitraceId_);
|
||||
if (hitraceId_.IsFlagEnabled(HITRACE_FLAG_TP_INFO)) {
|
||||
HiTrace::Tracepoint(HITRACE_CM_THREAD, HITRACE_TP_SR,
|
||||
hitraceId_, "Before %s pending job execute", "Promise");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ExecuteJobScope::~ExecuteJobScope()
|
||||
{
|
||||
if (hitraceId_.IsValid()) {
|
||||
if (hitraceId_.IsFlagEnabled(HITRACE_FLAG_TP_INFO)) {
|
||||
HiTrace::Tracepoint(HITRACE_CM_THREAD, HITRACE_TP_SS,
|
||||
hitraceId_, "After %s pending job execute", "Promise");
|
||||
}
|
||||
HiTrace::ClearId();
|
||||
}
|
||||
if (saveId_.IsValid()) {
|
||||
HiTrace::SetId(saveId_);
|
||||
}
|
||||
}
|
||||
} // namespace panda::ecmascript::job
|
49
ecmascript/jobs/hitrace_scope.h
Normal file
49
ecmascript/jobs/hitrace_scope.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 ECMASCRIPT_JOBS_HIREACE_SCOPE_H
|
||||
#define ECMASCRIPT_JOBS_HIREACE_SCOPE_H
|
||||
|
||||
#include "ecmascript/jobs/micro_job_queue.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
#if defined(ENABLE_HITRACE)
|
||||
#include "hitrace/hitraceid.h"
|
||||
#endif
|
||||
|
||||
namespace panda::ecmascript::job {
|
||||
#if defined(ENABLE_HITRACE)
|
||||
using namespace OHOS::HiviewDFX;
|
||||
#endif
|
||||
class PendingJob;
|
||||
class EnqueueJobScope {
|
||||
public:
|
||||
explicit EnqueueJobScope(const JSHandle<PendingJob> &pendingJob, job::QueueType queueType);
|
||||
|
||||
~EnqueueJobScope();
|
||||
};
|
||||
|
||||
class ExecuteJobScope {
|
||||
public:
|
||||
explicit ExecuteJobScope(const JSHandle<PendingJob> &pendingJob);
|
||||
|
||||
~ExecuteJobScope();
|
||||
private:
|
||||
#if defined(ENABLE_HITRACE)
|
||||
HiTraceId saveId_;
|
||||
HiTraceId hitraceId_;
|
||||
#endif
|
||||
};
|
||||
} // namespace panda::ecmascript::job
|
||||
#endif // ECMASCRIPT_JOBS_HIREACE_SCOPE_H
|
@ -16,6 +16,7 @@
|
||||
#include "ecmascript/jobs/micro_job_queue.h"
|
||||
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/jobs/hitrace_scope.h"
|
||||
#include "ecmascript/jobs/pending_job.h"
|
||||
#include "ecmascript/js_arguments.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
@ -38,6 +39,7 @@ void MicroJobQueue::EnqueueJob(JSThread *thread, JSHandle<MicroJobQueue> jobQueu
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
[[maybe_unused]] EcmaHandleScope handleScope(thread);
|
||||
JSHandle<PendingJob> pendingJob(factory->NewPendingJob(job, argv));
|
||||
ENQUEUE_JOB_HITRACE(pendingJob, queueType);
|
||||
if (queueType == QueueType::QUEUE_PROMISE) {
|
||||
JSHandle<TaggedQueue> promiseQueue(thread, jobQueue->GetPromiseJobQueue());
|
||||
LOG_ECMA(DEBUG) << "promiseQueue start length: " << promiseQueue->Size();
|
||||
|
@ -17,7 +17,6 @@
|
||||
#define ECMASCRIPT_JOBS_MICRO_JOB_QUEUE_H
|
||||
|
||||
#include "ecmascript/ecma_string.h"
|
||||
#include "ecmascript/jobs/pending_job.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
#include "ecmascript/js_thread.h"
|
||||
#include "ecmascript/mem/c_containers.h"
|
||||
|
@ -18,10 +18,11 @@
|
||||
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/jobs/hitrace_scope.h"
|
||||
#include "ecmascript/js_function.h"
|
||||
#include "ecmascript/record.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/record.h"
|
||||
#include "ecmascript/tagged_array.h"
|
||||
#include "ecmascript/tooling/interface/js_debugger_manager.h"
|
||||
#include "ecmascript/mem/c_containers.h"
|
||||
@ -37,6 +38,7 @@ public:
|
||||
|
||||
static JSTaggedValue ExecutePendingJob(const JSHandle<PendingJob> &pendingJob, JSThread *thread)
|
||||
{
|
||||
EXECUTE_JOB_HITRACE(pendingJob);
|
||||
tooling::JsDebuggerManager *jsDebuggerManager = thread->GetEcmaVM()->GetJsDebuggerManager();
|
||||
jsDebuggerManager->GetNotificationManager()->PendingJobEntryEvent();
|
||||
|
||||
@ -52,11 +54,22 @@ public:
|
||||
|
||||
static constexpr size_t JOB_OFFSET = Record::SIZE;
|
||||
ACCESSORS(Job, JOB_OFFSET, ARGUMENT_OFFSET);
|
||||
#if defined(ENABLE_HITRACE)
|
||||
ACCESSORS(Arguments, ARGUMENT_OFFSET, CHAINID_OFFSET);
|
||||
ACCESSORS_PRIMITIVE_FIELD(ChainId, uint64_t, CHAINID_OFFSET, SPANID_OFFSET)
|
||||
ACCESSORS_PRIMITIVE_FIELD(SpanId, uint64_t, SPANID_OFFSET, PARENTSPANID_OFFSET)
|
||||
ACCESSORS_PRIMITIVE_FIELD(ParentSpanId, uint64_t, PARENTSPANID_OFFSET, FLAGS_OFFSET)
|
||||
ACCESSORS_PRIMITIVE_FIELD(Flags, uint32_t, FLAGS_OFFSET, LAST_OFFSET)
|
||||
DEFINE_ALIGN_SIZE(LAST_OFFSET);
|
||||
|
||||
DECL_VISIT_OBJECT(JOB_OFFSET, CHAINID_OFFSET)
|
||||
#else
|
||||
ACCESSORS(Arguments, ARGUMENT_OFFSET, SIZE);
|
||||
|
||||
DECL_DUMP()
|
||||
|
||||
DECL_VISIT_OBJECT(JOB_OFFSET, SIZE)
|
||||
#endif
|
||||
|
||||
DECL_DUMP()
|
||||
};
|
||||
} // namespace panda::ecmascript::job
|
||||
#endif // ECMASCRIPT_JOBS_PENDING_JOB_H
|
||||
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "ecmascript/jobs/micro_job_queue.h"
|
||||
#include "ecmascript/jobs/pending_job.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/js_promise.h"
|
||||
#include "ecmascript/tagged_queue.h"
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "ecmascript/builtins/builtins_promise_handler.h"
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/jobs/micro_job_queue.h"
|
||||
#include "ecmascript/js_function.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
|
@ -1888,6 +1888,12 @@ JSHandle<job::PendingJob> ObjectFactory::NewPendingJob(const JSHandle<JSFunction
|
||||
JSHandle<job::PendingJob> obj(thread_, header);
|
||||
obj->SetJob(thread_, func.GetTaggedValue());
|
||||
obj->SetArguments(thread_, argv.GetTaggedValue());
|
||||
#if defined(ENABLE_HITRACE)
|
||||
obj->SetChainId(0);
|
||||
obj->SetSpanId(0);
|
||||
obj->SetParentSpanId(0);
|
||||
obj->SetFlags(0);
|
||||
#endif
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
@ -850,7 +850,11 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump)
|
||||
break;
|
||||
}
|
||||
case JSType::PENDING_JOB: {
|
||||
#if defined(ENABLE_HITRACE)
|
||||
CHECK_DUMP_FIELDS(Record::SIZE, ecmascript::job::PendingJob::SIZE, 6U)
|
||||
#else
|
||||
CHECK_DUMP_FIELDS(Record::SIZE, ecmascript::job::PendingJob::SIZE, 2U)
|
||||
#endif
|
||||
JSHandle<JSHClass> pendingClass(thread,
|
||||
JSHClass::Cast(globalConst->GetPendingJobClass().GetTaggedObject()));
|
||||
JSHandle<TaggedObject> pendingJob(thread, factory->NewDynObject(pendingClass));
|
||||
|
@ -98,7 +98,10 @@ ohos_shared_library("libark_ecma_debugger_test") {
|
||||
|
||||
if (is_ohos && is_standard_system) {
|
||||
if (build_public_version) {
|
||||
external_deps = [ "hitrace_native:hitrace_meter" ]
|
||||
external_deps = [
|
||||
"hitrace_native:hitrace_meter",
|
||||
"hitrace_native:libhitrace",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,10 @@ ohos_shared_library("jsdebugtest") {
|
||||
|
||||
if (is_ohos && is_standard_system) {
|
||||
if (build_public_version) {
|
||||
external_deps = [ "hitrace_native:hitrace_meter" ]
|
||||
external_deps = [
|
||||
"hitrace_native:hitrace_meter",
|
||||
"hitrace_native:libhitrace",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ third_party_gn_path = "//third_party"
|
||||
compile_llvm_online = false
|
||||
run_with_asan = false
|
||||
enable_bytrace = true
|
||||
enable_hitrace = true
|
||||
enable_dump_in_faultlog = true
|
||||
asan_lib_path = "/usr/lib/llvm-10/lib/clang/10.0.0/lib/linux"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user