mirror of
https://gitee.com/openharmony/developtools_hiperf
synced 2024-11-23 07:29:42 +00:00
commit
ab6c001845
@ -78,6 +78,7 @@ constexpr const int MULTIPLE_SIZE = 1024;
|
||||
constexpr const uint16_t CHECK_FREQUENCY = 100; //
|
||||
constexpr const uint8_t CHECK_TIMEOUT = 30;
|
||||
constexpr const int INDENT_TWO = 2;
|
||||
constexpr const float ALMOST_ZERO = 0.001;
|
||||
#if !is_mingw
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
@ -165,7 +166,7 @@ void HexDump(const void *buf, size_t size, size_t max_size = 0);
|
||||
|
||||
std::string &StringTrim(std::string &s);
|
||||
|
||||
std::vector<std::string> StringSplit(std::string source, const std::string split = ",");
|
||||
std::vector<std::string> StringSplit(std::string source, const std::string &split = ",");
|
||||
|
||||
size_t SubStringCount(const std::string &source, const std::string &sub);
|
||||
|
||||
|
@ -30,7 +30,7 @@ static std::unique_ptr<HiperfClient::Client> g_hiperfClient =
|
||||
static std::unique_ptr<HiperfClient::RecordOption> g_hiperfRecordOption =
|
||||
std::make_unique<HiperfClient::RecordOption>();
|
||||
|
||||
static std::vector<std::string> StringSplit(std::string source, const std::string split = ",")
|
||||
static std::vector<std::string> StringSplit(std::string source, const std::string &split = ",")
|
||||
{
|
||||
size_t pos = 0;
|
||||
std::vector<std::string> result;
|
||||
@ -51,7 +51,7 @@ static std::vector<std::string> StringSplit(std::string source, const std::strin
|
||||
return result;
|
||||
}
|
||||
|
||||
static std::vector<int> StringSplitToInt(std::string source, const std::string split = ",")
|
||||
static std::vector<int> StringSplitToInt(std::string source, const std::string &split = ",")
|
||||
{
|
||||
size_t pos = 0;
|
||||
std::vector<int> result;
|
||||
|
@ -189,6 +189,7 @@ PerfEvents::~PerfEvents()
|
||||
bool PerfEvents::IsEventSupport(perf_type_id type, __u64 config)
|
||||
{
|
||||
unique_ptr<perf_event_attr> attr = PerfEvents::CreateDefaultAttr(type, config);
|
||||
CHECK_TRUE(attr == nullptr, false, 0, "");
|
||||
UniqueFd fd = Open(*attr.get());
|
||||
if (fd < 0) {
|
||||
printf("event not support %s\n", GetStaticConfigName(type, config).c_str());
|
||||
@ -211,6 +212,7 @@ bool PerfEvents::SetBranchSampleType(uint64_t value)
|
||||
// cpu-clcles event must be supported
|
||||
unique_ptr<perf_event_attr> attr =
|
||||
PerfEvents::CreateDefaultAttr(PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES);
|
||||
CHECK_TRUE(attr == nullptr, false, 0, "");
|
||||
attr->sample_type |= PERF_SAMPLE_BRANCH_STACK;
|
||||
attr->branch_sample_type = value;
|
||||
if (!IsEventAttrSupport(*attr.get())) {
|
||||
@ -246,7 +248,7 @@ bool PerfEvents::AddOffCpuEvent()
|
||||
bool PerfEvents::AddEvents(const std::vector<std::string> &eventStrings, bool group)
|
||||
{
|
||||
bool followGroup = false;
|
||||
HLOGV(" %s %s", VectorToString(eventStrings).c_str(), followGroup ? "followGroup" : "");
|
||||
HLOGV(" %s", VectorToString(eventStrings).c_str());
|
||||
|
||||
for (std::string eventString : eventStrings) {
|
||||
if (!AddEvent(eventString, followGroup)) {
|
||||
@ -465,12 +467,10 @@ bool PerfEvents::AddEvent(perf_type_id type, __u64 config, bool excludeUser, boo
|
||||
}
|
||||
|
||||
eventItem.attr.watermark = 1;
|
||||
if (eventItem.attr.watermark == 1) {
|
||||
eventItem.attr.wakeup_watermark = (mmapPages_ * pageSize_) >> 1;
|
||||
static constexpr unsigned int maxWakeupMark = 1024 * 1024;
|
||||
if (eventItem.attr.wakeup_watermark > maxWakeupMark) {
|
||||
eventItem.attr.wakeup_watermark = maxWakeupMark;
|
||||
}
|
||||
eventItem.attr.wakeup_watermark = (mmapPages_ * pageSize_) >> 1;
|
||||
static constexpr unsigned int maxWakeupMark = 1024 * 1024;
|
||||
if (eventItem.attr.wakeup_watermark > maxWakeupMark) {
|
||||
eventItem.attr.wakeup_watermark = maxWakeupMark;
|
||||
}
|
||||
|
||||
// for a group of events, only enable comm/mmap on the first event
|
||||
@ -657,9 +657,6 @@ bool PerfEvents::StartTracking(bool immediately)
|
||||
HLOGE("PerfEvents::EnableTracking() failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (immediately) {
|
||||
printf("Profiling duration is %.3f seconds.\n", float(timeOut_.count()) / THOUSANDS);
|
||||
printf("Start Profiling...\n");
|
||||
}
|
||||
@ -874,11 +871,11 @@ void PerfEvents::SetSampleFrequency(unsigned int frequency)
|
||||
sampleFreq_ = frequency;
|
||||
}
|
||||
int maxRate = 0;
|
||||
static bool printFlag = false;
|
||||
CHECK_TRUE(!ReadIntFromProcFile("/proc/sys/kernel/perf_event_max_sample_rate", maxRate),
|
||||
NO_RETVAL, LOG_TYPE_PRINTF,
|
||||
"read perf_event_max_sample_rate fail.\n");
|
||||
if (sampleFreq_ > static_cast<unsigned int>(maxRate)) {
|
||||
static bool printFlag = false;
|
||||
sampleFreq_ = static_cast<unsigned int>(maxRate);
|
||||
if (!printFlag) {
|
||||
printf("Adjust sampling frequency to maximum allowed frequency %d.\n", maxRate);
|
||||
@ -1167,7 +1164,7 @@ bool PerfEvents::StatReport(const __u64 &durationInSec)
|
||||
countEvents_[configName]->userOnly = eventItem.attr.exclude_kernel;
|
||||
countEvents_[configName]->kernelOnly = eventItem.attr.exclude_user;
|
||||
}
|
||||
std::unique_ptr<CountEvent> &countEvent = countEvents_[configName];
|
||||
const std::unique_ptr<CountEvent> &countEvent = countEvents_[configName];
|
||||
HLOGM("eventItem.fdItems:%zu", eventItem.fdItems.size());
|
||||
for (const auto &fditem : eventItem.fdItems) {
|
||||
if (read(fditem.fd, &readNoGroupValue, sizeof(readNoGroupValue)) > 0) {
|
||||
@ -1508,7 +1505,7 @@ bool PerfEvents::CutStackAndMove(MmapFd &mmap)
|
||||
size_t dynSizePos = stackSizePos + sizeof(uint64_t) + stackSize;
|
||||
uint64_t dynSize = 0;
|
||||
GetRecordFieldFromMmap(mmap, &dynSize, mmap.mmapPage->data_tail + dynSizePos, sizeof(dynSize));
|
||||
uint64_t newStackSize = std::min((dynSize + alignSize >= 1 ? dynSize + alignSize - 1 : 0) &
|
||||
uint64_t newStackSize = std::min((dynSize + alignSize - 1) &
|
||||
(~(alignSize >= 1 ? alignSize - 1 : 0)), stackSize);
|
||||
if (newStackSize >= stackSize) {
|
||||
return false;
|
||||
|
@ -166,7 +166,7 @@ bool PerfFileWriter::ReadRecords(ProcessRecordCB &callback)
|
||||
if (remainingSize < sizeof(perf_event_header)) {
|
||||
HLOGW("not enough sizeof(perf_event_header).");
|
||||
return false;
|
||||
} else if (Read(buf, sizeof(perf_event_header)) <= 0) {
|
||||
} else if (!Read(buf, sizeof(perf_event_header))) {
|
||||
HLOGW("read perf_event_header failed.");
|
||||
return false;
|
||||
} else {
|
||||
|
@ -401,7 +401,7 @@ bool Report::OutputStdCallFrame(int indent, const std::string_view &funcName, ui
|
||||
|
||||
CHECK_TRUE(heat < option_.callStackHeatLimit_, false, 0, ""); // don't print this three anymore
|
||||
|
||||
if (heat == num) {
|
||||
if (abs(heat - num) < ALMOST_ZERO) {
|
||||
fprintf(output_, "%*s", indent, " ");
|
||||
fprintf(output_, "%*s ", FULL_PERCENTAGE_NUM_LEN, " ");
|
||||
} else {
|
||||
|
@ -54,7 +54,7 @@ bool ReportProtobufFileWriter::Write(const void *buffer, int size)
|
||||
{
|
||||
if (protobufFileStream_->is_open()) {
|
||||
try {
|
||||
protobufFileStream_->write((const char *)buffer, size);
|
||||
protobufFileStream_->write(static_cast<const char *>(buffer), size);
|
||||
HLOGM("writed %d bytes", size);
|
||||
return true;
|
||||
} catch (std::ofstream::failure &writeErr) {
|
||||
|
@ -417,7 +417,7 @@ std::string SubCommandStat::GetDetailComments(const std::unique_ptr<PerfEvents::
|
||||
if (configName == GetCommentConfigName(countEvent, "hw-cpu-cycles")) {
|
||||
if (findRunningTime) {
|
||||
double hz = 0;
|
||||
if (running_time_in_sec != 0) {
|
||||
if (abs(running_time_in_sec) > ALMOST_ZERO) {
|
||||
hz = summary.eventCount / (running_time_in_sec / scale);
|
||||
}
|
||||
comment += hz / 1e9;
|
||||
@ -498,7 +498,7 @@ void SubCommandStat::GetComments(const std::map<std::string, std::unique_ptr<Per
|
||||
((group_id == it->second->id) ||
|
||||
(IsMonitoredAtAllTime(main_scale) && IsMonitoredAtAllTime(scale)))) {
|
||||
double hz = 0;
|
||||
if (running_time_in_sec != 0) {
|
||||
if (abs(running_time_in_sec) > ALMOST_ZERO) {
|
||||
hz = it->second->eventCount / (running_time_in_sec / scale);
|
||||
}
|
||||
comments[configName] = StringPrintf("%lf GHz", hz / 1e9);
|
||||
|
@ -123,7 +123,7 @@ size_t SubStringCount(const std::string &source, const std::string &sub)
|
||||
return count;
|
||||
}
|
||||
|
||||
std::vector<std::string> StringSplit(std::string source, const std::string split)
|
||||
std::vector<std::string> StringSplit(std::string source, const std::string &split)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
|
||||
@ -796,12 +796,12 @@ bool NeedAdaptHMBundlePath(std::string& filename, const std::string& threadname)
|
||||
if (!needCheck) {
|
||||
return false;
|
||||
}
|
||||
std::string path = "/data/storage/el1/bundle";
|
||||
std::string newpath = "/data/app/el1/bundle/public/";
|
||||
const std::string path = "/data/storage/el1/bundle";
|
||||
std::string newFileName = filename;
|
||||
size_t pos = newFileName.find(path);
|
||||
if (pos != std::string::npos) {
|
||||
if (access(filename.c_str(), F_OK) != 0) {
|
||||
const std::string newpath = "/data/app/el1/bundle/public/";
|
||||
// /data/storage/el1/bundle/libs/arm64/libentry.so
|
||||
newFileName.replace(pos, path.length(), newpath + threadname);
|
||||
if (access(newFileName.c_str(), F_OK) != 0) {
|
||||
|
@ -790,6 +790,7 @@ void VirtualRuntime::UpdateFromRecord(PerfRecordAuxtrace &recordAuxTrace)
|
||||
#if defined(is_ohos) && is_ohos
|
||||
recordAuxTrace.DumpLog(__FUNCTION__);
|
||||
SpeDecoder *decoder = SpeDecoderDataNew(recordAuxTrace.rawData_, recordAuxTrace.data_.size);
|
||||
CHECK_TRUE(decoder == nullptr, NO_RETVAL, 0, "");
|
||||
std::vector<SpeRecord> records;
|
||||
while (true) {
|
||||
int ret = SpeDecode(decoder);
|
||||
@ -829,6 +830,7 @@ void VirtualRuntime::SymbolSpeRecord(PerfRecordAuxtrace &recordAuxTrace)
|
||||
#if defined(is_ohos) && is_ohos
|
||||
recordAuxTrace.DumpLog(__FUNCTION__);
|
||||
SpeDecoder *decoder = SpeDecoderDataNew(recordAuxTrace.rawData_, recordAuxTrace.data_.size);
|
||||
CHECK_TRUE(decoder == nullptr, NO_RETVAL, 0, "");
|
||||
while (true) {
|
||||
int ret = SpeDecode(decoder);
|
||||
if (ret <= 0) {
|
||||
|
@ -305,7 +305,6 @@ void VirtualThread::ParseDevhostMap(pid_t devhost)
|
||||
std::string mapPath = StringPrintf("/proc/%d/maps", devhost);
|
||||
std::string mapContent = ReadFileToString(mapPath);
|
||||
std::string filename;
|
||||
uint64_t begin, end, offset;
|
||||
if (mapContent.size() > 0) {
|
||||
std::istringstream s(mapContent);
|
||||
std::string line;
|
||||
@ -324,6 +323,7 @@ void VirtualThread::ParseDevhostMap(pid_t devhost)
|
||||
if (addrRanges.size() != mmapAddrRangeToken) {
|
||||
continue;
|
||||
}
|
||||
uint64_t begin, end, offset;
|
||||
// 2fe40000 / 311e1000
|
||||
try {
|
||||
begin = std::stoull(addrRanges[0], nullptr, NUMBER_FORMAT_HEX_BASE);
|
||||
|
@ -44,15 +44,17 @@ public:
|
||||
|
||||
std::unique_ptr<PerfFileReaderFuzzer> reader =
|
||||
std::make_unique<PerfFileReaderFuzzer>(resolvedPath, fp);
|
||||
|
||||
if (!reader->ReadFileHeader()) {
|
||||
printf("head read error\n");
|
||||
(void)fclose(fp);
|
||||
return nullptr;
|
||||
}
|
||||
if (!reader->ReadAttrSection()) {
|
||||
printf("attr read error\n");
|
||||
(void)fclose(fp);
|
||||
return nullptr;
|
||||
}
|
||||
(void)fclose(fp);
|
||||
return reader;
|
||||
};
|
||||
};
|
||||
|
@ -75,10 +75,8 @@ bool PerfEventsTest::RecordCount(std::unique_ptr<PerfEventRecord> record)
|
||||
{
|
||||
g_recordCount++;
|
||||
if (record->GetType() == PERF_RECORD_SAMPLE) {
|
||||
if (record->GetType() == PERF_RECORD_SAMPLE) {
|
||||
// the record is allowed from a cache memory, does not free memory after use
|
||||
record.release();
|
||||
}
|
||||
// the record is allowed from a cache memory, does not free memory after use
|
||||
record.release();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -35,13 +35,13 @@ public:
|
||||
static void CompareEventDesc(const std::vector<AttrWithId> &a,
|
||||
const std::vector<AttrWithId> &b);
|
||||
|
||||
static const int BIGK = 1024;
|
||||
static const uint32_t BIGK = 1024;
|
||||
static const uint32_t TESTNUMBER1 = 1;
|
||||
static const uint32_t TESTNUMBER2 = 2;
|
||||
static const uint32_t TESTNUMBER3 = 3;
|
||||
static const uint32_t TESTNUMBER4 = 4;
|
||||
static const uint32_t TESTNUMBER5 = 5;
|
||||
static const int TWO = 2;
|
||||
static const int TESTNUMBER1 = 1;
|
||||
static const int TESTNUMBER2 = 2;
|
||||
static const int TESTNUMBER3 = 3;
|
||||
static const int TESTNUMBER4 = 4;
|
||||
static const int TESTNUMBER5 = 5;
|
||||
};
|
||||
|
||||
void PerfFileFormatTest::SetUpTestCase() {}
|
||||
|
@ -34,11 +34,11 @@ public:
|
||||
void TearDown();
|
||||
|
||||
static void TestEventDescInit(std::vector<AttrWithId> &eventDesc);
|
||||
static const int TESTNUMBER1 = 1;
|
||||
static const int TESTNUMBER2 = 2;
|
||||
static const int TESTNUMBER3 = 3;
|
||||
static const int TESTNUMBER4 = 4;
|
||||
static const int TESTNUMBER5 = 5;
|
||||
static const uint32_t TESTNUMBER1 = 1;
|
||||
static const uint32_t TESTNUMBER2 = 2;
|
||||
static const uint32_t TESTNUMBER3 = 3;
|
||||
static const uint32_t TESTNUMBER4 = 4;
|
||||
static const uint32_t TESTNUMBER5 = 5;
|
||||
};
|
||||
|
||||
void PerfFileWriterTest::SetUpTestCase() {}
|
||||
|
@ -105,8 +105,6 @@ HWTEST_F(ReportTest, ReportItemCallFrameSame, TestSize.Level1)
|
||||
ReportItemCallFrame aDiffDso("a", 0, "aa1234", 0, 1234);
|
||||
ReportItemCallFrame b("b", 0x0, "bb", 0, 0);
|
||||
|
||||
EXPECT_EQ(a == a, true);
|
||||
EXPECT_EQ(a != a, false);
|
||||
EXPECT_EQ(a == aDuplicated, true);
|
||||
EXPECT_EQ(a == a2, false);
|
||||
EXPECT_EQ(a == aDiffAddr, false);
|
||||
@ -182,8 +180,6 @@ HWTEST_F(ReportTest, ReportItemSame, TestSize.Level1)
|
||||
ReportItem aDiffVaddr(1, 2, "comm", "dso", "func", 0x1230, 1000);
|
||||
ReportItem aDiffEventCount(1, 2, "comm", "dso", "func", 0x123, 10000);
|
||||
|
||||
EXPECT_EQ(a == a, true);
|
||||
EXPECT_EQ(a != a, false);
|
||||
EXPECT_EQ(a == aDuplicated, true);
|
||||
|
||||
EXPECT_EQ(a == aDiffPid, false);
|
||||
|
Loading…
Reference in New Issue
Block a user