mirror of
https://gitee.com/openharmony/developtools_hiperf
synced 2024-11-26 17:21:15 +00:00
commit
5da5a213eb
@ -65,6 +65,7 @@ public:
|
||||
bool ReadDataSection(ProcessRecordCB &callback);
|
||||
bool ReadRecords(ProcessRecordCB &callback);
|
||||
bool Read(void *buf, size_t len);
|
||||
void SetWriteRecordStat(bool isWrite);
|
||||
|
||||
private:
|
||||
std::string fileBuffer_;
|
||||
|
@ -214,6 +214,11 @@ bool PerfFileWriter::Read(void *buf, size_t len)
|
||||
return true;
|
||||
}
|
||||
|
||||
void PerfFileWriter::SetWriteRecordStat(bool isWrite)
|
||||
{
|
||||
isWritingRecord = isWrite;
|
||||
}
|
||||
|
||||
uint64_t PerfFileWriter::GetDataSize() const
|
||||
{
|
||||
return dataSection_.size;
|
||||
|
@ -1260,6 +1260,10 @@ bool SubCommandRecord::OnSubCommand(std::vector<std::string> &args)
|
||||
}
|
||||
HIPERF_HILOGI(MODULE_DEFAULT, "SubCommandRecord perfEvents tracking finish");
|
||||
|
||||
if (isSpe_) {
|
||||
HLOGD("stop write spe record");
|
||||
fileWriter_->SetWriteRecordStat(false);
|
||||
}
|
||||
startSaveFileTimes_ = steady_clock::now();
|
||||
if (!FinishWriteRecordFile()) {
|
||||
HLOGE("Fail to finish record file %s", outputFilename_.c_str());
|
||||
|
@ -651,6 +651,10 @@ bool SubCommandStat::OnSubCommand(std::vector<std::string> &args)
|
||||
HLOGV("CheckAppIsRunning() failed");
|
||||
return false;
|
||||
}
|
||||
if (!CheckOptionPid(selectPids_)) {
|
||||
HLOGV("CheckOptionPid() failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
perfEvents_.SetCpu(selectCpus_);
|
||||
std::vector<pid_t> pids;
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <condition_variable>
|
||||
#include <cstdlib>
|
||||
#include <mutex>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
@ -2245,10 +2246,24 @@ HWTEST_F(SubCommandStatTest, TestOnSubCommand_app_running, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(SubCommandStatTest, CheckPidAndApp, TestSize.Level1)
|
||||
{
|
||||
pid_t existPid = -1;
|
||||
const std::string basePath {"/proc/"};
|
||||
std::vector<std::string> subDirs = GetSubDirs(basePath);
|
||||
for (const auto &subDir : subDirs) {
|
||||
if (!IsDigits(subDir)) {
|
||||
continue;
|
||||
}
|
||||
pid_t pid = std::stoll(subDir);
|
||||
existPid = max(existPid, pid);
|
||||
}
|
||||
std::string cmd = "stat -p " + std::to_string(existPid + rand() % 100 + 1) + " -d 2";
|
||||
EXPECT_EQ(Command::DispatchCommand(cmd), false);
|
||||
|
||||
StdoutRecord stdoutRecord;
|
||||
stdoutRecord.Start();
|
||||
const auto startTime = chrono::steady_clock::now();
|
||||
EXPECT_EQ(Command::DispatchCommand("stat -p 700001 -d 2"), true);
|
||||
std::string existCmd = "stat -p " + std::to_string(existPid) + " -d 2";
|
||||
EXPECT_EQ(Command::DispatchCommand(existCmd), true);
|
||||
const auto costMs = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
chrono::steady_clock::now() - startTime);
|
||||
EXPECT_LE(costMs.count(), defaultRunTimeoutMs);
|
||||
|
Loading…
Reference in New Issue
Block a user