fix code spec

Change-Id: Iaa8905b9444595fc9c21aaa8c046b4d63c7d81c5
Signed-off-by: b200200 <wangyonglang@huawei.com>
This commit is contained in:
b200200 2022-06-22 19:22:52 +08:00
parent 046086431d
commit f052d08e1b
10 changed files with 219 additions and 89 deletions

View File

@ -22,6 +22,13 @@ config("libframe_analyzer_config") {
"-Werror",
"-g3",
]
if (current_os != "ohos") {
cflags += [
"-Wno-c++17-extensions",
"-Wno-unused-private-field",
]
}
}
config("libframe_analyzer_public_config") {
@ -29,23 +36,31 @@ config("libframe_analyzer_public_config") {
}
ohos_shared_library("libframe_analyzer") {
sources = [
"src/frame_collector.cpp",
"src/frame_painter.cpp",
"src/frame_saver.cpp",
]
if (current_os == "ohos") {
sources = [
"src/frame_collector.cpp",
"src/frame_painter.cpp",
"src/frame_saver.cpp",
]
deps = [
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara",
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara_watchagent",
"//third_party/flutter/build/skia:ace_skia_ohos",
"//utils/native/base:utils",
]
} else {
sources = [
"src/mingw/frame_collector.cpp",
"src/mingw/frame_painter.cpp",
]
}
configs = [ ":libframe_analyzer_config" ]
public_configs = [ ":libframe_analyzer_public_config" ]
deps = [
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara",
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara_watchagent",
"//third_party/flutter/build/skia:ace_skia_ohos",
]
subsystem_name = "graphic"
part_name = "graphic_standard"
}

View File

@ -57,6 +57,7 @@ private:
static inline std::unique_ptr<FrameCollector> instance = nullptr;
FrameCollector();
bool ProcessUIMarkLocked(int32_t index, int64_t timeNs);
static void SwitchFunction(const char *key, const char *value, void *context);
// pending

View File

@ -16,12 +16,12 @@
#ifndef ROSEN_MODULE_FRAME_ANALYZER_EXPORT_FRAME_PAINTER_H
#define ROSEN_MODULE_FRAME_ANALYZER_EXPORT_FRAME_PAINTER_H
#include "frame_collector.h"
class SkCanvas;
namespace OHOS {
namespace Rosen {
class FrameCollector;
class FramePainter {
public:
FramePainter(FrameCollector &collector);

View File

@ -29,6 +29,11 @@ namespace OHOS {
namespace Rosen {
namespace {
constexpr ::OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001400, "FrameCollector" };
constexpr int32_t uimarksStart = static_cast<int32_t>(FrameEventType::UIMarksStart);
constexpr int32_t uimarksEnd = static_cast<int32_t>(FrameEventType::UIMarksEnd) - 1;
constexpr int32_t loopEnd = static_cast<int32_t>(FrameEventType::LoopEnd) - 1;
constexpr int32_t vsyncStart = static_cast<int32_t>(FrameEventType::WaitVsyncStart);
constexpr int32_t vsyncEnd = static_cast<int32_t>(FrameEventType::WaitVsyncEnd);
} // namespace
FrameCollector &FrameCollector::GetInstance()
@ -65,49 +70,61 @@ void FrameCollector::MarkFrameEvent(const FrameEventType &type, int64_t timeNs)
return;
}
constexpr int32_t uimarksStart = static_cast<int32_t>(FrameEventType::UIMarksStart);
constexpr int32_t uimarksEnd = static_cast<int32_t>(FrameEventType::UIMarksEnd) - 1;
constexpr int32_t loopEnd = static_cast<int32_t>(FrameEventType::LoopEnd) - 1;
constexpr int32_t vsyncMark = static_cast<int32_t>(FrameEventType::WaitVsyncEnd);
::OHOS::HiviewDFX::HiLog::Debug(LABEL,
"FrameCollector::MarkFrameEvent index(%{public}d) occur at %{public}" PRIi64,
static_cast<int32_t>(index), timeNs);
std::lock_guard lockPending(pendingMutex_);
std::lock_guard lockFrameQueue(frameQueueMutex_);
if (index <= uimarksEnd) {
pendingUIMarks_.times[index] = timeNs;
} else if (index < vsyncMark) {
pbefore_ = &frameQueue_.Push({});
if (ProcessUIMarkLocked(index, timeNs)) {
return;
}
if (index == vsyncStart) {
pbefore_ = &frameQueue_.Push(FrameInfo());
pbefore_->frameNumber = currentUIMarks_.frameNumber;
for (auto i = uimarksStart; i <= uimarksEnd; i++) {
pbefore_->times[i] = currentUIMarks_.times[i];
}
pbefore_->times[index] = timeNs;
} else {
if (haveAfterVsync_ == false) {
haveAfterVsync_ = true;
pafter_ = pbefore_;
if (haveAfterVsync_) {
pbefore_->skiped = true;
pbefore_->times[vsyncEnd] = pbefore_->times[vsyncStart];
}
return;
}
if (!haveAfterVsync_) {
haveAfterVsync_ = true;
pafter_ = pbefore_;
}
if (pafter_ != nullptr) {
pafter_->times[index] = timeNs;
}
if (index == uimarksEnd) {
currentUIMarks_ = pendingUIMarks_;
pendingUIMarks_.frameNumber = ++currentFrameNumber_;
::OHOS::HiviewDFX::HiLog::Info(LABEL, "currentUIMarks_");
}
if (index == vsyncMark - 1 && haveAfterVsync_) {
pbefore_->skiped = true;
pbefore_->times[vsyncMark + 1] = pbefore_->times[vsyncMark];
}
::OHOS::HiviewDFX::HiLog::Debug(LABEL,
"FrameCollector::MarkFrameEvent index(%{public}d) occur at %{public}" PRIi64,
static_cast<int32_t>(index), timeNs);
if (index == loopEnd) {
haveAfterVsync_ = false;
}
}
bool FrameCollector::ProcessUIMarkLocked(int32_t index, int64_t timeNs)
{
if (index < uimarksEnd) {
pendingUIMarks_.times[index] = timeNs;
return true;
}
if (index == uimarksEnd) {
pendingUIMarks_.times[index] = timeNs;
currentUIMarks_ = pendingUIMarks_;
pendingUIMarks_.frameNumber = ++currentFrameNumber_;
return true;
}
return false;
}
void FrameCollector::ClearEvents()
{
std::lock_guard lock(frameQueueMutex_);

View File

@ -27,6 +27,11 @@ namespace OHOS {
namespace Rosen {
namespace {
constexpr ::OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0xD001400, "FramePainter" };
constexpr size_t FrameEventTypeInterval = 2;
constexpr int32_t Frame60Ms = 1000 / 60;
constexpr int32_t Frame30Ms = 1000 / 30;
constexpr auto loopstart = static_cast<size_t>(FrameEventType::LoopStart);
constexpr auto loopend = static_cast<size_t>(FrameEventType::LoopEnd);
std::map<FrameEventType, SkColor> colorMap = {
{FrameEventType::UploadStart, 0x0000ffff}, // cyan
{FrameEventType::AnimateStart, 0x0000cc00}, // mid green
@ -60,12 +65,9 @@ void FramePainter::Draw(SkCanvas &canvas)
auto x = barWidth * (frameQueueMaxSize - 1);
auto fq = collector_.LockGetFrameQueue();
for (auto rit = fq.rbegin(); rit != fq.rend(); rit++) {
constexpr auto loopstart = static_cast<size_t>(FrameEventType::LoopStart);
constexpr auto loopend = static_cast<size_t>(FrameEventType::LoopEnd);
uint8_t alpha = SumHeight(*rit) >= 16.0 ? 0x7f : 0x3f;
auto y = height;
for (size_t i = loopstart; i < loopend; i += 2) {
for (size_t i = loopstart; i < loopend; i += FrameEventTypeInterval) {
if (auto it = colorMap.find(static_cast<FrameEventType>(i)); it != colorMap.end()) {
constexpr auto alphaOffset = 24;
paint.setColor(it->second | (alpha << alphaOffset));
@ -89,10 +91,16 @@ void FramePainter::Draw(SkCanvas &canvas)
}
collector_.UnlockFrameQueue();
auto frameOffset = 0.5 * heightPerMs;
auto frameLength = 1 * heightPerMs;
auto rect60 = SkRect::MakeXYWH(0, (frameTotalMs - Frame60Ms) * heightPerMs + frameOffset,
width, frameLength);
auto rect30 = SkRect::MakeXYWH(0, (frameTotalMs - Frame30Ms) * heightPerMs + frameOffset,
width, frameLength);
paint.setColor(0xbf00ff00);
canvas.drawRect(SkRect::MakeXYWH(0, (frameTotalMs - 16 + 0.5) * heightPerMs, width, heightPerMs), paint);
canvas.drawRect(rect60, paint);
paint.setColor(0xbfff0000);
canvas.drawRect(SkRect::MakeXYWH(0, (frameTotalMs - 32 + 0.5) * heightPerMs, width, heightPerMs), paint);
canvas.drawRect(rect30, paint);
}
double FramePainter::SumHeight(const struct FrameInfo &info)
@ -101,7 +109,7 @@ double FramePainter::SumHeight(const struct FrameInfo &info)
constexpr auto loopend = static_cast<size_t>(FrameEventType::LoopEnd);
auto sum = 0.0;
for (size_t i = loopstart; i < loopend; i += 2) {
for (size_t i = loopstart; i < loopend; i += FrameEventTypeInterval) {
if (colorMap.find(static_cast<FrameEventType>(i)) == colorMap.end()) {
continue;
}

View File

@ -44,7 +44,7 @@ FrameSaver::FrameSaver()
return;
}
if (isExist == false) {
if (!isExist) {
fs::create_directory(saveDirectory, ec);
if (ec) {
::OHOS::HiviewDFX::HiLog::Warn(LABEL,
@ -85,7 +85,7 @@ void FrameSaver::SaveFrameEvent(const FrameEventType &type, int64_t timeNs)
{FrameEventType::FlushEnd, "FlushEnd "},
};
if (ofs_.is_open() == false) {
if (!ofs_.is_open()) {
::OHOS::HiviewDFX::HiLog::Info(LABEL, "%{public}s %{public}" PRIi64, frameEventTypeStringMap[type], timeNs);
return;
}

View File

@ -0,0 +1,53 @@
/*
* 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 "frame_collector.h"
namespace OHOS {
namespace Rosen {
FrameCollector &FrameCollector::GetInstance()
{
if (instance == nullptr) {
static std::mutex mutex;
std::lock_guard<std::mutex> lock(mutex);
if (instance == nullptr) {
instance = std::unique_ptr<FrameCollector>(new FrameCollector());
}
}
return *instance;
}
void FrameCollector::MarkFrameEvent(const FrameEventType &type, int64_t timeNs)
{
}
bool FrameCollector::ProcessUIMarkLocked(int32_t index, int64_t timeNs)
{
return false;
}
void FrameCollector::ClearEvents()
{
}
FrameCollector::FrameCollector()
{
}
void FrameCollector::SwitchFunction(const char *key, const char *value, void *context)
{
}
} // namespace Rosen
} // namespace OHOS

View File

@ -0,0 +1,35 @@
/*
* 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 "frame_painter.h"
#include "frame_collector.h"
namespace OHOS {
namespace Rosen {
FramePainter::FramePainter(FrameCollector &collector) : collector_(collector)
{
}
void FramePainter::Draw(SkCanvas &canvas)
{
}
double FramePainter::SumHeight(const struct FrameInfo &info)
{
return 0;
}
} // namespace Rosen
} // namespace OHOS

View File

@ -107,53 +107,53 @@ HWTEST_F(FrameCollectorTest, MarkFrameEvent, Function | MediumTest | Level2)
}
PART("CaseDescription") {
STEP("1. check queue size 0") {
STEP_ASSERT_EQ(collector.LockGetFrameQueue().GetSize(), 0);
collector.UnlockFrameQueue();
}
STEP("1. check queue size 0") {
STEP_ASSERT_EQ(collector.LockGetFrameQueue().GetSize(), 0);
collector.UnlockFrameQueue();
}
STEP("2. mark UIMarks") {
collector.MarkFrameEvent(FrameEventType::UploadStart);
collector.MarkFrameEvent(FrameEventType::UploadEnd);
collector.MarkFrameEvent(FrameEventType::AnimateStart);
collector.MarkFrameEvent(FrameEventType::AnimateEnd);
collector.MarkFrameEvent(FrameEventType::LayoutStart);
collector.MarkFrameEvent(FrameEventType::LayoutEnd);
collector.MarkFrameEvent(FrameEventType::DrawStart);
collector.MarkFrameEvent(FrameEventType::DrawEnd);
}
STEP("2. mark UIMarks") {
collector.MarkFrameEvent(FrameEventType::UploadStart);
collector.MarkFrameEvent(FrameEventType::UploadEnd);
collector.MarkFrameEvent(FrameEventType::AnimateStart);
collector.MarkFrameEvent(FrameEventType::AnimateEnd);
collector.MarkFrameEvent(FrameEventType::LayoutStart);
collector.MarkFrameEvent(FrameEventType::LayoutEnd);
collector.MarkFrameEvent(FrameEventType::DrawStart);
collector.MarkFrameEvent(FrameEventType::DrawEnd);
}
STEP("3. check queue size 0") {
STEP_ASSERT_EQ(collector.LockGetFrameQueue().GetSize(), 0);
collector.UnlockFrameQueue();
}
STEP("3. check queue size 0") {
STEP_ASSERT_EQ(collector.LockGetFrameQueue().GetSize(), 0);
collector.UnlockFrameQueue();
}
STEP("4. mark WaitVsyncStart") {
collector.MarkFrameEvent(FrameEventType::WaitVsyncStart);
}
STEP("4. mark WaitVsyncStart") {
collector.MarkFrameEvent(FrameEventType::WaitVsyncStart);
}
STEP("5. check queue size 1") {
STEP_ASSERT_EQ(collector.LockGetFrameQueue().GetSize(), 1);
collector.UnlockFrameQueue();
}
STEP("5. check queue size 1") {
STEP_ASSERT_EQ(collector.LockGetFrameQueue().GetSize(), 1);
collector.UnlockFrameQueue();
}
STEP("6. mark WaitVsyncStart") {
collector.MarkFrameEvent(FrameEventType::WaitVsyncStart);
}
STEP("6. mark WaitVsyncStart") {
collector.MarkFrameEvent(FrameEventType::WaitVsyncStart);
}
STEP("7. check queue size 2") {
STEP_ASSERT_EQ(collector.LockGetFrameQueue().GetSize(), 2);
collector.UnlockFrameQueue();
}
STEP("7. check queue size 2") {
STEP_ASSERT_EQ(collector.LockGetFrameQueue().GetSize(), 2);
collector.UnlockFrameQueue();
}
STEP("8. clear events") {
collector.ClearEvents();
}
STEP("8. clear events") {
collector.ClearEvents();
}
STEP("9. check queue size 0") {
STEP_ASSERT_EQ(collector.LockGetFrameQueue().GetSize(), 0);
collector.UnlockFrameQueue();
}
STEP("9. check queue size 0") {
STEP_ASSERT_EQ(collector.LockGetFrameQueue().GetSize(), 0);
collector.UnlockFrameQueue();
}
}
}
} // namespace Rosen

View File

@ -19,5 +19,6 @@ config("test_header_config") {
group("test_header") {
public_configs = [ ":test_header_config" ]
public_deps = [ "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog" ]
public_deps =
[ "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog" ]
}