!247 Gitee Review - 0701

Merge pull request !247 from youzhi92/0701
This commit is contained in:
openharmony_ci
2021-07-14 01:09:26 +00:00
committed by Gitee
3 changed files with 13 additions and 13 deletions
@@ -14,14 +14,14 @@
*/
#include "js_heap_stats_dumper.h"
#include <QDir>
#include "ace_log.h"
#include "securec.h"
#include <QDir>
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) {
@@ -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_;
@@ -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);