max sample rate optimization

Signed-off-by: yuyanqinghw <yuyanqing539@huawei.com>
This commit is contained in:
yuyanqinghw 2024-01-30 15:08:09 +08:00
parent e2e258fa19
commit 29a2f3d80a
3 changed files with 29 additions and 1 deletions

View File

@ -330,6 +330,7 @@ public:
static constexpr size_t BUFFER_CRITICAL_LEVEL = 5 * 1024 * 1024;
static constexpr size_t MAX_BUFFER_SIZE_LITTLE = 128 * 1024 * 1024;
static constexpr size_t MAX_BUFFER_SIZE_LARGE = 256 * 1024 * 1024;
static constexpr uint64_t DEFAULT_EVENT_MAX_SAMPLE_RATE = 8000;
PerfEvents();
~PerfEvents();

View File

@ -748,6 +748,21 @@ void PerfEvents::SetSampleFrequency(unsigned int frequency)
if (frequency > 0) {
sampleFreq_ = frequency;
}
int maxRate = 0;
static bool printFlag = false;
if (!ReadIntFromProcFile("/proc/sys/kernel/perf_event_max_sample_rate", maxRate)) {
printf("read perf_event_max_sample_rate fail.\n");
return;
}
if (sampleFreq_ > maxRate)
{
sampleFreq_ = maxRate;
if (!printFlag)
{
printf("Adjust sampling frequency to maximum allowed frequency %d.\n", maxRate);
printFlag = true;
}
}
}
void PerfEvents::SetSamplePeriod(unsigned int period)

View File

@ -673,7 +673,19 @@ bool SubCommandRecord::SetPerfMaxSampleRate()
{
auto cmp = [](int oldValue, int newValue) { return oldValue == newValue; };
int frequency = frequency_ != 0 ? frequency_ : PerfEvents::DEFAULT_SAMPLE_FREQUNCY;
return SetPerfLimit(PERF_EVENT_MAX_SAMPLE_RATE, frequency, cmp, "hiviewdfx.hiperf.perf_event_max_sample_rate");
int maxRate = 0;
if (!ReadIntFromProcFile(PERF_EVENT_MAX_SAMPLE_RATE, maxRate)) {
printf("read %s fail.\n", PERF_EVENT_MAX_SAMPLE_RATE.c_str());
return false;
}
if (maxRate > frequency)
{
return true;
}
int newRate = frequency > PerfEvents::DEFAULT_EVENT_MAX_SAMPLE_RATE ? frequency :
PerfEvents::DEFAULT_EVENT_MAX_SAMPLE_RATE;
return SetPerfLimit(PERF_EVENT_MAX_SAMPLE_RATE, newRate, cmp,
"hiviewdfx.hiperf.perf_event_max_sample_rate");
}
bool SubCommandRecord::SetPerfEventMlock()