!14456 RSProfiler: Add rs_profiler_command files [Podlesny Viktor]

Merge pull request !14456 from Korobkov Dmitry/rsprofiler_add_command_file
This commit is contained in:
openharmony_ci 2024-09-19 14:53:39 +00:00 committed by Gitee
commit 4cceea8162
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
11 changed files with 292 additions and 193 deletions

View File

@ -245,6 +245,7 @@ ohos_shared_library("librender_service") {
"$rosen_root/modules/render_service_profiler/rs_profiler_beta_recorder.cpp",
"$rosen_root/modules/render_service_profiler/rs_profiler_capture_recorder.cpp",
"$rosen_root/modules/render_service_profiler/rs_profiler_capturedata.cpp",
"$rosen_root/modules/render_service_profiler/rs_profiler_command.cpp",
"$rosen_root/modules/render_service_profiler/rs_profiler_file.cpp",
"$rosen_root/modules/render_service_profiler/rs_profiler_network.cpp",
"$rosen_root/modules/render_service_profiler/rs_profiler_packet.cpp",

View File

@ -24,6 +24,7 @@
#include "rs_profiler_cache.h"
#include "rs_profiler_capture_recorder.h"
#include "rs_profiler_capturedata.h"
#include "rs_profiler_command.h"
#include "rs_profiler_file.h"
#include "rs_profiler_json.h"
#include "rs_profiler_log.h"
@ -31,7 +32,6 @@
#include "rs_profiler_packet.h"
#include "rs_profiler_settings.h"
#include "rs_profiler_telemetry.h"
#include "rs_profiler_utils.h"
#include "params/rs_display_render_params.h"
#include "pipeline/rs_main_thread.h"
@ -1813,60 +1813,6 @@ void RSProfiler::PlaybackResume(const ArgList& args)
Respond("OK");
}
RSProfiler::Command RSProfiler::GetCommand(const std::string& command)
{
static const std::map<std::string, Command> COMMANDS = {
{ "rstree_contains", DumpTree },
{ "rstree_fix", PatchNode },
{ "rstree_kill_node", KillNode },
{ "rstree_setparent", AttachChild },
{ "rstree_getroot", GetRoot },
{ "rstree_node_mod", DumpNodeModifiers },
{ "rstree_node_prop", DumpNodeProperties },
{ "rstree_pid", DumpSurfaces },
{ "rstree_kill_pid", KillPid },
{ "rstree_prepare_replay", PlaybackPrepare },
{ "rstree_save_frame", TestSaveFrame },
{ "rstree_load_frame", TestLoadFrame },
{ "rstree_switch", TestSwitch },
{ "rstree_dump_json", DumpTreeToJson },
{ "rsrecord_start", RecordStart },
{ "rsrecord_stop", RecordStop },
{ "rsrecord_replay_prepare", PlaybackPrepareFirstFrame },
{ "rsrecord_replay", PlaybackStart },
{ "rsrecord_replay_stop", PlaybackStop },
{ "rsrecord_pause_now", PlaybackPause },
{ "rsrecord_pause_at", PlaybackPauseAt },
{ "rsrecord_pause_resume", PlaybackResume },
{ "rsrecord_pause_clear", PlaybackPauseClear },
{ "rsrecord_sendbinary", RecordSendBinary },
{ "rssurface_pid", DumpNodeSurface },
{ "rscon_print", DumpConnections },
{ "save_rdc", SaveRdc },
{ "save_skp", SaveSkp },
{ "info", GetDeviceInfo },
{ "freq", GetDeviceFrequency },
{ "fixenv", FixDeviceEnv },
{ "set", SetSystemParameter },
{ "get", GetSystemParameter },
{ "params", DumpSystemParameters },
{ "get_perf_tree", GetPerfTree },
{ "calc_perf_node", CalcPerfNode },
{ "calc_perf_node_all", CalcPerfNodeAll },
{ "socket_shutdown", SocketShutdown },
{ "version", Version },
{ "file_version", FileVersion },
{ "reset", Reset },
};
if (command.empty()) {
return nullptr;
}
const auto delegate = COMMANDS.find(command);
return (delegate != COMMANDS.end()) ? delegate->second : nullptr;
}
void RSProfiler::ProcessCommands()
{
if (g_playbackWaitFrames > 0) {
@ -1876,18 +1822,9 @@ void RSProfiler::ProcessCommands()
return;
}
std::vector<std::string> commandData;
if (!Network::PopCommand(commandData)) {
return;
}
const std::string& command = commandData[0];
if (const Command delegate = GetCommand(command)) {
const ArgList args =
(commandData.size() > 1) ? ArgList({ commandData.begin() + 1, commandData.end() }) : ArgList();
delegate(args);
} else if (!command.empty()) {
Respond("Command has not been found: " + command);
std::vector<std::string> line;
if (Network::PopCommand(line)) {
Invoke(line);
}
}

View File

@ -333,8 +333,7 @@ private:
static void TypefaceUnmarshalling(std::stringstream& stream, uint32_t fileVersion);
// Network interface
using Command = void (*)(const ArgList&);
static Command GetCommand(const std::string& command);
static void Invoke(const std::vector<std::string>& line);
static void ProcessPauseMessage();
static void ProcessCommands();
static void Respond(const std::string& message);
@ -393,6 +392,9 @@ private:
static void OnWorkModeChanged();
static void ProcessSignalFlag();
private:
using CommandRegistry = std::map<std::string, void (*)(const ArgList&)>;
static const CommandRegistry COMMANDS;
// set to true in DT only
RSB_EXPORT static bool testing_;

View File

@ -17,11 +17,11 @@
#include "rs_profiler.h"
#include "rs_profiler_archive.h"
#include "rs_profiler_command.h"
#include "rs_profiler_file.h"
#include "rs_profiler_network.h"
#include "rs_profiler_packet.h"
#include "rs_profiler_telemetry.h"
#include "rs_profiler_utils.h"
namespace OHOS::Rosen {
@ -149,13 +149,9 @@ bool RSProfiler::IsBetaRecordStarted()
void RSProfiler::SaveBetaRecord()
{
if (!IsBetaRecordSavingTriggered()) {
return;
}
constexpr double recordMaxLengthSeconds = 30.0;
const auto recordLength = Now() - g_recordsTimestamp;
if (recordLength > recordMaxLengthSeconds) {
if (!IsBetaRecordSavingTriggered() && (recordLength <= recordMaxLengthSeconds)) {
return;
}

View File

@ -0,0 +1,81 @@
/*
* Copyright (c) 2024 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 "rs_profiler.h"
#include "rs_profiler_command.h"
namespace OHOS::Rosen {
const RSProfiler::CommandRegistry RSProfiler::COMMANDS = {
{ "rstree_contains", DumpTree },
{ "rstree_fix", PatchNode },
{ "rstree_kill_node", KillNode },
{ "rstree_setparent", AttachChild },
{ "rstree_getroot", GetRoot },
{ "rstree_node_mod", DumpNodeModifiers },
{ "rstree_node_prop", DumpNodeProperties },
{ "rstree_pid", DumpSurfaces },
{ "rstree_kill_pid", KillPid },
{ "rstree_prepare_replay", PlaybackPrepare },
{ "rstree_save_frame", TestSaveFrame },
{ "rstree_load_frame", TestLoadFrame },
{ "rstree_switch", TestSwitch },
{ "rstree_dump_json", DumpTreeToJson },
{ "rsrecord_start", RecordStart },
{ "rsrecord_stop", RecordStop },
{ "rsrecord_replay_prepare", PlaybackPrepareFirstFrame },
{ "rsrecord_replay", PlaybackStart },
{ "rsrecord_replay_stop", PlaybackStop },
{ "rsrecord_pause_now", PlaybackPause },
{ "rsrecord_pause_at", PlaybackPauseAt },
{ "rsrecord_pause_resume", PlaybackResume },
{ "rsrecord_pause_clear", PlaybackPauseClear },
{ "rsrecord_sendbinary", RecordSendBinary },
{ "rssurface_pid", DumpNodeSurface },
{ "rscon_print", DumpConnections },
{ "save_rdc", SaveRdc },
{ "save_skp", SaveSkp },
{ "info", GetDeviceInfo },
{ "freq", GetDeviceFrequency },
{ "fixenv", FixDeviceEnv },
{ "set", SetSystemParameter },
{ "get", GetSystemParameter },
{ "params", DumpSystemParameters },
{ "get_perf_tree", GetPerfTree },
{ "calc_perf_node", CalcPerfNode },
{ "calc_perf_node_all", CalcPerfNodeAll },
{ "socket_shutdown", SocketShutdown },
{ "version", Version },
{ "file_version", FileVersion },
{ "reset", Reset },
};
void RSProfiler::Invoke(const std::vector<std::string>& line)
{
if (line.empty() || line[0].empty()) {
return;
}
const auto delegate = COMMANDS.find(line[0]);
if (delegate == COMMANDS.end()) {
Respond("Command has not been found: " + line[0]);
return;
}
const ArgList args = (line.size() > 1) ? ArgList({ line.begin() + 1, line.end() }) : ArgList();
delegate->second(args);
}
} // namespace OHOS::Rosen

View File

@ -0,0 +1,115 @@
/*
* Copyright (c) 2024 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 RS_PROFILER_COMMAND_H
#define RS_PROFILER_COMMAND_H
#include "rs_profiler_utils.h"
namespace OHOS::Rosen {
class ArgList final {
public:
explicit ArgList() = default;
explicit ArgList(std::vector<std::string> args) : args_(std::move(args)) {}
size_t Count() const
{
return args_.size();
}
bool Empty() const
{
return args_.empty();
}
void Clear()
{
args_.clear();
}
const std::string& String(size_t index = 0u) const
{
static const std::string EMPTY;
return index < Count() ? args_[index] : EMPTY;
}
int8_t Int8(size_t index = 0u) const
{
return Utils::ToInt8(String(index));
}
int16_t Int16(size_t index = 0u) const
{
return Utils::ToInt16(String(index));
}
int32_t Int32(size_t index = 0u) const
{
return Utils::ToInt32(String(index));
}
int64_t Int64(size_t index = 0u) const
{
return Utils::ToInt64(String(index));
}
uint8_t Uint8(size_t index = 0u) const
{
return Utils::ToUint8(String(index));
}
uint16_t Uint16(size_t index = 0u) const
{
return Utils::ToUint16(String(index));
}
uint32_t Uint32(size_t index = 0u) const
{
return Utils::ToUint32(String(index));
}
uint64_t Uint64(size_t index = 0u) const
{
return Utils::ToUint64(String(index));
}
float Fp32(size_t index = 0u) const
{
return Utils::ToFp32(String(index));
}
double Fp64(size_t index = 0u) const
{
return Utils::ToFp64(String(index));
}
pid_t Pid(size_t index = 0u) const
{
return static_cast<pid_t>(Uint32(index));
}
uint64_t Node(size_t index = 0u) const
{
return Uint64(index);
}
protected:
std::vector<std::string> args_;
};
} // namespace OHOS::Rosen
#endif // RS_PROFILER_COMMAND_H

View File

@ -450,12 +450,14 @@ FILE* Utils::FileOpen(const std::string& path, const std::string& options)
return nullptr;
}
#ifndef RENDER_PROFILER_APPLICATION
if (ShouldFileBeCreated(options) && !FileExists(realPath)) {
auto file = open(realPath.data(), O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
if (file != -1) {
close(file);
}
}
#endif
auto file = fopen(realPath.data(), options.data());
if (!IsFileValid(file)) {

View File

@ -194,97 +194,6 @@ public:
}
};
// ArgList
class ArgList final {
public:
explicit ArgList() = default;
explicit ArgList(std::vector<std::string> args) : args_(std::move(args)) {}
size_t Count() const
{
return args_.size();
}
bool Empty() const
{
return args_.empty();
}
void Clear()
{
args_.clear();
}
const std::string& String(size_t index = 0u) const
{
static const std::string EMPTY;
return index < Count() ? args_[index] : EMPTY;
}
int8_t Int8(size_t index = 0u) const
{
return Utils::ToInt8(String(index));
}
int16_t Int16(size_t index = 0u) const
{
return Utils::ToInt16(String(index));
}
int32_t Int32(size_t index = 0u) const
{
return Utils::ToInt32(String(index));
}
int64_t Int64(size_t index = 0u) const
{
return Utils::ToInt64(String(index));
}
uint8_t Uint8(size_t index = 0u) const
{
return Utils::ToUint8(String(index));
}
uint16_t Uint16(size_t index = 0u) const
{
return Utils::ToUint16(String(index));
}
uint32_t Uint32(size_t index = 0u) const
{
return Utils::ToUint32(String(index));
}
uint64_t Uint64(size_t index = 0u) const
{
return Utils::ToUint64(String(index));
}
float Fp32(size_t index = 0u) const
{
return Utils::ToFp32(String(index));
}
double Fp64(size_t index = 0u) const
{
return Utils::ToFp64(String(index));
}
pid_t Pid(size_t index = 0u) const
{
return Uint32(index);
}
uint64_t Node(size_t index = 0u) const
{
return Uint64(index);
}
protected:
std::vector<std::string> args_;
};
} // namespace OHOS::Rosen
#endif // RS_PROFILER_UTILS_H

View File

@ -236,3 +236,28 @@ ohos_unittest("RSProfilerUtilsTest") {
subsystem_name = "graphic"
}
############################## RSProfilerCommandTest ##################################
ohos_unittest("RSProfilerCommandTest") {
module_out_path = module_output_path
sources = [ "rs_profiler_command_test.cpp" ]
configs = [
":render_test",
"$graphic_2d_root/rosen/modules/render_service_base:export_config",
]
deps = [
"$graphic_2d_root/rosen/modules/render_service:librender_service",
"$graphic_2d_root/rosen/modules/render_service_base:librender_service_base",
"//third_party/googletest:gtest_main",
]
external_deps = [
"c_utils:utils",
"init:libbegetutil",
]
subsystem_name = "graphic"
}

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2024 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 <fcntl.h>
#include "gtest/gtest.h"
#include "rs_profiler_command.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS::Rosen {
class RSProfilerCommandTest : public testing::Test {
public:
static void SetUpTestCase() {};
static void TearDownTestCase() {};
void SetUp() override {};
void TearDown() override {};
};
/*
* @tc.name: CommandArgListTest
* @tc.desc: RSProfiler Command ArgList public API Test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(RSProfilerCommandTest, CommandArgListTest, testing::ext::TestSize.Level1)
{
std::vector<std::string> args { "123", "-5", "45738957893", "837983", "1.5", "678.789", "qwe" };
ArgList list { args };
EXPECT_EQ(list.Uint32(0), 123);
EXPECT_EQ(list.Int32(1), -5);
EXPECT_EQ(list.Uint64(2), 45738957893);
EXPECT_EQ(list.Int64(3), 837983);
EXPECT_EQ(list.Fp32(4), 1.5f);
EXPECT_EQ(list.Fp64(5), 678.789);
EXPECT_EQ(list.String(6), "qwe");
EXPECT_EQ(list.Count(), 7);
EXPECT_TRUE(list.String(7).empty());
EXPECT_TRUE(list.String(100).empty());
EXPECT_FALSE(list.Empty());
list.Clear();
EXPECT_TRUE(list.Empty());
}

View File

@ -124,33 +124,6 @@ HWTEST_F(RSProfilerUtilsTest, UtilsSplitTest, testing::ext::TestSize.Level1)
EXPECT_EQ(Utils::Split(str), result);
}
/*
* @tc.name: UtilsArgListTest
* @tc.desc: RSProfiler Utils ArgList public API Test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(RSProfilerUtilsTest, UtilsArgListTest, testing::ext::TestSize.Level1)
{
std::vector<std::string> args { "123", "-5", "45738957893", "837983", "1.5", "678.789", "qwe" };
ArgList list { args };
EXPECT_EQ(list.Uint32(0), 123);
EXPECT_EQ(list.Int32(1), -5);
EXPECT_EQ(list.Uint64(2), 45738957893);
EXPECT_EQ(list.Int64(3), 837983);
EXPECT_EQ(list.Fp32(4), 1.5f);
EXPECT_EQ(list.Fp64(5), 678.789);
EXPECT_EQ(list.String(6), "qwe");
EXPECT_EQ(list.Count(), 7);
EXPECT_TRUE(list.String(7).empty());
EXPECT_TRUE(list.String(100).empty());
EXPECT_FALSE(list.Empty());
list.Clear();
EXPECT_TRUE(list.Empty());
}
/*
* @tc.name: UtilsIdRoutineTest
* @tc.desc: RSProfiler Utils identifiers combining routine Test