Skip to content

Commit

Permalink
Add back memory stats
Browse files Browse the repository at this point in the history
  • Loading branch information
variar committed May 29, 2021
1 parent 58aed56 commit b2e5b1c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
61 changes: 39 additions & 22 deletions src/app/crashhandler.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Anton Filimonov and other contributors
* Copyright (C) 2020, 2021 Anton Filimonov and other contributors
*
* This file is part of klogg.
*
Expand All @@ -19,18 +19,6 @@

#include "crashhandler.h"

#include "sentry.h"

#ifdef KLOGG_USE_MIMALLOC
#include <mimalloc.h>
#endif

#include "issuereporter.h"
#include "klogg_version.h"
#include "log.h"
#include "memory_info.h"
#include "openfilehelper.h"

#include <QByteArray>
#include <QDialog>
#include <QDialogButtonBox>
Expand All @@ -47,8 +35,20 @@
#include <QTimer>
#include <QUrlQuery>
#include <QVBoxLayout>
#include <string_view>

#ifdef KLOGG_USE_MIMALLOC
#include <mimalloc.h>
#endif

#include "client/crash_report_database.h"
#include "sentry.h"

#include "issuereporter.h"
#include "klogg_version.h"
#include "log.h"
#include "memory_info.h"
#include "openfilehelper.h"

namespace {

Expand Down Expand Up @@ -177,7 +177,6 @@ bool checkCrashpadReports( const QString& databasePath )

#ifdef Q_OS_WIN
const auto reportFile = QString::fromStdWString( report.file_path.value() );

#else
const auto reportFile = QString::fromStdString( report.file_path.value() );
#endif
Expand Down Expand Up @@ -245,22 +244,40 @@ CrashHandler::CrashHandler()
sentry_set_tag( "qt", qVersion() );
sentry_set_tag( "build_arch", QSysInfo::buildCpuArchitecture().toLatin1().data() );

const auto totalMemory = std::to_string( physicalMemory() );
LOG_INFO << "Physical memory " << totalMemory;
auto addExtra = []( const char* name, size_t value ) {
sentry_set_extra( name, sentry_value_new_string( std::to_string( value ).c_str() ) );
LOG_INFO << "Process stats: " << name << " - " << value;
};

sentry_set_extra( "memory", sentry_value_new_string( totalMemory.c_str() ) );
addExtra( "memory", physicalMemory() );

memoryUsageTimer_ = std::make_unique<QTimer>();
QObject::connect( memoryUsageTimer_.get(), &QTimer::timeout, []() {
const auto vmUsed = std::to_string( usedMemory() );
sentry_set_extra( "vm_used", sentry_value_new_string( vmUsed.c_str() ) );
LOG_INFO << "Process stats, vm_used " << vmUsed;
QObject::connect( memoryUsageTimer_.get(), &QTimer::timeout, [ addExtra ]() {
const auto vmUsed = usedMemory();
addExtra( "vm_used", vmUsed );

#ifdef KLOGG_USE_MIMALLOC
size_t elapsedMsecs, userMsecs, systemMsecs, currentRss, peakRss, currentCommit,
peakCommit, pageFaults;

mi_process_info( &elapsedMsecs, &userMsecs, &systemMsecs, &currentRss, &peakRss,
&currentCommit, &peakCommit, &pageFaults );

addExtra( "elapsed_msecs", elapsedMsecs );
addExtra( "user_msecs", userMsecs );
addExtra( "system_msecs", systemMsecs );
addExtra( "current_rss", currentRss );
addExtra( "peak_rss", peakRss );
addExtra( "current_commit", currentCommit );
addExtra( "peak_commit", peakCommit );
addExtra( "page_faults", pageFaults );
#endif
} );
memoryUsageTimer_->start( 10000 );

if ( needWaitForUpload ) {
QProgressDialog progressDialog;
progressDialog.setLabelText( QString( "Uploading crash reports" ) );
progressDialog.setLabelText( "Uploading crash reports" );
progressDialog.setRange( 0, 0 );

QTimer::singleShot( 30 * 1000, &progressDialog, &QProgressDialog::cancel );
Expand Down
6 changes: 3 additions & 3 deletions src/app/crashhandler.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Anton Filimonov and other contributors
* Copyright (C) 2020, 2021 Anton Filimonov and other contributors
*
* This file is part of klogg.
*
Expand Down Expand Up @@ -36,8 +36,8 @@ class CrashHandler {
#else
class CrashHandler {
public:
CrashHandler(){}
~CrashHandler(){}
CrashHandler() = default;
~CrashHandler() = default;
};
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (C) 2016 -- 2019 Anton Filimonov and other contributors
* Copyright (C) 2016 -- 2021 Anton Filimonov and other contributors
*
* This file is part of klogg.
*
Expand Down

0 comments on commit b2e5b1c

Please sign in to comment.