From d9cf35e3b7e4cb074e08c9425c7bd7c55318d090 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 4 Jul 2024 09:14:15 +0800 Subject: [PATCH 01/10] =?UTF-8?q?fix:=20=E5=B0=86std::bind=E5=92=8Cstd::th?= =?UTF-8?q?read=E4=BF=AE=E6=94=B9=E4=B8=BA=E5=8C=BF=E5=90=8D=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: root --- demo/cpp/hiperf_demo.cpp | 5 ++++- src/report.cpp | 10 ++++++++-- src/subcommand_record.cpp | 21 ++++++++++++++++----- src/subcommand_report.cpp | 5 ++++- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/demo/cpp/hiperf_demo.cpp b/demo/cpp/hiperf_demo.cpp index 3e438e3..3590a7b 100644 --- a/demo/cpp/hiperf_demo.cpp +++ b/demo/cpp/hiperf_demo.cpp @@ -69,7 +69,10 @@ int main() if (myHiperf.Start(opt)) { printf("demo start successfully\n"); } - std::thread workload(TestCodeThread, 0); + auto it = []() { + TestCodeThread(0); + } + std::thread workload(it); sleep(waitTime); // try for each thread times for (int i = 0; i < countTry; i++) { diff --git a/src/report.cpp b/src/report.cpp index 7bbeaf0..f536c46 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -121,7 +121,10 @@ void Report::StatisticsRecords() // merge duplicate HLOGD("uniquing %zu", totalReportCount); auto last = std::unique(config.reportItems_.begin(), config.reportItems_.end(), - std::bind(&Report::MultiLevelSameAndUpdateCount, this, _1, _2)); + // std::bind(&Report::MultiLevelSameAndUpdateCount, this, _1, _2)); + [this] (ReportItem &l, ReportItem &r) -> bool { + return this->MultiLevelSameAndUpdateCount(l, r); + }); config.reportItems_.erase(last, config.reportItems_.end()); @@ -196,7 +199,10 @@ void Report::AdjustReportItems() // sort first. HLOGD("MultiLevelSorting %" PRIu64 "", totalReportCount); std::sort(config.reportItems_.begin(), config.reportItems_.end(), - std::bind(&Report::MultiLevelSorting, this, _1, _2)); + // std::bind(&Report::MultiLevelSorting, this, _1, _2)); + [this] (const ReportItem &a, const ReportItem &b) -> bool { + return this->MultiLevelSorting(std::move(a), std::move(b)); + }); HLOGD("MultiLevelSorting %" PRIu64 " done", totalReportCount); // reorder the callstack if (option_.debug_) { diff --git a/src/subcommand_record.cpp b/src/subcommand_record.cpp index dbd89c6..f3a734a 100644 --- a/src/subcommand_record.cpp +++ b/src/subcommand_record.cpp @@ -774,7 +774,10 @@ void SubCommandRecord::RecoverSavedCmdlinesSize() bool SubCommandRecord::PreparePerfEvent() { // we need to notify perfEvents_ sampling mode by SetRecordCallBack first - auto processRecord = std::bind(&SubCommandRecord::ProcessRecord, this, std::placeholders::_1); + // auto processRecord = std::bind(&SubCommandRecord::ProcessRecord, this, std::placeholders::_1); + auto processRecord = [this](std::unique_ptr record) -> bool { + return this->ProcessRecord(std::move(record)); + }; perfEvents_.SetRecordCallBack(processRecord); perfEvents_.SetCpu(selectCpus_); @@ -873,7 +876,10 @@ bool SubCommandRecord::PrepareSysKernel() bool SubCommandRecord::PrepareVirtualRuntime() { - auto saveRecord = std::bind(&SubCommandRecord::SaveRecord, this, std::placeholders::_1, false); + // auto saveRecord = std::bind(&SubCommandRecord::SaveRecord, this, std::placeholders::_1, false); + auto saveRecord = [this](std::unique_ptr record) -> bool { + return this->SaveRecord(std::move(record), false); + }; virtualRuntime_.SetRecordMode(saveRecord); // do some config for virtualRuntime_ @@ -906,8 +912,10 @@ bool SubCommandRecord::PrepareVirtualRuntime() } if (dedupStack_) { virtualRuntime_.SetDedupStack(); - auto collectSymbol = - std::bind(&SubCommandRecord::CollectSymbol, this, std::placeholders::_1); + auto collectSymbol = [this](PerfRecordSample *sample) { + this->SaveRecord((std::unique_ptr)sample, false); + }; + // std::bind(&SubCommandRecord::CollectSymbol, this, std::placeholders::_1); virtualRuntime_.SetCollectSymbolCallBack(collectSymbol); } return true; @@ -1713,7 +1721,10 @@ bool SubCommandRecord::FinishWriteRecordFile() virtualRuntime_.CollectDedupSymbol(kernelSymbolsHits_, userSymbolsHits_); } else { fileWriter_->ReadDataSection( - std::bind(&SubCommandRecord::CollectionSymbol, this, std::placeholders::_1)); + // std::bind(&SubCommandRecord::CollectionSymbol, this, std::placeholders::_1)); + [this] (std::unique_ptr record) -> bool { + return this->CollectionSymbol(std::move(record)); + }); } #if USE_COLLECT_SYMBOLIC SymbolicHits(); diff --git a/src/subcommand_report.cpp b/src/subcommand_report.cpp index 44ded84..84f41ae 100644 --- a/src/subcommand_report.cpp +++ b/src/subcommand_report.cpp @@ -482,7 +482,10 @@ bool SubCommandReport::LoadPerfData() // before load data section SetHM(); recordFileReader_->ReadDataSection( - std::bind(&SubCommandReport::RecordCallBack, this, std::placeholders::_1)); + [this] (std::unique_ptr record) -> bool { + return this->RecordCallBack(std::move(record)); + }); + // std::bind(&SubCommandReport::RecordCallBack, this, std::placeholders::_1)); if (cpuOffMode_) { FlushCacheRecord(); } From f21935b55109202db962bc488bf7f62616fce203 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 4 Jul 2024 09:36:50 +0800 Subject: [PATCH 02/10] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: root --- src/subcommand_record.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/subcommand_record.cpp b/src/subcommand_record.cpp index f3a734a..73ca6c0 100644 --- a/src/subcommand_record.cpp +++ b/src/subcommand_record.cpp @@ -774,7 +774,6 @@ void SubCommandRecord::RecoverSavedCmdlinesSize() bool SubCommandRecord::PreparePerfEvent() { // we need to notify perfEvents_ sampling mode by SetRecordCallBack first - // auto processRecord = std::bind(&SubCommandRecord::ProcessRecord, this, std::placeholders::_1); auto processRecord = [this](std::unique_ptr record) -> bool { return this->ProcessRecord(std::move(record)); }; @@ -876,7 +875,6 @@ bool SubCommandRecord::PrepareSysKernel() bool SubCommandRecord::PrepareVirtualRuntime() { - // auto saveRecord = std::bind(&SubCommandRecord::SaveRecord, this, std::placeholders::_1, false); auto saveRecord = [this](std::unique_ptr record) -> bool { return this->SaveRecord(std::move(record), false); }; From 7a969cc802979ae862dcfb29304d2edf5f0a0694 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 4 Jul 2024 15:02:02 +0800 Subject: [PATCH 03/10] =?UTF-8?q?fix=EF=BC=9A=E6=8C=89=E7=85=A7=E6=84=8F?= =?UTF-8?q?=E8=A7=81=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: root --- src/report.cpp | 7 +++---- src/subcommand_record.cpp | 4 +--- src/subcommand_report.cpp | 1 - 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/report.cpp b/src/report.cpp index f536c46..2b3a319 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -199,10 +199,9 @@ void Report::AdjustReportItems() // sort first. HLOGD("MultiLevelSorting %" PRIu64 "", totalReportCount); std::sort(config.reportItems_.begin(), config.reportItems_.end(), - // std::bind(&Report::MultiLevelSorting, this, _1, _2)); - [this] (const ReportItem &a, const ReportItem &b) -> bool { - return this->MultiLevelSorting(std::move(a), std::move(b)); - }); + [this] (const ReportItem &a, const ReportItem &b) -> bool { + return this->MultiLevelSorting(std::move(a), std::move(b)); + }); HLOGD("MultiLevelSorting %" PRIu64 " done", totalReportCount); // reorder the callstack if (option_.debug_) { diff --git a/src/subcommand_record.cpp b/src/subcommand_record.cpp index 73ca6c0..02891a7 100644 --- a/src/subcommand_record.cpp +++ b/src/subcommand_record.cpp @@ -913,7 +913,6 @@ bool SubCommandRecord::PrepareVirtualRuntime() auto collectSymbol = [this](PerfRecordSample *sample) { this->SaveRecord((std::unique_ptr)sample, false); }; - // std::bind(&SubCommandRecord::CollectSymbol, this, std::placeholders::_1); virtualRuntime_.SetCollectSymbolCallBack(collectSymbol); } return true; @@ -1719,9 +1718,8 @@ bool SubCommandRecord::FinishWriteRecordFile() virtualRuntime_.CollectDedupSymbol(kernelSymbolsHits_, userSymbolsHits_); } else { fileWriter_->ReadDataSection( - // std::bind(&SubCommandRecord::CollectionSymbol, this, std::placeholders::_1)); [this] (std::unique_ptr record) -> bool { - return this->CollectionSymbol(std::move(record)); + return this->CollectionSymbol(std::move(record)); }); } #if USE_COLLECT_SYMBOLIC diff --git a/src/subcommand_report.cpp b/src/subcommand_report.cpp index 84f41ae..ce78cbe 100644 --- a/src/subcommand_report.cpp +++ b/src/subcommand_report.cpp @@ -485,7 +485,6 @@ bool SubCommandReport::LoadPerfData() [this] (std::unique_ptr record) -> bool { return this->RecordCallBack(std::move(record)); }); - // std::bind(&SubCommandReport::RecordCallBack, this, std::placeholders::_1)); if (cpuOffMode_) { FlushCacheRecord(); } From cdf1c85118e3894480cdcb12a3238abf231bc294 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 4 Jul 2024 15:43:58 +0800 Subject: [PATCH 04/10] =?UTF-8?q?fix=EF=BC=9A=E6=8C=89=E7=85=A7=E6=84=8F?= =?UTF-8?q?=E8=A7=81=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: root --- src/report.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/report.cpp b/src/report.cpp index 2b3a319..2943022 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -199,9 +199,9 @@ void Report::AdjustReportItems() // sort first. HLOGD("MultiLevelSorting %" PRIu64 "", totalReportCount); std::sort(config.reportItems_.begin(), config.reportItems_.end(), - [this] (const ReportItem &a, const ReportItem &b) -> bool { - return this->MultiLevelSorting(std::move(a), std::move(b)); - }); + [this] (const ReportItem &a, const ReportItem &b) -> bool { + return this->MultiLevelSorting(std::move(a), std::move(b)); + }); HLOGD("MultiLevelSorting %" PRIu64 " done", totalReportCount); // reorder the callstack if (option_.debug_) { From bd312128d3a1e3e5628dcdd5b99cd04a1bb3d524 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 4 Jul 2024 16:01:49 +0800 Subject: [PATCH 05/10] =?UTF-8?q?fix=EF=BC=9A=E6=8C=89=E7=85=A7=E6=84=8F?= =?UTF-8?q?=E8=A7=81=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: root --- src/report.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/report.cpp b/src/report.cpp index 2943022..4486e6d 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -121,10 +121,9 @@ void Report::StatisticsRecords() // merge duplicate HLOGD("uniquing %zu", totalReportCount); auto last = std::unique(config.reportItems_.begin(), config.reportItems_.end(), - // std::bind(&Report::MultiLevelSameAndUpdateCount, this, _1, _2)); - [this] (ReportItem &l, ReportItem &r) -> bool { - return this->MultiLevelSameAndUpdateCount(l, r); - }); + [this] (ReportItem &l, ReportItem &r) -> bool { + return this->MultiLevelSameAndUpdateCount(l, r); + }); config.reportItems_.erase(last, config.reportItems_.end()); @@ -199,9 +198,9 @@ void Report::AdjustReportItems() // sort first. HLOGD("MultiLevelSorting %" PRIu64 "", totalReportCount); std::sort(config.reportItems_.begin(), config.reportItems_.end(), - [this] (const ReportItem &a, const ReportItem &b) -> bool { - return this->MultiLevelSorting(std::move(a), std::move(b)); - }); + [this] (const ReportItem &a, const ReportItem &b) -> bool { + return this->MultiLevelSorting(std::move(a), std::move(b)); + }); HLOGD("MultiLevelSorting %" PRIu64 " done", totalReportCount); // reorder the callstack if (option_.debug_) { From 8ec9b84a93bc3eebce4b23b9950a79589baa15fd Mon Sep 17 00:00:00 2001 From: root Date: Thu, 4 Jul 2024 16:11:53 +0800 Subject: [PATCH 06/10] =?UTF-8?q?fix=EF=BC=9A=E6=8C=89=E7=85=A7=E6=84=8F?= =?UTF-8?q?=E8=A7=81=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: root --- src/report.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/report.cpp b/src/report.cpp index 4486e6d..a395089 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -198,9 +198,9 @@ void Report::AdjustReportItems() // sort first. HLOGD("MultiLevelSorting %" PRIu64 "", totalReportCount); std::sort(config.reportItems_.begin(), config.reportItems_.end(), - [this] (const ReportItem &a, const ReportItem &b) -> bool { - return this->MultiLevelSorting(std::move(a), std::move(b)); - }); + [this] (const ReportItem &a, const ReportItem &b) -> bool { + return this->MultiLevelSorting(std::move(a), std::move(b)); + }); HLOGD("MultiLevelSorting %" PRIu64 " done", totalReportCount); // reorder the callstack if (option_.debug_) { From e64ff03b8ec600f7bbc5c796d002fecb82ddad3c Mon Sep 17 00:00:00 2001 From: root Date: Thu, 4 Jul 2024 16:26:54 +0800 Subject: [PATCH 07/10] =?UTF-8?q?fix=EF=BC=9A=E6=8C=89=E7=85=A7=E6=84=8F?= =?UTF-8?q?=E8=A7=81=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: root --- src/report.cpp | 2 +- src/subcommand_record.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/report.cpp b/src/report.cpp index a395089..16f0063 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -200,7 +200,7 @@ void Report::AdjustReportItems() std::sort(config.reportItems_.begin(), config.reportItems_.end(), [this] (const ReportItem &a, const ReportItem &b) -> bool { return this->MultiLevelSorting(std::move(a), std::move(b)); - }); + }); HLOGD("MultiLevelSorting %" PRIu64 " done", totalReportCount); // reorder the callstack if (option_.debug_) { diff --git a/src/subcommand_record.cpp b/src/subcommand_record.cpp index 02891a7..d3cfeee 100644 --- a/src/subcommand_record.cpp +++ b/src/subcommand_record.cpp @@ -911,7 +911,7 @@ bool SubCommandRecord::PrepareVirtualRuntime() if (dedupStack_) { virtualRuntime_.SetDedupStack(); auto collectSymbol = [this](PerfRecordSample *sample) { - this->SaveRecord((std::unique_ptr)sample, false); + this->CollectSymbol((std::unique_ptr)sample, false); }; virtualRuntime_.SetCollectSymbolCallBack(collectSymbol); } From ab8645f13f987cb161a202791e07d4fa260dfd94 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 4 Jul 2024 16:48:38 +0800 Subject: [PATCH 08/10] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E6=9C=89?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: root --- src/subcommand_record.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subcommand_record.cpp b/src/subcommand_record.cpp index d3cfeee..84e173a 100644 --- a/src/subcommand_record.cpp +++ b/src/subcommand_record.cpp @@ -911,7 +911,7 @@ bool SubCommandRecord::PrepareVirtualRuntime() if (dedupStack_) { virtualRuntime_.SetDedupStack(); auto collectSymbol = [this](PerfRecordSample *sample) { - this->CollectSymbol((std::unique_ptr)sample, false); + this->CollectSymbol(std::move(sample)); }; virtualRuntime_.SetCollectSymbolCallBack(collectSymbol); } From 4aeff33b842d2e5da17014820bd4fb9725e56fda Mon Sep 17 00:00:00 2001 From: root Date: Thu, 4 Jul 2024 19:09:24 +0800 Subject: [PATCH 09/10] =?UTF-8?q?fix:=20=E5=8F=96=E6=B6=88std::move?= =?UTF-8?q?=E7=9A=84=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: root --- src/report.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/report.cpp b/src/report.cpp index 16f0063..1a39107 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -199,7 +199,7 @@ void Report::AdjustReportItems() HLOGD("MultiLevelSorting %" PRIu64 "", totalReportCount); std::sort(config.reportItems_.begin(), config.reportItems_.end(), [this] (const ReportItem &a, const ReportItem &b) -> bool { - return this->MultiLevelSorting(std::move(a), std::move(b)); + return this->MultiLevelSorting(a, b); }); HLOGD("MultiLevelSorting %" PRIu64 " done", totalReportCount); // reorder the callstack From 5acd2ace909b362528947c416275ada879c24238 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 4 Jul 2024 20:21:38 +0800 Subject: [PATCH 10/10] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E7=BC=A9?= =?UTF-8?q?=E8=BF=9B=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: root --- src/report.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/report.cpp b/src/report.cpp index 1a39107..7dca29d 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -121,9 +121,9 @@ void Report::StatisticsRecords() // merge duplicate HLOGD("uniquing %zu", totalReportCount); auto last = std::unique(config.reportItems_.begin(), config.reportItems_.end(), - [this] (ReportItem &l, ReportItem &r) -> bool { - return this->MultiLevelSameAndUpdateCount(l, r); - }); + [this] (ReportItem &l, ReportItem &r) -> bool { + return this->MultiLevelSameAndUpdateCount(l, r); + }); config.reportItems_.erase(last, config.reportItems_.end()); @@ -198,9 +198,9 @@ void Report::AdjustReportItems() // sort first. HLOGD("MultiLevelSorting %" PRIu64 "", totalReportCount); std::sort(config.reportItems_.begin(), config.reportItems_.end(), - [this] (const ReportItem &a, const ReportItem &b) -> bool { - return this->MultiLevelSorting(a, b); - }); + [this] (const ReportItem &a, const ReportItem &b) -> bool { + return this->MultiLevelSorting(a, b); + }); HLOGD("MultiLevelSorting %" PRIu64 " done", totalReportCount); // reorder the callstack if (option_.debug_) {