From fbf943866e7faad7ec7328ebab78179c1ca2b5b4 Mon Sep 17 00:00:00 2001 From: DCHii <13780064348@163.com> Date: Fri, 10 May 2024 16:53:48 +0800 Subject: [PATCH] Modifying data structures to adapt to hotspot functions --- include/pmu.h | 2 +- pmu/pmu.cpp | 1 + pmu/pmu_event.h | 1 + pmu/sampler.cpp | 9 +++++++-- symbol/symbol_resolve.cpp | 2 +- util/linked_list.h | 16 ++++++++++++++++ 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/include/pmu.h b/include/pmu.h index bb7cb3a..f2cb590 100644 --- a/include/pmu.h +++ b/include/pmu.h @@ -80,7 +80,7 @@ struct PmuAttr { unsigned excludeUser : 1; // don't count user unsigned excludeKernel : 1; // don't count kernel enum SymbolMode symbolMode; // refer to comments of SymbolMode - + unsigned callStack : 1; // collect complete call stack // SPE related fields. enum SpeFilter dataFilter; // spe data filter enum SpeEventFilter evFilter; // spe event filter diff --git a/pmu/pmu.cpp b/pmu/pmu.cpp index e2b0a46..0b50c3c 100644 --- a/pmu/pmu.cpp +++ b/pmu/pmu.cpp @@ -616,6 +616,7 @@ static struct PmuTaskAttr* AssignTaskParam(PmuTaskType collectType, PmuAttr *att taskParam->pmuEvt->period = attr->period; taskParam->pmuEvt->excludeKernel = attr->excludeKernel; taskParam->pmuEvt->excludeUser = attr->excludeUser; + taskParam->pmuEvt->callStack = attr->callStack; return taskParam.release(); } diff --git a/pmu/pmu_event.h b/pmu/pmu_event.h index 992fa3a..a80b1fa 100644 --- a/pmu/pmu_event.h +++ b/pmu/pmu_event.h @@ -39,6 +39,7 @@ struct PmuEvt { int cpumask; // a representative CPU number for each socket (package) in the motherboard. unsigned excludeUser : 1; // don't count user unsigned excludeKernel : 1; // don't count kernel + unsigned callStack : 1; // collect complete call stack union { unsigned period; // sample period unsigned freq; // sample frequency diff --git a/pmu/sampler.cpp b/pmu/sampler.cpp index f8ad789..3fd1a17 100644 --- a/pmu/sampler.cpp +++ b/pmu/sampler.cpp @@ -131,9 +131,14 @@ void KUNPENG_PMU::PerfSampler::RawSampleProcess( KUNPENG_PMU::PerfRawSample *sample = (KUNPENG_PMU::PerfRawSample *)event->sample.array; if (symMode != NO_SYMBOL_RESOLVE) { // Copy ips from ring buffer and get stack info later. - for (__u64 i = 0; i < sample->nr; ++i) { - ips->ips.push_back(sample->ips[i]); + if (evt->callStack == 0 && sample->nr - 1 >= 0) { + ips->ips.push_back(sample->ips[sample->nr - 1]); + } else { + for (int i = sample->nr - 1; i >= 0; --i) { + ips->ips.push_back(sample->ips[i]); + } } + } current->cpu = static_cast(sample->cpu); current->pid = static_cast(sample->pid); diff --git a/symbol/symbol_resolve.cpp b/symbol/symbol_resolve.cpp index 79e97ea..7c0da16 100644 --- a/symbol/symbol_resolve.cpp +++ b/symbol/symbol_resolve.cpp @@ -817,7 +817,7 @@ struct Stack* SymbolResolve::StackToHash(int pid, unsigned long* stack, int nr) } else { current->symbol = nullptr; } - AddTail(&head, ¤t); + AddDoubleLinkedTail(&head, ¤t); } if (this->stackMap.at(pid).find(stackId) == this->stackMap.at(pid).end()) { diff --git a/util/linked_list.h b/util/linked_list.h index 2a2cd50..ea0e687 100644 --- a/util/linked_list.h +++ b/util/linked_list.h @@ -55,6 +55,22 @@ void AddTail(ListNode** head, ListNode** newNode) } } +// Function to add a node at the tail of the double linked list +template +void AddDoubleLinkedTail(ListNode** head, ListNode** newNode) +{ + if (*head == nullptr) { + *head = *newNode; + } else { + ListNode* current = *head; + while (current->next != nullptr) { + current = current->next; + } + current->next = *newNode; + (*newNode)->prev = current; + } +} + // Function to free the linked list template void FreeList(ListNode** head) -- Gitee