From a5a3e122f6540948d9479cd38f61df0a78726d0a Mon Sep 17 00:00:00 2001 From: youzhi92 Date: Mon, 12 Jul 2021 16:22:15 +0800 Subject: [PATCH] issueNo: #13S13B Description:dump JS heap in QT simulator Feature or Bugfix:Feature Binary Source:No Signed-off-by: youzhi92 Change-Id: Id33a358c272459771ead7f704d62ca22b44e4a0e --- .../simulator/utils/js_heap_stats_dumper.cpp | 14 +++++++------- .../targets/simulator/utils/js_heap_stats_dumper.h | 10 +++++----- .../targets/simulator/utils/js_heap_stats_writer.h | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/frameworks/tools/qt/simulator/jsfwk/targets/simulator/utils/js_heap_stats_dumper.cpp b/frameworks/tools/qt/simulator/jsfwk/targets/simulator/utils/js_heap_stats_dumper.cpp index 206bee5..b420bd4 100644 --- a/frameworks/tools/qt/simulator/jsfwk/targets/simulator/utils/js_heap_stats_dumper.cpp +++ b/frameworks/tools/qt/simulator/jsfwk/targets/simulator/utils/js_heap_stats_dumper.cpp @@ -14,14 +14,14 @@ */ #include "js_heap_stats_dumper.h" +#include #include "ace_log.h" #include "securec.h" -#include namespace OHOS { namespace ACELite { JSHeapStatsDumper::JSHeapStatsDumper() - : writer_(QDir::currentPath() + "/dump_heap.txt") + : stats_(), writer_(QDir::currentPath() + "/dump_heap.txt") { if (memset_s(&stats_, sizeof(stats_), 0, sizeof(stats_)) != 0) { HILOG_ERROR(HILOG_MODULE_ACE, "failed to memset."); @@ -42,32 +42,32 @@ void JSHeapStatsDumper::Dump() } } -bool JSHeapStatsDumper::HasChanged(JSHeapStatus &stats) const +bool JSHeapStatsDumper::HasChanged(const JSHeapStatus &stats) const { return stats.allocBytes != stats_.allocBytes || stats.peakAllocBytes != stats_.peakAllocBytes; } -void JSHeapStatsDumper::HandleChange(JSHeapStatus &stats) +void JSHeapStatsDumper::HandleChange(const JSHeapStatus &stats) { UpdateStats(stats); LogStats(stats); SaveStats(stats); } -void JSHeapStatsDumper::UpdateStats(JSHeapStatus &stats) +void JSHeapStatsDumper::UpdateStats(const JSHeapStatus &stats) { stats_.allocBytes = stats.allocBytes; stats_.peakAllocBytes = stats.peakAllocBytes; stats_.totalBytes = stats.totalBytes; } -void JSHeapStatsDumper::LogStats(JSHeapStatus &stats) const +void JSHeapStatsDumper::LogStats(const JSHeapStatus &stats) const { HILOG_DEBUG(HILOG_MODULE_ACE, "Current Allocated Bytes: %d, Peak Allocated Bytes: %d, Total Bytes: %d", stats.allocBytes, stats.peakAllocBytes, stats.totalBytes); } -void JSHeapStatsDumper::SaveStats(JSHeapStatus &stats) +void JSHeapStatsDumper::SaveStats(const JSHeapStatus &stats) { char buffer[255] = {0}; if (sprintf_s(buffer, sizeof(buffer), "%d/%d ", stats.allocBytes, stats.peakAllocBytes) < 0) { diff --git a/frameworks/tools/qt/simulator/jsfwk/targets/simulator/utils/js_heap_stats_dumper.h b/frameworks/tools/qt/simulator/jsfwk/targets/simulator/utils/js_heap_stats_dumper.h index a4986fe..16bfdf2 100644 --- a/frameworks/tools/qt/simulator/jsfwk/targets/simulator/utils/js_heap_stats_dumper.h +++ b/frameworks/tools/qt/simulator/jsfwk/targets/simulator/utils/js_heap_stats_dumper.h @@ -29,11 +29,11 @@ public: void Dump(); private: - bool HasChanged(JSHeapStatus &stats) const; - void HandleChange(JSHeapStatus &stats); - void UpdateStats(JSHeapStatus &stats); - void LogStats(JSHeapStatus &stats) const; - void SaveStats(JSHeapStatus &stats); + bool HasChanged(const JSHeapStatus &stats) const; + void HandleChange(const JSHeapStatus &stats); + void UpdateStats(const JSHeapStatus &stats); + void LogStats(const JSHeapStatus &stats) const; + void SaveStats(const JSHeapStatus &stats); JSHeapStatus stats_; JSHeapStatsWriter writer_; diff --git a/frameworks/tools/qt/simulator/jsfwk/targets/simulator/utils/js_heap_stats_writer.h b/frameworks/tools/qt/simulator/jsfwk/targets/simulator/utils/js_heap_stats_writer.h index b055457..24844e0 100644 --- a/frameworks/tools/qt/simulator/jsfwk/targets/simulator/utils/js_heap_stats_writer.h +++ b/frameworks/tools/qt/simulator/jsfwk/targets/simulator/utils/js_heap_stats_writer.h @@ -24,7 +24,7 @@ namespace OHOS { namespace ACELite { class JSHeapStatsWriter { public: - JSHeapStatsWriter(const QString filename); + explicit JSHeapStatsWriter(const QString filename); ~JSHeapStatsWriter(); void Write(const char *text);