File indexing completed on 2024-05-12 05:43:33
0001 /* 0002 Copyright (C) 2015 Volker Krause <vkrause@kde.org> 0003 0004 This program is free software; you can redistribute it and/or modify it 0005 under the terms of the GNU Library General Public License as published by 0006 the Free Software Foundation; either version 2 of the License, or (at your 0007 option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, but WITHOUT 0010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 0012 License for more details. 0013 0014 You should have received a copy of the GNU General Public License 0015 along with this program. If not, see <https://www.gnu.org/licenses/>. 0016 */ 0017 0018 #include "loadbenchmarkmodel.h" 0019 0020 #include <checks/ldbenchmark.h> 0021 #include <elf/elffile.h> 0022 0023 LoadBenchmarkModel::LoadBenchmarkModel(QObject* parent): QAbstractTableModel(parent) 0024 { 0025 } 0026 0027 LoadBenchmarkModel::~LoadBenchmarkModel() = default; 0028 0029 void LoadBenchmarkModel::setBenchmark(const std::shared_ptr< LDBenchmark >& data) 0030 { 0031 beginResetModel(); 0032 m_data = data; 0033 endResetModel(); 0034 } 0035 0036 QVariant LoadBenchmarkModel::data(const QModelIndex& index, int role) const 0037 { 0038 if (!m_data || !index.isValid()) 0039 return {}; 0040 0041 if (role == Qt::DisplayRole || role == Qt::EditRole) { 0042 switch (index.column()) { 0043 case 0: return m_data->file(index.row())->displayName(); 0044 case 1: return m_data->median(LDBenchmark::LoadMode::Lazy, index.row()); 0045 case 2: return m_data->min(LDBenchmark::LoadMode::Lazy, index.row()); 0046 case 3: return m_data->median(LDBenchmark::LoadMode::Now, index.row()); 0047 case 4: return m_data->min(LDBenchmark::LoadMode::Now, index.row()); 0048 case 5: return m_data->file(index.row())->reverseRelocator()->size(); 0049 } 0050 } 0051 return {}; 0052 } 0053 0054 int LoadBenchmarkModel::columnCount(const QModelIndex& parent) const 0055 { 0056 Q_UNUSED(parent); 0057 return 6; 0058 } 0059 0060 int LoadBenchmarkModel::rowCount(const QModelIndex& parent) const 0061 { 0062 if (parent.isValid() || !m_data) 0063 return 0; 0064 return m_data->size(); 0065 } 0066 0067 QVariant LoadBenchmarkModel::headerData(int section, Qt::Orientation orientation, int role) const 0068 { 0069 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { 0070 switch (section) { 0071 case 0: return tr("File"); 0072 case 1: return tr("Lazy Median"); 0073 case 2: return tr("Lazy Min"); 0074 case 3: return tr("Now Median"); 0075 case 4: return tr("Now Min"); 0076 case 5: return tr("Relocs"); 0077 } 0078 } 0079 return QAbstractItemModel::headerData(section, orientation, role); 0080 }