File indexing completed on 2024-04-14 04:31:21

0001 /* This file is part of KDevelop
0002    Copyright 2011 Mathieu Lornac <mathieu.lornac@gmail.com>
0003    Copyright 2011 Damien Coppel <damien.coppel@gmail.com>
0004    Copyright 2016-2017 Anton Anikin <anton@anikin.xyz>
0005 
0006    This program is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU General Public
0008    License as published by the Free Software Foundation; either
0009    version 2 of the License, or (at your option) any later version.
0010 
0011    This program is distributed in the hope that it will be useful,
0012    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0014    General Public License for more details.
0015 
0016    You should have received a copy of the GNU General Public License
0017    along with this program; see the file COPYING.  If not, write to
0018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019    Boston, MA 02110-1301, USA.
0020 */
0021 
0022 #include "massif_parser.h"
0023 
0024 #include "massif_model.h"
0025 #include "massif_snapshot.h"
0026 
0027 #include <QFile>
0028 
0029 namespace Valgrind
0030 {
0031 
0032 void massifParse(const QString& fileName, MassifSnapshotsModel* model)
0033 {
0034     Q_ASSERT(model);
0035 
0036     MassifSnapshot* snapshot = nullptr;
0037     QString line;
0038     QStringList keyValue;
0039 
0040     QFile file(fileName);
0041     file.open(QIODevice::ReadOnly);
0042 
0043     while (!file.atEnd()) {
0044         line = file.readLine();
0045 
0046         if (line.startsWith(QChar('#')) ||
0047             line.startsWith(QStringLiteral("desc")) ||
0048             line.startsWith(QStringLiteral("time_unit")) ||
0049             line.startsWith(QStringLiteral("cmd"))) {
0050 
0051             continue; // skip comment and useless lines
0052         }
0053 
0054         keyValue = line.split(QChar('='));
0055         const QString& key = keyValue.at(0);
0056         const QString& value = keyValue.at(1);
0057 
0058         if (key == QStringLiteral("snapshot")) {
0059             snapshot = new MassifSnapshot;
0060             snapshot->setValue(key, value.trimmed());
0061             continue;
0062         }
0063 
0064         Q_ASSERT(snapshot);
0065         snapshot->setValue(key, value.trimmed());
0066 
0067         if (key == QStringLiteral("heap_tree")) {
0068             if (value.startsWith(QStringLiteral("peak")) ||
0069                 value.startsWith(QStringLiteral("detailed"))) {
0070 
0071                 while (!file.atEnd()) {
0072                     line = file.readLine();
0073                     if (line.startsWith(QChar('#'))) {
0074                         break;
0075                     }
0076 
0077                     snapshot->heapTree.append(line.remove(QLatin1Char('\n')));
0078                 }
0079             }
0080 
0081             model->addSnapshot(snapshot);
0082         }
0083     }
0084 }
0085 
0086 }