mirror of
https://gitee.com/openharmony/hiviewdfx_hitrace
synced 2024-11-23 07:49:43 +00:00
fix: 对trace文件移除的结果进行判断,并添加日志记录及用例看护
Signed-off-by: jiangwei <jiangwei214@h-partners.com>
This commit is contained in:
parent
89a7f77bdb
commit
53605d410c
@ -589,7 +589,8 @@ bool WriteFile(uint8_t contentType, const std::string &src, int outFd, const std
|
||||
if (traceEndTime < pageTraceTime) {
|
||||
endFlag = true;
|
||||
readBytes = 0;
|
||||
HILOG_ERROR(LOG_CORE, "Current pageTraceTime:(%{public}" PRId64 ") is larger than traceEndTime:(%{public}" PRId64 "), stop to read trace info.",
|
||||
HILOG_INFO(LOG_CORE,
|
||||
"Current pageTraceTime:(%{public}" PRId64 ") is larger than traceEndTime:(%{public}" PRId64 ")",
|
||||
pageTraceTime, traceEndTime);
|
||||
break;
|
||||
}
|
||||
@ -1105,7 +1106,11 @@ TraceErrorCode DumpTraceInner(std::vector<std::string> &outputFiles)
|
||||
}
|
||||
|
||||
if (g_dumpStatus) {
|
||||
remove(reOutPath.c_str());
|
||||
if (remove(reOutPath.c_str()) == 0) {
|
||||
HILOG_INFO(LOG_CORE, "Delete outpath:%{public}s success.", reOutPath.c_str());
|
||||
} else {
|
||||
HILOG_INFO(LOG_CORE, "Delete outpath:%{public}s failed.", reOutPath.c_str());
|
||||
}
|
||||
return static_cast<TraceErrorCode>(g_dumpStatus.load());
|
||||
}
|
||||
|
||||
@ -1492,7 +1497,8 @@ TraceRetInfo DumpTrace(int maxDuration, uint64_t traceEndTime)
|
||||
// beware of input precision of seconds: add an extra second of tolerance
|
||||
g_inputTraceEndTime = (traceEndTime - static_cast<uint64_t>(boot_time) + 1) * S_TO_NS;
|
||||
} else {
|
||||
HILOG_ERROR(LOG_CORE, "DumpTrace: traceEndTime:(%{public}" PRId64 ") is earlier than boot_time:(%{public}" PRId64 ").",
|
||||
HILOG_ERROR(LOG_CORE,
|
||||
"DumpTrace: traceEndTime:(%{public}" PRId64 ") is earlier than boot_time:(%{public}" PRId64 ").",
|
||||
traceEndTime, static_cast<uint64_t>(boot_time));
|
||||
ret.errorCode = OUT_OF_TIME;
|
||||
return ret;
|
||||
|
@ -245,6 +245,7 @@ HWTEST_F(HitraceDumpTest, DumpTraceTest_004, TestSize.Level0)
|
||||
uint64_t traceEndTime = 1;
|
||||
TraceRetInfo ret = DumpTrace(0, traceEndTime);
|
||||
ASSERT_TRUE(ret.errorCode == TraceErrorCode::OUT_OF_TIME);
|
||||
ASSERT_TRUE(ret.outputFiles.empty());
|
||||
ASSERT_TRUE(CloseTrace() == TraceErrorCode::SUCCESS);
|
||||
|
||||
ASSERT_TRUE(OpenTrace(tagGroups) == TraceErrorCode::SUCCESS);
|
||||
@ -272,6 +273,7 @@ HWTEST_F(HitraceDumpTest, DumpTraceTest_004, TestSize.Level0)
|
||||
maxDuration = 10;
|
||||
ret = DumpTrace(maxDuration, traceEndTime);
|
||||
ASSERT_TRUE(ret.errorCode == TraceErrorCode::OUT_OF_TIME);
|
||||
ASSERT_TRUE(ret.outputFiles.empty());
|
||||
ASSERT_TRUE(CloseTrace() == TraceErrorCode::SUCCESS);
|
||||
|
||||
ASSERT_TRUE(OpenTrace(tagGroups) == TraceErrorCode::SUCCESS);
|
||||
@ -279,6 +281,7 @@ HWTEST_F(HitraceDumpTest, DumpTraceTest_004, TestSize.Level0)
|
||||
maxDuration = 10;
|
||||
ret = DumpTrace(maxDuration, traceEndTime);
|
||||
ASSERT_TRUE(ret.errorCode == TraceErrorCode::OUT_OF_TIME);
|
||||
ASSERT_TRUE(ret.outputFiles.empty());
|
||||
ASSERT_TRUE(CloseTrace() == TraceErrorCode::SUCCESS);
|
||||
|
||||
ASSERT_TRUE(OpenTrace(tagGroups) == TraceErrorCode::SUCCESS);
|
||||
@ -302,6 +305,7 @@ HWTEST_F(HitraceDumpTest, DumpTraceTest_005, TestSize.Level0)
|
||||
uint64_t traceEndTime = static_cast<uint64_t>(std::time(nullptr)) - 20; // current time - 20 seconds
|
||||
TraceRetInfo ret = DumpTrace(0, traceEndTime);
|
||||
ASSERT_TRUE(ret.errorCode == TraceErrorCode::OUT_OF_TIME);
|
||||
ASSERT_TRUE(ret.outputFiles.empty());
|
||||
ASSERT_TRUE(CloseTrace() == TraceErrorCode::SUCCESS);
|
||||
|
||||
ASSERT_TRUE(OpenTrace(tagGroups) == TraceErrorCode::SUCCESS);
|
||||
@ -310,6 +314,7 @@ HWTEST_F(HitraceDumpTest, DumpTraceTest_005, TestSize.Level0)
|
||||
int maxDuration = 10;
|
||||
ret = DumpTrace(maxDuration, traceEndTime);
|
||||
ASSERT_TRUE(ret.errorCode == TraceErrorCode::OUT_OF_TIME);
|
||||
ASSERT_TRUE(ret.outputFiles.empty());
|
||||
ASSERT_TRUE(CloseTrace() == TraceErrorCode::SUCCESS);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user