This commit is contained in:
s30035957 2024-11-06 16:14:59 +08:00
commit a46c2a3ba2
28 changed files with 508 additions and 242 deletions

View File

@ -72,6 +72,7 @@ group("unittest") {
"plugins/hisysevent_plugin/test:unittest",
"plugins/memory_plugin/test:unittest",
"plugins/network_plugin/test:unittest",
"plugins/network_profiler/test:unittest",
"plugins/process_plugin/test:unittest",
"plugins/xpower_plugin/test:unittest",
"services/ipc/test:unittest",

View File

@ -368,6 +368,35 @@ public:
return cmdStr;
}
std::string CreateSplitNetworkProfilerCommand(const std::string &outFile, int time) const
{
std::string cmdStr =
"hiprofiler_cmd -s -k \\\n"
"-c - \\\n";
cmdStr += "-o " + outFile + " \\\n";
cmdStr += "-t " + std::to_string(time) + " \\\n"
"<<CONFIG\n"
"request_id: 1\n"
"session_config {\n"
" buffers {\n"
" pages: 16384\n"
" }\n"
" split_file: true\n"
"}\n"
"plugin_configs {\n"
" plugin_name: \"network-profiler\"\n"
" config_data {\n"
" clock_id: 1\n"
" smb_pages: 16384\n"
" startup_process_name: \"com.ohos.systemui\"\n"
" block: true\n"
" flush_interval: 5\n"
" }\n"
"}\n"
"CONFIG\n";
return cmdStr;
}
std::string CreateSplitHiperfCommand(const std::string &outFile, const std::string &perfFile,
const std::string &perfSplitFile, int time) const
{
@ -817,3 +846,27 @@ HWTEST_F(HiprofilerCmdTest, DFX_DFR_Hiprofiler_0230, Function | MediumTest | Lev
system(cmd.c_str());
#endif
}
/**
* @tc.name: hiprofiler_cmd
* @tc.desc: Test hiprofiler_cmd with split hiebpf file.
* @tc.type: FUNC
*/
HWTEST_F(HiprofilerCmdTest, DFX_DFR_Hiprofiler_0240, Function | MediumTest | Level1)
{
std::string outFileName = "split_htrace";
std::string outFile = DEFAULT_PATH + outFileName + ".htrace";
std::string content = "";
int time = 10;
std::string cmd = CreateSplitNetworkProfilerCommand(outFile, time);
EXPECT_TRUE(RunCommand(cmd, content));
EXPECT_NE(access(outFile.c_str(), F_OK), 0);
cmd = "ls " + DEFAULT_PATH + outFileName + "*_1.htrace";
EXPECT_TRUE(RunCommand(cmd, content));
EXPECT_STRNE(content.c_str(), "");
cmd = "rm " + DEFAULT_PATH + outFileName + "*.htrace";
system(cmd.c_str());
}

View File

@ -24,6 +24,7 @@ sources_base = [
"unittest/common/native/hook_manager_test.cpp",
"unittest/common/native/hook_service_test.cpp",
"unittest/common/native/register_test.cpp",
"unittest/common/native/stack_preprocess_test.cpp",
"unittest/common/native/symbols_file_test.cpp",
"unittest/common/native/utilities_test.cpp",
"unittest/common/native/virtual_thread_test.cpp",

View File

@ -0,0 +1,109 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
* 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 <gtest/gtest.h>
#include "stack_preprocess.h"
#include "native_hook_config.pb.h"
#include "plugin_module_api.h"
using namespace std;
using namespace testing::ext;
using namespace OHOS::Developtools::NativeDaemon;
namespace {
constexpr static uint32_t MAX_MATCH_INTERVAL = 3600;
constexpr static uint32_t MAX_MATCH_CNT = 1000;
}
class StackPreprocessTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void StackPreprocessTest::SetUpTestCase(void)
{
}
void StackPreprocessTest::TearDownTestCase(void)
{
}
void StackPreprocessTest::SetUp(void)
{
}
void StackPreprocessTest::TearDown(void)
{
}
long WriteFunc(WriterStruct* writer, const void* data, size_t size)
{
if (writer == nullptr || data == nullptr || size <= 0) {
return -1;
}
return 0;
}
bool FlushFunc(WriterStruct* writer)
{
if (writer == nullptr) {
return false;
}
return true;
}
/*
@tc.name: StackPreprocessTest001
@tc.desc: test StackPreprocess with overcceeding max matching interval.
@tc.type: FUNC
*/
HWTEST_F(StackPreprocessTest, StackPreprocessTest001, TestSize.Level1)
{
NativeHookConfig hookConfig;
hookConfig.set_malloc_free_matching_interval(MAX_MATCH_INTERVAL + 1);
StackPreprocess preprocess(nullptr, hookConfig, 0);
ASSERT_TRUE(preprocess.hookConfig_.malloc_free_matching_interval() == MAX_MATCH_INTERVAL);
}
/*
@tc.name: StackPreprocessTest002
@tc.desc: test StackPreprocess with overcceeding max matching cnt.
@tc.type: FUNC
*/
HWTEST_F(StackPreprocessTest, StackPreprocessTest002, TestSize.Level1)
{
NativeHookConfig hookConfig;
hookConfig.set_malloc_free_matching_cnt(MAX_MATCH_CNT + 1);
StackPreprocess preprocess(nullptr, hookConfig, 0);
ASSERT_TRUE(preprocess.hookConfig_.malloc_free_matching_cnt() == MAX_MATCH_CNT);
}
/*
@tc.name: StackPreprocessTest003
@tc.desc: test StackPreprocess with save_file set to true but no file pointer provided.
@tc.type: FUNC
*/
HWTEST_F(StackPreprocessTest, StackPreprocessTest003, TestSize.Level1)
{
NativeHookConfig hookConfig;
hookConfig.set_save_file(true);
FILE* fpHookData = nullptr;
StackPreprocess preprocess(nullptr, hookConfig, 0, fpHookData);
ASSERT_TRUE(hookConfig.save_file() && fpHookData == nullptr);
}

View File

@ -245,6 +245,7 @@ void* MallocHookStart(void* disableHookCallback)
COMMON::PrintMallinfoLog("before hook(byte) => ", g_miStart);
g_mallocTimes = 0;
g_hookClient.reset();
GetMainThreadRuntimeStackRange(g_filterStaLibRange);
if (g_hookClient != nullptr) {
return nullptr;
} else {
@ -271,7 +272,6 @@ bool ohos_malloc_hook_on_start(void (*disableHookCallback)())
pthread_setspecific(g_hookTid, nullptr);
pthread_key_create(&g_updateThreadNameCount, nullptr);
pthread_setspecific(g_updateThreadNameCount, reinterpret_cast<void *>(0));
GetMainThreadRuntimeStackRange(g_filterStaLibRange);
constexpr int paramBufferLen = 128;
char paramOutBuf[paramBufferLen] = {0};
int ret = GetParameter("persist.hiviewdfx.profiler.mem.filter", "", paramOutBuf, paramBufferLen);
@ -632,6 +632,11 @@ void* hook_calloc(void* (*fn)(size_t, size_t), size_t number, size_t size)
#endif
return pRet;
}
std::weak_ptr<HookSocketClient> weakClient = g_hookClient;
auto holder = weakClient.lock();
if (holder == nullptr) {
return pRet;
}
StackRawData rawdata = {{{{0}}}};
const char* stackptr = nullptr;
const char* stackendptr = nullptr;
@ -675,17 +680,13 @@ void* hook_calloc(void* (*fn)(size_t, size_t), size_t number, size_t size)
if (g_ClientConfig.sampleInterval >= THRESHOLD) {
Addr2Bitpool(pRet);
}
std::weak_ptr<HookSocketClient> weakClient = g_hookClient;
auto holder = weakClient.lock();
if (holder != nullptr) {
int realSize = 0;
if (g_ClientConfig.fpunwind) {
realSize = sizeof(BaseStackRawData) + (fpStackDepth * sizeof(uint64_t));
} else {
realSize = sizeof(BaseStackRawData) + sizeof(rawdata.regs);
}
holder->SendStackWithPayload(&rawdata, realSize, stackptr, stackSize);
int realSize = 0;
if (g_ClientConfig.fpunwind) {
realSize = sizeof(BaseStackRawData) + (fpStackDepth * sizeof(uint64_t));
} else {
realSize = sizeof(BaseStackRawData) + sizeof(rawdata.regs);
}
holder->SendStackWithPayload(&rawdata, realSize, stackptr, stackSize);
g_mallocTimes++;
#ifdef PERFORMANCE_DEBUG
struct timespec end = {};
@ -741,6 +742,11 @@ void* hook_realloc(void* (*fn)(void*, size_t), void* ptr, size_t size)
#endif
return pRet;
}
std::weak_ptr<HookSocketClient> weakClient = g_hookClient;
auto holder = weakClient.lock();
if (holder == nullptr) {
return pRet;
}
StackRawData rawdata = {{{{0}}}};
StackRawData freeData = {{{{0}}}};
const char* stackptr = nullptr;
@ -792,27 +798,23 @@ void* hook_realloc(void* (*fn)(void*, size_t), void* ptr, size_t size)
if (g_ClientConfig.sampleInterval >= THRESHOLD) {
Addr2Bitpool(pRet);
}
std::weak_ptr<HookSocketClient> weakClient = g_hookClient;
auto holder = weakClient.lock();
if (holder != nullptr) {
int realSize = 0;
int freeRealSize = 0;
freeData.type = FREE_MSG;
freeData.pid = rawdata.pid;
freeData.tid = rawdata.tid;
freeData.mallocSize = 0;
freeData.addr = ptr;
freeData.ts = rawdata.ts;
if (g_ClientConfig.fpunwind) {
realSize = sizeof(BaseStackRawData) + (fpStackDepth * sizeof(uint64_t));
freeRealSize = sizeof(BaseStackRawData);
} else {
realSize = sizeof(BaseStackRawData) + sizeof(rawdata.regs);
freeRealSize = realSize;
}
holder->SendStackWithPayload(&freeData, freeRealSize, nullptr, 0); // 0: Don't unwind the freeData
holder->SendStackWithPayload(&rawdata, realSize, stackptr, stackSize);
int realSize = 0;
int freeRealSize = 0;
freeData.type = FREE_MSG;
freeData.pid = rawdata.pid;
freeData.tid = rawdata.tid;
freeData.mallocSize = 0;
freeData.addr = ptr;
freeData.ts = rawdata.ts;
if (g_ClientConfig.fpunwind) {
realSize = sizeof(BaseStackRawData) + (fpStackDepth * sizeof(uint64_t));
freeRealSize = sizeof(BaseStackRawData);
} else {
realSize = sizeof(BaseStackRawData) + sizeof(rawdata.regs);
freeRealSize = realSize;
}
holder->SendStackWithPayload(&freeData, freeRealSize, nullptr, 0); // 0: Don't unwind the freeData
holder->SendStackWithPayload(&rawdata, realSize, stackptr, stackSize);
#ifdef PERFORMANCE_DEBUG
g_mallocTimes++;
struct timespec end = {};
@ -889,6 +891,11 @@ void hook_free(void (*free_func)(void*), void* p)
struct timespec start = {};
clock_gettime(CLOCK_REALTIME, &start);
#endif
std::weak_ptr<HookSocketClient> weakClient = g_hookClient;
auto holder = weakClient.lock();
if (holder == nullptr) {
return;
}
StackRawData rawdata = {{{{0}}}};
const char* stackptr = nullptr;
const char* stackendptr = nullptr;
@ -931,17 +938,13 @@ void hook_free(void (*free_func)(void*), void* p)
rawdata.tid = static_cast<uint32_t>(GetCurThreadId());
rawdata.mallocSize = 0;
rawdata.addr = p;
std::weak_ptr<HookSocketClient> weakClient = g_hookClient;
auto holder = weakClient.lock();
if (holder != nullptr) {
int realSize = 0;
if (g_ClientConfig.fpunwind) {
realSize = sizeof(BaseStackRawData) + (fpStackDepth * sizeof(uint64_t));
} else {
realSize = sizeof(BaseStackRawData) + sizeof(rawdata.regs);
}
holder->SendStackWithPayload(&rawdata, realSize, stackptr, stackSize);
int realSize = 0;
if (g_ClientConfig.fpunwind) {
realSize = sizeof(BaseStackRawData) + (fpStackDepth * sizeof(uint64_t));
} else {
realSize = sizeof(BaseStackRawData) + sizeof(rawdata.regs);
}
holder->SendStackWithPayload(&rawdata, realSize, stackptr, stackSize);
#ifdef PERFORMANCE_DEBUG
g_mallocTimes++;
struct timespec end = {};
@ -1008,6 +1011,11 @@ void* hook_mmap(void*(*fn)(void*, size_t, int, int, int, off_t),
#endif
return ret;
}
std::weak_ptr<HookSocketClient> weakClient = g_hookClient;
auto holder = weakClient.lock();
if (holder == nullptr) {
return ret;
}
StackRawData rawdata = {{{{0}}}};
const char* stackptr = nullptr;
const char* stackendptr = nullptr;
@ -1048,11 +1056,6 @@ void* hook_mmap(void*(*fn)(void*, size_t, int, int, int, off_t),
rawdata.tid = static_cast<uint32_t>(GetCurThreadId());
rawdata.mallocSize = length;
rawdata.addr = ret;
std::weak_ptr<HookSocketClient> weakClient = g_hookClient;
auto holder = weakClient.lock();
if (holder == nullptr) {
return ret;
}
if (fd >= 0) {
rawdata.type = MMAP_FILE_PAGE_MSG;
char path[FD_PATH_LENGTH] = {0};
@ -1105,13 +1108,17 @@ int hook_munmap(int(*fn)(void*, size_t), void* addr, size_t length)
if (g_ClientConfig.mmapDisable || IsPidChanged()) {
return ret;
}
#ifdef PERFORMANCE_DEBUG
struct timespec start = {};
clock_gettime(CLOCK_REALTIME, &start);
#endif
int stackSize = 0;
std::weak_ptr<HookSocketClient> weakClient = g_hookClient;
auto holder = weakClient.lock();
if (holder == nullptr) {
return ret;
}
StackRawData rawdata = {{{{0}}}};
const char* stackptr = nullptr;
const char* stackendptr = nullptr;
@ -1152,17 +1159,13 @@ int hook_munmap(int(*fn)(void*, size_t), void* addr, size_t length)
rawdata.tid = static_cast<uint32_t>(GetCurThreadId());
rawdata.mallocSize = length;
rawdata.addr = addr;
std::weak_ptr<HookSocketClient> weakClient = g_hookClient;
auto holder = weakClient.lock();
if (holder != nullptr) {
int realSize = 0;
if (g_ClientConfig.fpunwind) {
realSize = sizeof(BaseStackRawData) + (fpStackDepth * sizeof(uint64_t));
} else {
realSize = sizeof(BaseStackRawData) + sizeof(rawdata.regs);
}
holder->SendStackWithPayload(&rawdata, realSize, stackptr, stackSize);
int realSize = 0;
if (g_ClientConfig.fpunwind) {
realSize = sizeof(BaseStackRawData) + (fpStackDepth * sizeof(uint64_t));
} else {
realSize = sizeof(BaseStackRawData) + sizeof(rawdata.regs);
}
holder->SendStackWithPayload(&rawdata, realSize, stackptr, stackSize);
#ifdef PERFORMANCE_DEBUG
g_mallocTimes++;
struct timespec end = {};
@ -1187,6 +1190,11 @@ int hook_prctl(int(*fn)(int, ...),
if (reinterpret_cast<char*>(arg5) == nullptr || IsPidChanged()) {
return ret;
}
std::weak_ptr<HookSocketClient> weakClient = g_hookClient;
auto holder = weakClient.lock();
if (holder == nullptr) {
return ret;
}
if (option == PR_SET_VMA && arg2 == PR_SET_VMA_ANON_NAME) {
#ifdef PERFORMANCE_DEBUG
struct timespec start = {};
@ -1204,11 +1212,7 @@ int hook_prctl(int(*fn)(int, ...),
HILOG_BASE_ERROR(LOG_CORE, "memcpy_s tag failed");
}
rawdata.name[sizeof(rawdata.name) - 1] = '\0';
std::weak_ptr<HookSocketClient> weakClient = g_hookClient;
auto holder = weakClient.lock();
if (holder != nullptr) {
holder->SendStackWithPayload(&rawdata, sizeof(BaseStackRawData) + tagLen, nullptr, 0);
}
holder->SendStackWithPayload(&rawdata, sizeof(BaseStackRawData) + tagLen, nullptr, 0);
#ifdef PERFORMANCE_DEBUG
g_mallocTimes++;
struct timespec end = {};
@ -1233,6 +1237,11 @@ void hook_memtrace(void* addr, size_t size, const char* tag, bool isUsing)
struct timespec start = {};
clock_gettime(CLOCK_REALTIME, &start);
#endif
std::weak_ptr<HookSocketClient> weakClient = g_hookClient;
auto holder = weakClient.lock();
if (holder == nullptr) {
return;
}
int stackSize = 0;
StackRawData rawdata = {{{{0}}}};
const char* stackptr = nullptr;
@ -1274,18 +1283,14 @@ void hook_memtrace(void* addr, size_t size, const char* tag, bool isUsing)
rawdata.tid = static_cast<uint32_t>(GetCurThreadId());
rawdata.mallocSize = size;
rawdata.addr = addr;
std::weak_ptr<HookSocketClient> weakClient = g_hookClient;
auto holder = weakClient.lock();
rawdata.tagId = isUsing ? GetTagId(holder, tag) : 0;
if (holder != nullptr) {
int realSize = 0;
if (g_ClientConfig.fpunwind) {
realSize = sizeof(BaseStackRawData) + (fpStackDepth * sizeof(uint64_t));
} else {
realSize = sizeof(BaseStackRawData) + sizeof(rawdata.regs);
}
holder->SendStackWithPayload(&rawdata, realSize, stackptr, stackSize);
int realSize = 0;
if (g_ClientConfig.fpunwind) {
realSize = sizeof(BaseStackRawData) + (fpStackDepth * sizeof(uint64_t));
} else {
realSize = sizeof(BaseStackRawData) + sizeof(rawdata.regs);
}
holder->SendStackWithPayload(&rawdata, realSize, stackptr, stackSize);
#ifdef PERFORMANCE_DEBUG
g_mallocTimes++;
struct timespec end = {};

View File

@ -0,0 +1,87 @@
# Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
# 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.
import("//build/test.gni")
import("../../../base/config.gni")
module_output_path = "${OHOS_PROFILER_TEST_MODULE_OUTPUT_PATH}/device"
network_profiler_path = "${OHOS_PROFILER_DIR}/device/plugins/network_profiler"
ohos_unittest("networkprofiler_ut") {
module_out_path = module_output_path
sources = [
"${network_profiler_path}/client/src/network_profiler.cpp",
"${network_profiler_path}/client/src/network_profiler_socker_client.cpp",
"${network_profiler_path}/client/src/network_profiler_write.cpp",
"unittest/network_profiler_test.cpp",
]
deps = [
"${OHOS_PROFILER_DIR}/device/plugins/api:plugins_sources",
"${OHOS_PROFILER_DIR}/device/plugins/network_profiler/service:network_profiler_service",
"${OHOS_PROFILER_DIR}/device/services/plugin_service:hiprofiler_plugin_service",
"${OHOS_PROFILER_DIR}/device/services/profiler_service:profiler_service",
"${OHOS_PROFILER_DIR}/device/services/shared_memory:shared_memory_lite",
]
external_deps = [
"abseil-cpp:absl_sync",
"bounds_checking_function:libsec_shared",
"googletest:gtest",
"grpc:grpc",
"grpc:grpcxx",
"hilog:libhilog_base",
"protobuf:protobuf_lite",
]
external_deps += [
"bounds_checking_function:libsec_shared",
"init:libbegetutil",
"openssl:libcrypto_shared",
]
defines = []
if (current_toolchain != host_toolchain) {
external_deps += [ "hilog:libhilog_base" ]
}
include_dirs = [
"${network_profiler_path}/client/include",
"${OHOS_PROFILER_DIR}/device/plugins/api/include",
"${OHOS_PROFILER_DIR}/device/plugins/api/src",
"${OHOS_PROFILER_DIR}/interfaces/kits",
"${OHOS_PROFILER_DIR}/device/base/include",
]
include_dirs += [
"${OHOS_PROFILER_DIR}/device/plugins/network_profiler/service/include",
"${OHOS_PROFILER_DIR}/device/services/ipc/include",
"${OHOS_PROFILER_DIR}/device/services/shared_memory/include",
"${OHOS_PROFILER_DIR}/device/services/plugin_service/include",
"${OHOS_PROFILER_DIR}/interfaces/kits",
"${OHOS_PROFILER_DIR}/device/plugins/api/include",
"${OHOS_PROFILER_DIR}/device/base/include",
]
cflags = [
"-Wno-inconsistent-missing-override",
"-Dprivate=public", #allow test code access private members
"-Dprotected=public", #allow test code access private members
]
subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}"
}
group("unittest") {
testonly = true
deps = [ ":networkprofiler_ut" ]
}

View File

@ -0,0 +1,96 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
* 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 <dlfcn.h>
#include <iostream>
#include <gtest/gtest.h>
#include <thread>
#include <vector>
#include <memory>
#include "init_param.h"
#include "network_profiler_socker_client.h"
#include "network_profiler.h"
#include "network_profiler_manager.h"
#include "grpc/impl/codegen/log.h"
#include "plugin_service.h"
#include "plugin_service.ipc.h"
#include "socket_context.h"
#include "network_profiler_config.pb.h"
using namespace testing::ext;
using namespace OHOS::Developtools::Profiler;
namespace {
const std::string PARAM_KAY = "hiviewdfx.hiprofiler.networkprofiler.target";
class NetworkProfilerTest : public ::testing::Test {
public:
static void SetUpTestCase()
{
};
static void TearDownTestCase()
{
}
void SetUp() {}
void TearDown() {}
};
void CallBackFunc()
{
return;
}
/**
* @tc.name: network profiler test
* @tc.desc: Test NetworkProfilerSocketClient IsProfilerEnable without SystemSetParameter
* @tc.type: FUNC
*/
HWTEST_F(NetworkProfilerTest, NetworkProfilerTest001, TestSize.Level1)
{
auto networkProfilerMgr = std::make_shared<NetworkProfilerManager>();
auto networkProfilerService = std::make_unique<NetworkProfilerSocketService>(networkProfilerMgr);
ASSERT_TRUE(networkProfilerService != nullptr);
networkProfilerMgr->Init();
auto networkProfiler = NetworkProfiler::GetInstance();
auto ret = networkProfiler->IsProfilerEnable();
ASSERT_FALSE(ret);
NetworkProfilerSocketClient client(1, networkProfiler, CallBackFunc);
client.SendNetworkProfilerData(nullptr, 0, nullptr, 0);
}
/**
* @tc.name: network profiler test
* @tc.desc: Test NetworkProfilerSocketClient send empty data to server
* @tc.type: FUNC
*/
HWTEST_F(NetworkProfilerTest, NetworkProfilerTest002, TestSize.Level1)
{
auto networkProfilerMgr = std::make_shared<NetworkProfilerManager>();
auto networkProfilerService = std::make_unique<NetworkProfilerSocketService>(networkProfilerMgr);
ASSERT_TRUE(networkProfilerService != nullptr);
networkProfilerMgr->Init();
SystemSetParameter(PARAM_KAY.c_str(), std::to_string(getpid()).c_str());
auto networkProfiler = NetworkProfiler::GetInstance();
auto ret = networkProfiler->IsProfilerEnable();
ASSERT_TRUE(ret);
NetworkProfilerSocketClient client(1, networkProfiler, CallBackFunc);
ret = client.SendNetworkProfilerData(nullptr, 0, nullptr, 0);
ASSERT_FALSE(ret);
SocketContext ctx;
ret = client.ProtocolProc(ctx, 0, nullptr, 0);
ASSERT_TRUE(ret);
}
} // namespace

View File

@ -146,7 +146,7 @@ HiDebug_ErrorCode OH_HiDebug_StopAppTraceCapture();
* {@link HIDEBUG_SUCCESS} Get graphics memory success.
* {@link HIDEBUG_INVALID_ARGUMENT} Invalid argumentvalue is null.
* {@link HIDEBUG_TRACE_ABNORMAL} Failed to get the application memory due to a remote exception.
* @since 13
* @since 14
*/
HiDebug_ErrorCode OH_HiDebug_GetGraphicsMemory(uint32_t *value);

View File

@ -151,7 +151,7 @@ std::map<std::string, std::string> CPU::GetSysProcessCpuLoad() const
const size_t oneHundred = 100;
if (!processId.empty()) {
int32_t procId = 0;
procId = std::stoi(processId);
procId = SPUtilesTye::StringToSometype<int32_t>(processId);
std::shared_ptr<CpuCollector> collector = CpuCollector::Create();
auto collectResult = collector->CollectProcessCpuStatInfo(procId, true);
auto data = collectResult.data;

View File

@ -36,7 +36,7 @@ long long DDR::GetDdrFreq()
} else {
SPUtils::LoadFile(ddrCurFreqRkPath, ddrfreq);
}
curFreq = std::atoll(ddrfreq.c_str());
curFreq = SPUtilesTye::StringToSometype<long long>(ddrfreq.c_str());
return curFreq;
}
void DDR::SetRkFlag()

View File

@ -68,7 +68,7 @@ int32_t GPU::GetRkGpuFreq()
const std::string gpuFreqPath = "/sys/class/devfreq/fde60000.gpu/cur_freq";
std::string rkFreq;
SPUtils::LoadFile(gpuFreqPath, rkFreq);
return std::stoi(rkFreq);
return SPUtilesTye::StringToSometype<int32_t>(rkFreq);
}
float GPU::GetRkGpuLoad()
@ -80,7 +80,7 @@ float GPU::GetRkGpuLoad()
if (len > 0) {
rkLoad = rkLoad.substr(0, len - 1);
}
return std::stoi(rkLoad);
return SPUtilesTye::StringToSometype<float>(rkLoad);
}
void GPU::SetRkFlag()

View File

@ -58,8 +58,6 @@ namespace OHOS {
typedef GpuCounterPlugin *(*GetGpuCounterPlugin)();
GetGpuCounterPlugin startGetGpuPerfInfo = (GetGpuCounterPlugin)dlsym(handle, CREATE_PLUGIN.c_str());
gpuPlugin = startGetGpuPerfInfo;
isflugin = true;
if (type == GC_START && gcStatus == GC_INIT) {
gpuCounterData.clear();
@ -182,51 +180,5 @@ namespace OHOS {
LOGI("GpuCounter collect finish.");
}
}
void AiScheduling::AiSchedulingSwitch()
{
void* handle = GpuCounter::GetInstance().GetSoHandle();
if (!handle) {
return;
}
bool aiFlag = GpuCounter::GetInstance().isflugin;
AiPlugin(aiFlag, handle);
AiStatusType();
if (type == AI_START && aiConfig == AI_INIT) {
int ret = setGameDevelopConfig()->SetGameDevelopConfig(aiConfigType, configMap);
if (ret == 1) {
LOGI("AiScheduling start");
} else {
LOGE("AiScheduling call gameService error, ret = %d", ret);
}
} else if (type == AI_CLOSE && aiConfig == AI_INIT) {
int ret = setGameDevelopConfig()->SetGameDevelopConfig(aiConfigType, configMap);
if (ret == 0) {
LOGI("AiScheduling close");
} else {
LOGE("AiScheduling call gameService error, ret = %d", ret);
}
} else {
LOGE("AiScheduling state error, type: %d, state: %d", type, aiConfig);
}
}
void AiScheduling::AiStatusType()
{
if (configMap["openAISched"] == "0") {
type = AI_CLOSE;
} else {
type = AI_START;
}
}
void AiScheduling::AiPlugin(bool flag, void* handle)
{
if (!flag) {
setGameDevelopConfig = (GetGpuCounterPlugin)dlsym(handle, CREATE_PLUGIN.c_str());
} else {
setGameDevelopConfig = GpuCounter::GetInstance().gpuPlugin;
}
}
}
}

View File

@ -54,7 +54,7 @@ std::map<std::string, std::string> Temperature::ItemData()
for (auto node : collectNodes) {
if (type.find(node) != std::string::npos) {
LOGI("type====: %s", type.c_str());
float t = std::stof(temp);
float t = SPUtilesTye::StringToSometype<float>(temp);
LOGI("temp====: %s", temp.c_str());
if (node == "gpu") {
result[type] = std::to_string(t);

View File

@ -32,7 +32,6 @@ namespace OHOS {
virtual int32_t StartGetGpuPerfInfo(int64_t duration, std::unique_ptr <GpuCounterCallback> callback) = 0;
virtual int32_t StopGetGpuPerfInfo() = 0;
virtual int32_t SetGameDevelopConfig(int32_t configType, std::map<std::string, std::string> configMap) = 0;
};
class GpuCounter : public SpProfiler {
@ -64,14 +63,11 @@ namespace OHOS {
void AddGpuCounterRealtimeData(std::string dataString);
void GetGpuRealtimeData(std::map<std::string, std::string> &dataMap);
void SaveData(std::string path);
void* GetSoHandle();
typedef GpuCounterPlugin *(*GetGpuCounterPlugin)();
GetGpuCounterPlugin gpuPlugin = nullptr;
bool isflugin = false;
private:
GpuCounter() {};
GpuCounter(const GpuCounter &);
GpuCounter &operator = (const GpuCounter &);
void* GetSoHandle();
GcStatus gcStatus = GC_INIT;
std::vector<std::string> gpuCounterData;
std::vector<std::string> gpuCounterSaveReportData;
@ -80,37 +76,8 @@ namespace OHOS {
const std::string PLUGIN_SO_PATH = "system/lib64/libgameservice_gpucounter_plugin.z.so";
const std::string CREATE_PLUGIN = "onCreatePlugin";
};
class AiScheduling {
public:
enum AiConfigType {
AI_INIT = 2,
};
enum AiSchedulingStatus {
AI_START = 1,
AI_CLOSE = 0,
};
public:
static AiScheduling &GetInstance()
{
static AiScheduling instance;
return instance;
}
void AiSchedulingSwitch();
void AiStatusType();
std::map<std::string, std::string> configMap;
private:
AiScheduling() {};
AiScheduling(const AiScheduling &);
AiScheduling &operator = (const AiScheduling &);
AiConfigType aiConfig = AI_INIT;
AiSchedulingStatus type;
const std::string PLUGIN_SO_PATH = "system/lib64/libgameservice_gpucounter_plugin.z.so";
const std::string CREATE_PLUGIN = "onCreatePlugin";
typedef GpuCounterPlugin *(*GetGpuCounterPlugin)();
GetGpuCounterPlugin setGameDevelopConfig = nullptr;
void AiPlugin(bool flag, void* handle);
const int32_t aiConfigType = 2;
};
};
}
#endif
#endif

View File

@ -163,8 +163,6 @@ const std::unordered_map<CommandType, std::string> COMMAND_MAP_REVERSE = {
{ CommandType::CT_NAV, std::string("-nav") },
{ CommandType::CT_O, std::string("-o") },
{ CommandType::CT_LF, std::string("-lockfreq") },
{ CommandType::CT_CLOSEAISCHEDULING, std::string("-CloseAIScheduling") },
{ CommandType::CT_OPENAISCHEDULING, std::string("-OpenAIScheduling") },
};
@ -230,7 +228,7 @@ const std::unordered_map<CmdCommand, std::string> CMD_COMMAND_MAP = {
{ CmdCommand::PIDOF_SP, std::string("pidof SP_daemon") },
{ CmdCommand::SERVER_GREP, std::string("ps -ef | grep -v grep | grep 'SP_daemon -server'") },
{ CmdCommand::EDITOR_SERVER_GREP, std::string("ps -ef | grep -v grep | grep 'SP_daemon -editorServer'") },
{ CmdCommand::UINPUT_BACK, std::string("uinput -K -d 2076 -d 2020") },
{ CmdCommand::UINPUT_BACK, std::string("uinput -T -m 600 2760 600 1300 200") },
{ CmdCommand::TIMESTAMPS, std::string("timestamps") },
{ CmdCommand::USER_PERMISSIONS, std::string("whoami") },
};

View File

@ -110,8 +110,6 @@ public:
// 采集配置项
std::vector<std::string> configs;
GpuCounter &gpuCounter = GpuCounter::GetInstance();
AiScheduling &aiScheduling = AiScheduling::GetInstance();
void IsGpuCounter(bool &flag, std::vector<std::string> cmdConfig);
};
}
}

View File

@ -19,8 +19,21 @@
#include <map>
#include <set>
#include <string>
#include <sstream>
namespace OHOS {
namespace SmartPerf {
class SPUtilesTye {
public:
template<typename T>
static T StringToSometype(const std::string& str)
{
T result;
std::stringstream ss;
ss << str;
ss >> result;
return result;
}
};
namespace SPUtils {
/**
* @brief Check if the file has permission to access

View File

@ -55,16 +55,16 @@ double ParseClickCompleteTrace::GetLineTime()
size_t position1 = line.find("....");
size_t position2 = line.find(":");
endTime = line.substr(position1 + subNum, position2 - position1 - subNum);
int endNum = std::stof(endTime);
int endFlagNum = std::stof(endTimeFlag);
int startNum = std::stof(startTime);
int endNum = SPUtilesTye::StringToSometype<float>(endTime);
int endFlagNum = SPUtilesTye::StringToSometype<float>(endTimeFlag);
int startNum = SPUtilesTye::StringToSometype<float>(startTime);
int timeNum = endNum - endFlagNum;
float interval = 0.3;
if (timeNum < interval) {
endTimeFlag = endTime;
continue;
}
if (std::stof(endTimeFlag) == 0) {
if (SPUtilesTye::StringToSometype<float>(endTimeFlag) == 0) {
endTimeFlag = endTime;
} else if (endFlagNum != 0 && startNum != 0 && timeNum > interval) {
break;
@ -82,10 +82,11 @@ double ParseClickCompleteTrace::GetTime(std::string endTime)
float subNum = 2;
endTime = endTime.substr(point - subNum);
startTime = startTime.substr(point - subNum);
if (std::stof(endTime) == 0 || std::stof(startTime) == 0) {
if (SPUtilesTye::StringToSometype<float>(endTime) == 0 || SPUtilesTye::StringToSometype<float>(startTime) == 0) {
} else {
double displayTime = 0.032;
completeTime = std::stof(endTime) - std::stof(startTime) + displayTime;
completeTime = SPUtilesTye::StringToSometype<float>(endTime) -
SPUtilesTye::StringToSometype<float>(startTime) + displayTime;
}
return completeTime;
}

View File

@ -50,20 +50,20 @@ double ParseClickResponseTrace::GetLineTime()
std::string::size_type doComposition;
size_t subNum = 5;
while (getline(infile, line)) {
appPid = SmartPerf::ParseClickResponseTrace::GetPid(line, "pid", appPid);
startTime = SmartPerf::ParseClickResponseTrace::GetStartTime(line, startTime);
appPid = ParseClickResponseTrace::GetPid(line, "pid", appPid);
startTime = ParseClickResponseTrace::GetStartTime(line, startTime);
doComposition = line.find("H:RSMainThread::DoComposition");
if (doComposition != std::string::npos) {
size_t position1 = line.find("....");
size_t position2 = line.find(":");
endTime = line.substr(position1 + subNum, position2 - position1 - subNum);
if (std::stof(startTime) == 0) {
if (SPUtilesTye::StringToSometype<float>(startTime) == 0) {
} else {
break;
}
}
}
completeTime = SmartPerf::ParseClickResponseTrace::GetTime(startTime, endTime);
completeTime = ParseClickResponseTrace::GetTime(startTime, endTime);
return completeTime;
}
double ParseClickResponseTrace::GetTime(std::string startTime, std::string endTime)
@ -72,10 +72,11 @@ double ParseClickResponseTrace::GetTime(std::string startTime, std::string endTi
float subNum = 2;
endTime = endTime.substr(point - subNum);
startTime = startTime.substr(point - subNum);
if (std::stof(endTime) == 0 || std::stof(startTime) == 0) {
if (SPUtilesTye::StringToSometype<float>(endTime) == 0 || SPUtilesTye::StringToSometype<float>(startTime) == 0) {
} else {
double displayTime = 0.032;
completeTime = std::stof(endTime) - std::stof(startTime) + displayTime;
completeTime = SPUtilesTye::StringToSometype<float>(endTime) -
SPUtilesTye::StringToSometype<float>(startTime) + displayTime;
}
return completeTime;
}

View File

@ -26,20 +26,21 @@
#include <cmath>
#include "include/parse_radar.h"
#include "include/sp_log.h"
#include "include/sp_utils.h"
namespace OHOS {
namespace SmartPerf {
double ParseRadar::ParseRadarStart(const std::string &string) const
{
double time = -1;
std::string target = "\"E2E_LATENCY\":";
time = std::stod(ExtractString(string, target));
time = SPUtilesTye::StringToSometype<double>(ExtractString(string, target));
return time;
}
double ParseRadar::ParseRadarStartResponse(const std::string &string) const
{
double time = -1;
std::string target = "\"RESPONSE_LATENCY\":";
time = std::stod(ExtractString(string, target));
time = SPUtilesTye::StringToSometype<double>(ExtractString(string, target));
return time;
}
std::string ParseRadar::ParseRadarAppStrart(const std::string &string) const
@ -100,7 +101,7 @@ int ParseRadar::GetMaxDelayTime(const int &delayTime, std::vector<std::string> &
{
int maxNum = -1;
for (size_t i = 0; i < delayTimeVec.size(); i++) {
int num = std::stoi(delayTimeVec[i]);
int num = SPUtilesTye::StringToSometype<int>(delayTimeVec[i]);
if (num < delayTime && num > maxNum) {
maxNum = num;
}

View File

@ -18,6 +18,7 @@
#include <regex>
#include "include/parse_slide_fps_trace.h"
#include "include/sp_log.h"
#include "include/sp_utils.h"
namespace OHOS {
namespace SmartPerf {
@ -48,13 +49,13 @@ double ParseSlideFpsTrace::CalculateTime()
if (count == four) {
needTime = true;
frameNow = 0;
touchTime = std::stod(SmartPerf::ParseSlideFpsTrace::GetLineTime(line));
touchTime = SPUtilesTye::StringToSometype<double>(ParseSlideFpsTrace::GetLineTime(line));
LOGI("ParseSlideFpsTrace::touchTime: (%s)", std::to_string(touchTime).c_str());
swiperFlingFlag = 0;
}
} else if (line.find("H:RSMainThread::DoComposition") != std::string::npos) {
frameNow++;
doCompositionTime = std::stod(SmartPerf::ParseSlideFpsTrace::GetLineTime(line));
doCompositionTime = SPUtilesTye::StringToSometype<double>(ParseSlideFpsTrace::GetLineTime(line));
LOGI("ParseSlideFpsTrace::doCompositionTime: (%s)", std::to_string(doCompositionTime).c_str());
} else if (line.find("H:WEB_LIST_FLING") != std::string::npos ||
line.find("H:APP_LIST_FLING,") != std::string::npos) {
@ -92,7 +93,7 @@ void ParseSlideFpsTrace::AppSwiperScroll(std::string line)
{
if (line.find("H:APP_SWIPER_SCROLL,") != std::string::npos) {
if (swiperScrollFlag == 0) {
touchTime = std::stod(SmartPerf::ParseSlideFpsTrace::GetLineTime(line));
touchTime = SPUtilesTye::StringToSometype<double>(ParseSlideFpsTrace::GetLineTime(line));
LOGI("AppSwiperScroll.touchTime: (%s)", std::to_string(touchTime).c_str());
needTime = true;
swiperScrollFlag = 1;

View File

@ -144,12 +144,12 @@ void ProfilerFPS::GetTimeDiff()
if (params[0].find("CLOCK_REALTIME") != std::string::npos && clockRealTime == 0) {
strRealTime = params[two];
strRealTime.erase(strRealTime.find('.'), 1);
clockRealTime = std::stoll(strRealTime);
clockRealTime = SPUtilesTye::StringToSometype<long long>(strRealTime);
currRealTime = clockRealTime;
} else if (params[0].find("CLOCK_MONOTONIC_RAW") != std::string::npos && clockMonotonicRaw == 0) {
strRealTime = params[two];
strRealTime.erase(strRealTime.find('.'), 1);
clockMonotonicRaw = std::stoll(strRealTime);
clockMonotonicRaw = SPUtilesTye::StringToSometype<long long>(strRealTime);
}
}
if (pclose(fd) == -1) {
@ -240,12 +240,13 @@ void ProfilerFPS::GetFPS(std::vector<std::string> v)
if (v[number] == "") {
printf("the args of num must be not-null!\n");
} else {
this->num = atoi(v[number].c_str());
this->num = SPUtilesTye::StringToSometype<int>(v[number].c_str());
if (this->num < 0) {
printf("set num:%d not valid arg\n", this->num);
}
printf("set num:%d success\n", this->num);
int sectionsNum = (static_cast<int>(v.size()) >= four) ? atoi(v[four].c_str()) : 0;
int sectionsNum = (static_cast<int>(v.size()) >= four) ?
SPUtilesTye::StringToSometype<int>(v[four].c_str()) : 0;
if (sectionsNum > ten) {
printf("set sectionsNum:%d not valid arg \n", sectionsNum);
} else {
@ -405,7 +406,7 @@ void ProfilerFPS::GetOhFps(std::vector<std::string> v)
if (v[number] == "") {
printf("the args of num must be not-null!\n");
} else {
this->num = atoi(v[number].c_str());
this->num = SPUtilesTye::StringToSometype<int>(v[number].c_str());
if (this->num < 0) {
printf("set num:%d not vaild arg\n", this->num);
}
@ -415,7 +416,7 @@ void ProfilerFPS::GetOhFps(std::vector<std::string> v)
if (static_cast<int>(v.size()) < four) {
sectionsNum = 0;
} else {
sectionsNum = atoi(v[four].c_str());
sectionsNum = SPUtilesTye::StringToSometype<int>(v[four].c_str());
}
for (int i = 0; i < this->num; i++) {
GetResultFPS(sectionsNum);

View File

@ -108,8 +108,9 @@ namespace OHOS {
} else if (first == "para0") {
eventName = second;
} else if (first == "time") {
realTimestamp = std::to_string(std::stoll(second) - SPTask::GetInstance().GetRealStartTime());
timestamp = std::to_string(std::stoll(second) - params.startTime);
realTimestamp = std::to_string(SPUtilesTye::StringToSometype<long long>(second) -
SPTask::GetInstance().GetRealStartTime());
timestamp = std::to_string(SPUtilesTye::StringToSometype<long long>(second) - params.startTime);
} else if (first == "enable") {
enable = second;
} else if (first == "value") {

View File

@ -16,7 +16,6 @@
#include <thread>
#include <cstring>
#include <iterator>
#include <map>
#include "unistd.h"
#include "include/heartbeat.h"
#include "include/sp_utils.h"
@ -29,7 +28,6 @@
#include "include/sp_log.h"
#include "include/RAM.h"
#include "include/common.h"
#include "include/GpuCounter.h"
namespace OHOS {
namespace SmartPerf {
@ -132,7 +130,7 @@ void SmartPerfCommand::HandleCommand(std::string argStr, const std::string &argS
LOGI("SmartPerfCommand::HandleCommand argStr(%s) argStr1(%s)", argStr.c_str(), argStr1.c_str());
switch (COMMAND_MAP.at(argStr)) {
case CommandType::CT_N:
num = atoi(argStr1.c_str());
num = SPUtilesTye::StringToSometype<int>(argStr1.c_str());
break;
case CommandType::CT_PKG:
pkgName = argStr1;
@ -165,8 +163,6 @@ void SmartPerfCommand::HandleCommand(std::string argStr, const std::string &argS
case CommandType::CT_HW:
case CommandType::CT_GC:
case CommandType::CT_NAV:
case CommandType::CT_OPENAISCHEDULING:
case CommandType::CT_CLOSEAISCHEDULING:
configs.push_back(argStr);
break;
default:
@ -187,11 +183,11 @@ int SmartPerfCommand::GetItemInfo(std::multimap<std::string, std::string, declty
}
for (size_t j = 0; j < configs.size(); j++) {
std::string curParam = configs[j];
if (curParam.find("-gc") != std::string::npos ||
curParam.find("-CloseAIScheduling") != std::string::npos ||
curParam.find("-OpenAIScheduling") != std::string::npos) {
if (curParam.find("-gc") != std::string::npos) {
continue;
}
SpProfiler *profiler = SpProfilerFactory::GetCmdProfilerItem(COMMAND_MAP.at(curParam), true);
if (profiler != nullptr) {
std::map<std::string, std::string> data = profiler->ItemData();
@ -204,6 +200,7 @@ int SmartPerfCommand::GetItemInfo(std::multimap<std::string, std::string, declty
LOGE("%s", errInfo.c_str());
return -1;
}
return rc;
}
@ -224,7 +221,12 @@ std::string SmartPerfCommand::ExecCommand()
const long long freq = 1000;
num = num + 1;
bool gcFlag = false;
IsGpuCounter(gcFlag, configs);
for (std::string itConfig : configs) {
if (itConfig.find("-gc") != std::string::npos) {
gpuCounter.StartCollect(GpuCounter::GC_START);
gcFlag = true;
}
}
while (index < num) {
std::multimap<std::string, std::string, decltype(SPUtils::Cmp) *> spMap(SPUtils::Cmp);
long long lastTime = SPUtils::GetCurTime();
@ -287,29 +289,5 @@ void SmartPerfCommand::InitSomething()
LOGI("SmartPerfCommand::InitSomething Privilege escalation!");
};
}
void SmartPerfCommand::IsGpuCounter(bool &flag, std::vector<std::string> cmdConfig)
{
for (std::string itConfig : cmdConfig) {
if (itConfig.find("-gc") != std::string::npos) {
gpuCounter.StartCollect(GpuCounter::GC_START);
flag = true;
}
if (itConfig.find("-CloseAIScheduling") != std::string::npos) {
std::map<std::string, std::string> figMap;
figMap["bundleName"] = pkgName;
figMap["openAISched"] = "0";
aiScheduling.configMap.insert(figMap.begin(), figMap.end());
aiScheduling.AiSchedulingSwitch();
}
if (itConfig.find("-OpenAIScheduling") != std::string::npos) {
std::map<std::string, std::string> figMap;
figMap["bundleName"] = pkgName;
figMap["openAISched"] = "1";
aiScheduling.configMap.insert(figMap.begin(), figMap.end());
aiScheduling.AiSchedulingSwitch();
}
}
}
}
}

View File

@ -146,16 +146,16 @@ void SpProfilerFactory::SetByTrace(std::string message)
std::vector<std::string> vItems;
SPUtils::StrSplit(vItem, delim, vItems);
if (vItems[0] == "traceSum") {
mSum = std::stoi(vItems[1]);
mSum = SPUtilesTye::StringToSometype<int>(vItems[1]);
}
if (vItems[0] == "fpsJitterTime") {
mThreshold = std::stoi(vItems[1]);
mThreshold = SPUtilesTye::StringToSometype<int>(vItems[1]);
}
if (vItems[0] == "catchInterval") {
mInterval = std::stoi(vItems[1]);
mInterval = SPUtilesTye::StringToSometype<int>(vItems[1]);
}
if (vItems[0] == "lowFps") {
lowFps = std::stoi(vItems[1]);
lowFps = SPUtilesTye::StringToSometype<int>(vItems[1]);
}
}
const ByTrace &bTrace = ByTrace::GetInstance();

View File

@ -64,14 +64,14 @@ static ExceptionMsg ParseToTask(std::string command, TaskInfo &taskInfo)
if (args[i] == COMMAND_MAP_REVERSE.at(CommandType::CT_SESSIONID)) {
sessionId = args[++i];
} else if (args[i] == COMMAND_MAP_REVERSE.at(CommandType::CT_INTERVAL)) {
interval = std::stoll(args[++i]);
interval = SPUtilesTye::StringToSometype<long long>(args[++i]);
} else if (args[i] == COMMAND_MAP_REVERSE.at(CommandType::CT_PKG)) {
pkg = args[++i];
} else if (args[i] == COMMAND_MAP_REVERSE.at(CommandType::CT_FL)) { // 获取用户fps的值并赋给snf. CT_FL
snf.fps = std::stoi(args[++i]);
snf.fps = SPUtilesTye::StringToSometype<int>(args[++i]);
snf.isEffective = true;
} else if (args[i] == COMMAND_MAP_REVERSE.at(CommandType::CT_FTL)) { // 获取frameTime的值 CT_FTL
snf.frameTime = std::stoi(args[++i]);
snf.frameTime = SPUtilesTye::StringToSometype<int>(args[++i]);
snf.isEffective = true;
} else {
if (args[i] == COMMAND_MAP_REVERSE.at(CommandType::CT_F)) { // 判断用户设置是否有-f

View File

@ -63,8 +63,8 @@ bool SPUtils::Cmp(const std::string &a, const std::string &b)
if (str1 != str2) {
return str1 < str2;
}
int num1 = std::stoi(a.substr(str1.length()));
int num2 = std::stoi(b.substr(str2.length()));
int num1 = SPUtilesTye::StringToSometype<int>(a.substr(str1.length()));
int num2 = SPUtilesTye::StringToSometype<int>(b.substr(str2.length()));
return num1 < num2;
}
return false;

View File

@ -19,6 +19,7 @@
#include <cmath>
#include "include/stalling_rate_trace.h"
#include "include/sp_log.h"
#include "include/sp_utils.h"
namespace OHOS {
namespace SmartPerf {
@ -202,7 +203,7 @@ void StallingRateTrace::AppList(const std::string &line, const std::string &sign
}
std::string waitFenceId = "|H:Waiting for Present Fence " + std::to_string(fenceId);
if (line.find(waitFenceId) != std::string::npos) {
nowTime = std::stod(SmartPerf::StallingRateTrace::GetOnScreenTimeStart(line));
nowTime = SPUtilesTye::StringToSometype<double>(StallingRateTrace::GetOnScreenTimeStart(line));
GetFrameLossTime(nowTime, lastTime, roundTime, frameLossTime);
LOGI("frameLossTime: (%s)", std::to_string(frameLossTime).c_str());
lastTime = nowTime;
@ -323,7 +324,7 @@ void StallingRateTrace::AppSwiperScroll(const std::string &line, const std::stri
}
std::string waitFenceId = "|H:Waiting for Present Fence " + std::to_string(fenceIdSwiper);
if (line.find(waitFenceId) != std::string::npos) {
nowSwiperTime = std::stod(SmartPerf::StallingRateTrace::GetOnScreenTimeStart(line));
nowSwiperTime = SPUtilesTye::StringToSometype<double>(StallingRateTrace::GetOnScreenTimeStart(line));
LOGI("nowSwiperTime: (%s)", std::to_string(nowSwiperTime).c_str());
GetFrameLossTime(nowSwiperTime, lastSwiperTime, roundSwiperTime, frameLossSwiperTime);
LOGI("frameLossSwiperTime: (%s)", std::to_string(frameLossSwiperTime).c_str());
@ -388,12 +389,12 @@ double StallingRateTrace::GetFrameRate(const std::string &line) const
std::string result1 = line.substr(pos1 + delimiter.length());
size_t pos2 = line.find(delimiter1);
std::string result2 = result1.substr(0, pos2);
rate = std::stod(result2.c_str());
rate = SPUtilesTye::StringToSometype<double>(result2.c_str());
}
if (line.find("rate:") != std::string::npos) {
size_t pos = line.find(delimiter);
std::string result = line.substr(pos + delimiter.length());
rate = std::stod(result.c_str());
rate = SPUtilesTye::StringToSometype<double>(result.c_str());
}
return rate;
}
@ -403,7 +404,7 @@ int StallingRateTrace::GetFenceId(const std::string &line) const
std::string delimiter = "H:Present Fence ";
size_t pos = line.find(delimiter);
std::string result = line.substr(pos + delimiter.length());
int presentFenceId = std::atoi(result.c_str());
int presentFenceId = SPUtilesTye::StringToSometype<int>(result.c_str());
return presentFenceId;
}
@ -424,7 +425,8 @@ double StallingRateTrace::GetTimes(const std::string &line, const std::string &s
if (positionFirst != std::string::npos && positionSecond != std::string::npos) {
if (line.find(sign) != std::string::npos) {
size_t subNum = 7;
return std::stod(line.substr(positionFirst + subNum, positionSecond - positionFirst - subNum));
return SPUtilesTye::StringToSometype<double>(line.substr(
positionFirst + subNum, positionSecond - positionFirst - subNum));
}
}
return 0.0;