File indexing completed on 2024-05-12 15:27:41

0001 /***************************************************************************
0002     File                 : MemoryWidget.cpp
0003     Project              : LabPlot
0004     Description          : widget showing the amount of memory consumed by the process
0005     --------------------------------------------------------------------
0006     Copyright            : (C) 2018 Alexander Semke (alexander.semke@web.de)
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *  This program is free software; you can redistribute it and/or modify   *
0012  *  it under the terms of the GNU General Public License as published by   *
0013  *  the Free Software Foundation; either version 2 of the License, or      *
0014  *  (at your option) any later version.                                    *
0015  *                                                                         *
0016  *  This program is distributed in the hope that it will be useful,        *
0017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0019  *  GNU General Public License for more details.                           *
0020  *                                                                         *
0021  *   You should have received a copy of the GNU General Public License     *
0022  *   along with this program; if not, write to the Free Software           *
0023  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0024  *   Boston, MA  02110-1301  USA                                           *
0025  *                                                                         *
0026  ***************************************************************************/
0027 
0028 #include "MemoryWidget.h"
0029 #include "tools/getRSS.h"
0030 
0031 #include <KLocalizedString>
0032 
0033 MemoryWidget::MemoryWidget(QWidget* parent) : QLabel(parent) {
0034     connect(&m_timer, &QTimer::timeout, this, &MemoryWidget::refreshMemoryInfo);
0035     refreshMemoryInfo();
0036     m_timer.start(2000);
0037 }
0038 
0039 void MemoryWidget::refreshMemoryInfo() {
0040     size_t used = getCurrentRSS()/1024/1024;
0041     size_t peak = getPeakRSS()/1024/1024;
0042     setText(i18n("Memory used %1 MB, peak %2 MB", used, peak));
0043 }