mirror of
https://github.com/openharmony/ark_js_runtime.git
synced 2026-08-27 02:31:17 -04:00
09aaafead4
1、std::array copy construction has high performance overhead, 2、Class is transferred to dictionary after adding getter and setter, resulting in IC failure https://gitee.com/openharmony/ark_js_runtime/issues/I55EFB?from=project-issue 500000 getter: 170ms > 105ms Signed-off-by: yingguofeng@huawei.com <yingguofeng@huawei.com> Change-Id: Ia08f22df798a3c3a2f6fafb6401c802e3af3c63b
126 lines
4.5 KiB
C++
126 lines
4.5 KiB
C++
/*
|
|
* 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 <iomanip>
|
|
|
|
#include "ecmascript/ecma_macros.h"
|
|
#include "ecmascript/runtime_call_id.h"
|
|
|
|
namespace panda::ecmascript {
|
|
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
|
|
EcmaRuntimeStat::EcmaRuntimeStat(const char *const runtimeCallerNames[], int count)
|
|
{
|
|
for (int i = 0; i < count; i++) {
|
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
|
callerStat_.emplace_back(PandaRuntimeCallerStat(CString(runtimeCallerNames[i])));
|
|
}
|
|
}
|
|
|
|
void EcmaRuntimeStat::StartCount(PandaRuntimeTimer *timer, int callerId)
|
|
{
|
|
if (currentTimer_ != nullptr) {
|
|
timer->SetParent(currentTimer_);
|
|
}
|
|
PandaRuntimeTimer *parent = currentTimer_;
|
|
currentTimer_ = timer;
|
|
PandaRuntimeCallerStat *callerStat = &callerStat_[callerId];
|
|
timer->Start(callerStat, parent);
|
|
}
|
|
|
|
void EcmaRuntimeStat::StopCount(const PandaRuntimeTimer *nowTimer)
|
|
{
|
|
if (nowTimer != currentTimer_) {
|
|
return;
|
|
}
|
|
PandaRuntimeTimer *parentTimer = currentTimer_->Stop();
|
|
currentTimer_ = parentTimer;
|
|
}
|
|
|
|
void EcmaRuntimeStat::Print() const
|
|
{
|
|
if (currentTimer_ != nullptr) {
|
|
currentTimer_->Snapshot();
|
|
}
|
|
PrintAllStats();
|
|
}
|
|
|
|
void EcmaRuntimeStat::ResetAllCount()
|
|
{
|
|
while (currentTimer_ != nullptr) {
|
|
StopCount(currentTimer_);
|
|
}
|
|
for (auto &runCallerStat : callerStat_) {
|
|
runCallerStat.Reset();
|
|
}
|
|
}
|
|
|
|
void EcmaRuntimeStat::PrintAllStats() const
|
|
{
|
|
LOG(INFO, RUNTIME) << "panda runtime stat:";
|
|
static constexpr int nameRightAdjustment = 45;
|
|
static constexpr int numberRightAdjustment = 12;
|
|
LOG(INFO, RUNTIME) << std::right << std::setw(nameRightAdjustment) << "InterPreter && GC && C++ Builtin Function"
|
|
<< std::setw(numberRightAdjustment) << "Time(ns)" << std::setw(numberRightAdjustment) << "Count"
|
|
<< std::setw(numberRightAdjustment) << "MaxTime(ns)"
|
|
<< std::setw(numberRightAdjustment) << "AvgTime(ns)";
|
|
LOG(INFO, RUNTIME) << "============================================================"
|
|
<< "=========================================================";
|
|
|
|
CVector<PandaRuntimeCallerStat> callerStat;
|
|
for (auto &runCallerStat : callerStat_) {
|
|
callerStat.push_back(runCallerStat);
|
|
}
|
|
// Sort by TotalTime
|
|
std::sort(callerStat.begin(), callerStat.end(),
|
|
[](const PandaRuntimeCallerStat &a, const PandaRuntimeCallerStat &b) -> bool {
|
|
return a.TotalTime() > b.TotalTime();
|
|
});
|
|
|
|
uint64_t totalTime = 0;
|
|
for (auto &runCallerStat : callerStat) {
|
|
if (runCallerStat.TotalCount() != 0) {
|
|
totalTime += runCallerStat.TotalTime();
|
|
LOG(INFO, RUNTIME) << std::right << std::setw(nameRightAdjustment) << runCallerStat.Name()
|
|
<< std::setw(numberRightAdjustment) << runCallerStat.TotalTime()
|
|
<< std::setw(numberRightAdjustment) << runCallerStat.TotalCount()
|
|
<< std::setw(numberRightAdjustment) << runCallerStat.MaxTime()
|
|
<< std::setw(numberRightAdjustment)
|
|
<< runCallerStat.TotalTime() / runCallerStat.TotalCount();
|
|
}
|
|
}
|
|
LOG(INFO, RUNTIME) << "------------------------------------------------------------"
|
|
<< "---------------------------------------------------------";
|
|
LOG(INFO, RUNTIME) << std::right << std::setw(nameRightAdjustment) << "Total Time(ns)"
|
|
<< std::setw(numberRightAdjustment) << totalTime;
|
|
}
|
|
|
|
EcmaRuntimeStatScope::EcmaRuntimeStatScope(EcmaVM *vm) : vm_(vm)
|
|
{
|
|
JSRuntimeOptions options = vm_->GetJSOptions();
|
|
if (options.IsEnableRuntimeStat()) {
|
|
vm_->SetRuntimeStatEnable(true);
|
|
}
|
|
}
|
|
|
|
EcmaRuntimeStatScope::~EcmaRuntimeStatScope()
|
|
{
|
|
JSRuntimeOptions options = vm_->GetJSOptions();
|
|
if (options.IsEnableRuntimeStat()) {
|
|
vm_->SetRuntimeStatEnable(false);
|
|
}
|
|
vm_ = nullptr;
|
|
}
|
|
} // namespace panda::ecmascript
|