mirror of
https://gitee.com/openharmony/developtools_profiler
synced 2025-02-18 17:59:06 +00:00
!1687 在HidebugNDK里新增HIDEBUG_NO_TRACE_RUNNING错误码
Merge pull request !1687 from 董博斯/master
This commit is contained in:
commit
0b060a8958
@ -144,8 +144,8 @@ HiDebug_ErrorCode OH_HiDebug_StartAppTraceCapture(HiDebug_TraceFlag flag,
|
||||
}
|
||||
std::string file;
|
||||
auto ret = nativeInterface->StartAppTraceCapture(tags, flag, limitSize, file);
|
||||
if (ret != OHOS::HiviewDFX::TRACE_SUCCESS) {
|
||||
return static_cast<HiDebug_ErrorCode>(ret);
|
||||
if (ret != HIDEBUG_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
if (strcpy_s(fileName, length, file.c_str()) != EOK) {
|
||||
nativeInterface->StopAppTraceCapture();
|
||||
@ -161,9 +161,5 @@ HiDebug_ErrorCode OH_HiDebug_StopAppTraceCapture()
|
||||
if (!nativeInterface) {
|
||||
return HIDEBUG_TRACE_ABNORMAL;
|
||||
}
|
||||
auto ret = nativeInterface->StopAppTraceCapture();
|
||||
if (ret == OHOS::HiviewDFX::TRACE_SUCCESS) {
|
||||
return HIDEBUG_SUCCESS;
|
||||
}
|
||||
return HIDEBUG_TRACE_ABNORMAL;
|
||||
return nativeInterface->StopAppTraceCapture();
|
||||
}
|
@ -25,15 +25,6 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace HiviewDFX {
|
||||
enum TraceState {
|
||||
TRACE_SUCCESS = 0,
|
||||
TRACE_INVALID_ARGS = 401,
|
||||
TRACE_CAPTURED_ALREADY = 11400102,
|
||||
TRACE_NO_PERMISSION = 11400103,
|
||||
TRACE_ABNORMAL = 11400104,
|
||||
TRACE_NO_RUNNING = 11400105,
|
||||
};
|
||||
|
||||
enum MemoryState {
|
||||
MEMORY_FAILED = -1,
|
||||
MEMORY_SUCCESS = 0,
|
||||
@ -53,8 +44,9 @@ public:
|
||||
|
||||
virtual double GetCpuUsage() = 0;
|
||||
virtual std::map<uint32_t, double> GetAppThreadCpuUsage() = 0;
|
||||
virtual int StartAppTraceCapture(uint64_t tags, uint32_t flag, uint32_t limitsize, std::string &file) = 0;
|
||||
virtual int StopAppTraceCapture() = 0;
|
||||
virtual HiDebug_ErrorCode StartAppTraceCapture(uint64_t tags, uint32_t flag,
|
||||
uint32_t limitsize, std::string &file) = 0;
|
||||
virtual HiDebug_ErrorCode StopAppTraceCapture() = 0;
|
||||
virtual int GetMemoryLeakResource(const std::string& type, int32_t value, bool enabledDebugLog) = 0;
|
||||
virtual std::optional<MemoryLimit> GetAppMemoryLimit() = 0;
|
||||
virtual std::optional<HiDebug_NativeMemInfo> GetAppNativeMemInfo() = 0;
|
||||
|
@ -42,8 +42,9 @@ public:
|
||||
HidebugNativeInterfaceImpl& operator =(const HidebugNativeInterfaceImpl&) = delete;
|
||||
double GetCpuUsage() override;
|
||||
std::map<uint32_t, double> GetAppThreadCpuUsage() override;
|
||||
int StartAppTraceCapture(uint64_t tags, uint32_t flag, uint32_t limitsize, std::string &file) override;
|
||||
int StopAppTraceCapture() override;
|
||||
HiDebug_ErrorCode StartAppTraceCapture(uint64_t tags, uint32_t flag,
|
||||
uint32_t limitsize, std::string &file) override;
|
||||
HiDebug_ErrorCode StopAppTraceCapture() override;
|
||||
int GetMemoryLeakResource(const std::string& type, int32_t value, bool enabledDebugLog) override;
|
||||
std::optional<double> GetSystemCpuUsage() override;
|
||||
std::optional<MemoryLimit> GetAppMemoryLimit() override;
|
||||
@ -91,35 +92,35 @@ std::map<uint32_t, double> HidebugNativeInterfaceImpl::GetAppThreadCpuUsage()
|
||||
return threadMap;
|
||||
}
|
||||
|
||||
int HidebugNativeInterfaceImpl::StartAppTraceCapture(uint64_t tags, uint32_t flag,
|
||||
HiDebug_ErrorCode HidebugNativeInterfaceImpl::StartAppTraceCapture(uint64_t tags, uint32_t flag,
|
||||
uint32_t limitsize, std::string &file)
|
||||
{
|
||||
auto ret = StartCaptureAppTrace((TraceFlag)flag, tags, limitsize, file);
|
||||
if (ret == RET_SUCC) {
|
||||
return TRACE_SUCCESS;
|
||||
return HIDEBUG_SUCCESS;
|
||||
}
|
||||
if (ret == RET_FAIL_INVALID_ARGS) {
|
||||
return TRACE_INVALID_ARGS;
|
||||
return HIDEBUG_INVALID_ARGUMENT;
|
||||
}
|
||||
if (ret == RET_STARTED) {
|
||||
return TRACE_CAPTURED_ALREADY;
|
||||
return HIDEBUG_TRACE_CAPTURED_ALREADY;
|
||||
}
|
||||
if (ret == RET_FAIL_MKDIR || ret == RET_FAIL_SETACL || ret == RET_FAIL_EACCES || ret == RET_FAIL_ENOENT) {
|
||||
return TRACE_NO_PERMISSION;
|
||||
return HIDEBUG_NO_PERMISSION;
|
||||
}
|
||||
return TRACE_ABNORMAL;
|
||||
return HIDEBUG_TRACE_ABNORMAL;
|
||||
}
|
||||
|
||||
int HidebugNativeInterfaceImpl::StopAppTraceCapture()
|
||||
HiDebug_ErrorCode HidebugNativeInterfaceImpl::StopAppTraceCapture()
|
||||
{
|
||||
auto ret = StopCaptureAppTrace();
|
||||
if (ret == RET_SUCC) {
|
||||
return TRACE_SUCCESS;
|
||||
return HIDEBUG_SUCCESS;
|
||||
}
|
||||
if (ret == RET_STOPPED) {
|
||||
return TRACE_NO_RUNNING;
|
||||
return HIDEBUG_NO_TRACE_RUNNING;
|
||||
}
|
||||
return TRACE_ABNORMAL;
|
||||
return HIDEBUG_TRACE_ABNORMAL;
|
||||
}
|
||||
|
||||
std::optional<double> HidebugNativeInterfaceImpl::GetSystemCpuUsage()
|
||||
|
@ -823,19 +823,19 @@ napi_value StartAppTraceCapture(napi_env env, napi_callback_info info)
|
||||
return CreateUndefined(env);
|
||||
}
|
||||
auto ret = nativeInterface->StartAppTraceCapture(tag, traceFlag, limitSize, file);
|
||||
if (ret == TRACE_SUCCESS) {
|
||||
if (ret == HIDEBUG_SUCCESS) {
|
||||
napi_create_string_utf8(env, file.c_str(), NAPI_AUTO_LENGTH, &result);
|
||||
return result;
|
||||
}
|
||||
if (ret == PARAMETER_ERROR) {
|
||||
if (ret == HIDEBUG_INVALID_ARGUMENT) {
|
||||
std::string errorMessage = "Invalid argument";
|
||||
napi_throw_error(env, std::to_string(ErrorCode::PARAMETER_ERROR).c_str(), errorMessage.c_str());
|
||||
}
|
||||
if (ret == HAVA_ALREADY_TRACE) {
|
||||
if (ret == HIDEBUG_TRACE_CAPTURED_ALREADY) {
|
||||
std::string errorMessage = "Capture trace already enabled.";
|
||||
napi_throw_error(env, std::to_string(ErrorCode::HAVA_ALREADY_TRACE).c_str(), errorMessage.c_str());
|
||||
}
|
||||
if (ret == WITHOUT_WRITE_PERMISSON) {
|
||||
if (ret == HIDEBUG_NO_PERMISSION) {
|
||||
std::string errorMessage = "No write permission on the file.";
|
||||
napi_throw_error(env, std::to_string(ErrorCode::WITHOUT_WRITE_PERMISSON).c_str(), errorMessage.c_str());
|
||||
}
|
||||
@ -851,11 +851,11 @@ napi_value StopAppTraceCapture(napi_env env, napi_callback_info info)
|
||||
return CreateUndefined(env);
|
||||
}
|
||||
auto ret = nativeInterface->StopAppTraceCapture();
|
||||
if (ret == SYSTEM_STATUS_ABNORMAL) {
|
||||
if (ret == HIDEBUG_TRACE_ABNORMAL) {
|
||||
std::string errorMessage = "The status of the trace is abnormal";
|
||||
napi_throw_error(env, std::to_string(ErrorCode::SYSTEM_STATUS_ABNORMAL).c_str(), errorMessage.c_str());
|
||||
}
|
||||
if (ret == NO_CAPTURE_TRACE_RUNNING) {
|
||||
if (ret == HIDEBUG_NO_TRACE_RUNNING) {
|
||||
std::string errorMessage = "No capture trace running";
|
||||
napi_throw_error(env, std::to_string(ErrorCode::NO_CAPTURE_TRACE_RUNNING).c_str(), errorMessage.c_str());
|
||||
}
|
||||
|
@ -57,7 +57,9 @@ typedef enum HiDebug_ErrorCode {
|
||||
/** No write permission on the file */
|
||||
HIDEBUG_NO_PERMISSION = 11400103,
|
||||
/** The status of the trace is abnormal */
|
||||
HIDEBUG_TRACE_ABNORMAL = 11400104
|
||||
HIDEBUG_TRACE_ABNORMAL = 11400104,
|
||||
/** No trace running */
|
||||
HIDEBUG_NO_TRACE_RUNNING = 11400105
|
||||
} HiDebug_ErrorCode;
|
||||
|
||||
/**
|
||||
|
@ -474,4 +474,77 @@ describe("HidebugJsTest", function () {
|
||||
expect(error.code === "401").assertTrue();
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* @tc.name: HidebugJsTest_020
|
||||
* @tc.desc: StartAppTraceCapture错误传参测试
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5VY8L
|
||||
*/
|
||||
it('HidebugJsTest_020', 0, function () {
|
||||
console.info("---------------------------HidebugJsTest_020----------------------------------");
|
||||
try {
|
||||
let tags = [hidebug.tags.ABILITY_MANAGER];
|
||||
let flag = 123;
|
||||
let limitSize = 1024 * 1024;
|
||||
let fileName = hidebug.startAppTraceCapture(tags, flag, limitSize);
|
||||
for (let i = 0; i < 3; i++) {
|
||||
hidebug.getSharedDirty();
|
||||
}
|
||||
hidebug.stopAppTraceCapture();
|
||||
expect().assertFail();
|
||||
} catch (error) {
|
||||
console.info(error.code);
|
||||
console.info(error.message);
|
||||
expect(error.code === "401").assertTrue();
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* @tc.name: HidebugJsTest_021
|
||||
* @tc.desc: StartAppTraceCapture重复启动测试
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5VY8L
|
||||
*/
|
||||
it('HidebugJsTest_021', 0, function () {
|
||||
console.info("---------------------------HidebugJsTest_021----------------------------------");
|
||||
let fileName = "";
|
||||
try {
|
||||
let tags = [hidebug.tags.ABILITY_MANAGER];
|
||||
let flag = hidebug.TraceFlag.MAIN_THREAD;
|
||||
let limitSize = 1024 * 1024;
|
||||
fileName = hidebug.startAppTraceCapture(tags, flag, limitSize);
|
||||
for (let i = 0; i < 3; i++) {
|
||||
hidebug.getSharedDirty();
|
||||
}
|
||||
fileName = hidebug.startAppTraceCapture(tags, flag, limitSize);
|
||||
hidebug.stopAppTraceCapture();
|
||||
expect().assertFail();
|
||||
} catch (error) {
|
||||
console.info(error.code);
|
||||
console.info(error.message);
|
||||
if (fileName.length > 0) {
|
||||
hidebug.stopAppTraceCapture();
|
||||
}
|
||||
expect(error.code === "11400102").assertTrue();
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* @tc.name: HidebugJsTest_022
|
||||
* @tc.desc: StartAppTraceCapture未启动直接关闭测试
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5VY8L
|
||||
*/
|
||||
it('HidebugJsTest_022', 0, function () {
|
||||
console.info("---------------------------HidebugJsTest_022----------------------------------");
|
||||
try {
|
||||
hidebug.stopAppTraceCapture();
|
||||
expect().assertFail();
|
||||
} catch (error) {
|
||||
console.info(error.code);
|
||||
console.info(error.message);
|
||||
expect(error.code === "11400105").assertTrue();
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -251,7 +251,58 @@ HWTEST_F(HidebugTest, OH_HiDebug_StartAppTraceCapture1, TestSize.Level1)
|
||||
EXPECT_EQ(OH_HiDebug_StopAppTraceCapture(), HIDEBUG_SUCCESS);
|
||||
} else {
|
||||
EXPECT_EQ(captureResult, HIDEBUG_NO_PERMISSION);
|
||||
EXPECT_EQ(OH_HiDebug_StopAppTraceCapture(), HIDEBUG_TRACE_ABNORMAL);
|
||||
EXPECT_EQ(OH_HiDebug_StopAppTraceCapture(), HIDEBUG_NO_TRACE_RUNNING);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OH_HiDebug_StartAppTraceCapture2
|
||||
* @tc.desc: test OH_HiDebug_StartAppTraceCapture. repeat start app capture trace
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(HidebugTest, OH_HiDebug_StartAppTraceCapture2, TestSize.Level1)
|
||||
{
|
||||
uint32_t fileLength = 256;
|
||||
char fileName[256] = {0};
|
||||
HiDebug_TraceFlag flag = HIDEBUG_TRACE_FLAG_MAIN_THREAD;
|
||||
uint64_t tags = HIDEBUG_TRACE_TAG_COMMON_LIBRARY;
|
||||
uint32_t limitSize = 1024 * 1024;
|
||||
const char* targetPath = "/data/storage/el2/log";
|
||||
auto captureResult = OH_HiDebug_StartAppTraceCapture(flag, tags, limitSize, fileName, fileLength);
|
||||
if (std::filesystem::exists(targetPath)) {
|
||||
EXPECT_EQ(captureResult, HIDEBUG_SUCCESS);
|
||||
auto captureResult2 = OH_HiDebug_StartAppTraceCapture(flag, tags, limitSize, fileName, fileLength);
|
||||
EXPECT_EQ(captureResult2, HIDEBUG_TRACE_CAPTURED_ALREADY);
|
||||
EXPECT_GT(sizeof(fileName) / sizeof(fileName[0]), 1);
|
||||
EXPECT_EQ(OH_HiDebug_StopAppTraceCapture(), HIDEBUG_SUCCESS);
|
||||
} else {
|
||||
EXPECT_EQ(captureResult, HIDEBUG_NO_PERMISSION);
|
||||
EXPECT_EQ(OH_HiDebug_StopAppTraceCapture(), HIDEBUG_NO_TRACE_RUNNING);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OH_HiDebug_StartAppTraceCapture3
|
||||
* @tc.desc: test OH_HiDebug_StartAppTraceCapture. repeat stop app capture trace
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(HidebugTest, OH_HiDebug_StartAppTraceCapture3, TestSize.Level1)
|
||||
{
|
||||
uint32_t fileLength = 256;
|
||||
char fileName[256] = {0};
|
||||
HiDebug_TraceFlag flag = HIDEBUG_TRACE_FLAG_MAIN_THREAD;
|
||||
uint64_t tags = HIDEBUG_TRACE_TAG_COMMON_LIBRARY;
|
||||
uint32_t limitSize = 1024 * 1024;
|
||||
const char* targetPath = "/data/storage/el2/log";
|
||||
auto captureResult = OH_HiDebug_StartAppTraceCapture(flag, tags, limitSize, fileName, fileLength);
|
||||
if (std::filesystem::exists(targetPath)) {
|
||||
EXPECT_EQ(captureResult, HIDEBUG_SUCCESS);
|
||||
EXPECT_GT(sizeof(fileName) / sizeof(fileName[0]), 1);
|
||||
EXPECT_EQ(OH_HiDebug_StopAppTraceCapture(), HIDEBUG_SUCCESS);
|
||||
EXPECT_EQ(OH_HiDebug_StopAppTraceCapture(), HIDEBUG_NO_TRACE_RUNNING);
|
||||
} else {
|
||||
EXPECT_EQ(captureResult, HIDEBUG_NO_PERMISSION);
|
||||
EXPECT_EQ(OH_HiDebug_StopAppTraceCapture(), HIDEBUG_NO_TRACE_RUNNING);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user