File indexing completed on 2024-04-21 04:36:00

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 2011 Lionel Duc <lionel.data@gmail.com>
0005  * Copyright 2011 Lucas Sarie <lucas.sarie@gmail.com>
0006  * Copyright 2017 Anton Anikin <anton@anikin.xyz>
0007 
0008    This program is free software; you can redistribute it and/or
0009    modify it under the terms of the GNU General Public
0010    License as published by the Free Software Foundation; either
0011    version 2 of the License, or (at your option) any later version.
0012 
0013    This program is distributed in the hope that it will be useful,
0014    but WITHOUT ANY WARRANTY; without even the implied warranty of
0015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016     General Public License for more details.
0017 
0018    You should have received a copy of the GNU General Public License
0019    along with this program; see the file COPYING.  If not, write to
0020    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0021    Boston, MA 02110-1301, USA.
0022 */
0023 
0024 #pragma once
0025 
0026 #include <QAbstractTableModel>
0027 
0028 class QItemSelectionModel;
0029 
0030 namespace Valgrind
0031 {
0032 
0033 class CallgrindFunction;
0034 
0035 class CallgrindCallInformation
0036 {
0037 public:
0038     explicit CallgrindCallInformation(const QStringList& stringValues);
0039 
0040     CallgrindFunction* caller = nullptr;
0041     CallgrindFunction* callee = nullptr;
0042 
0043     int callCount = 0;
0044 
0045     int eventValue(int type);
0046 
0047 private:
0048     QVector<int> m_eventValues;
0049 };
0050 
0051 class CallgrindFunction
0052 {
0053 public:
0054     explicit CallgrindFunction(int eventsCount);
0055 
0056     QString name;
0057     QString binaryFile;
0058     QStringList sourceFiles;
0059 
0060     int callCount();
0061 
0062     int eventValue(int type, bool inclusive);
0063     void addEventValues(const QStringList& stringValues);
0064 
0065     QList<CallgrindCallInformation*> callersInformation;
0066     QList<CallgrindCallInformation*> calleesInformation;
0067 
0068 private:
0069     QVector<int> m_eventValues;
0070 };
0071 
0072 class CallgrindFunctionsModel : public QAbstractTableModel
0073 {
0074     Q_OBJECT
0075 
0076 public:
0077     CallgrindFunctionsModel();
0078     ~CallgrindFunctionsModel() override;
0079 
0080     const QStringList& eventTypes();
0081     void setEventTypes(const QStringList& eventTypes);
0082 
0083     int currentEventType();
0084     void setCurrentEventType(int type);
0085 
0086     void setEventTotals(const QStringList& stringValues);
0087 
0088     void setPercentageValues(bool value);
0089 
0090     CallgrindFunction* addFunction(
0091         const QString& name,
0092         const QString& sourceFile,
0093         const QString& binaryFile);
0094 
0095 
0096     void addCall(
0097         CallgrindFunction* caller,
0098         CallgrindFunction* callee,
0099         int callCount,
0100         const QStringList& eventValues);
0101 
0102     QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
0103 
0104     int rowCount(const QModelIndex& parent = QModelIndex()) const override;
0105     int columnCount(const QModelIndex& parent = QModelIndex()) const override;
0106 
0107     QVariant data(const QModelIndex& index, int role) const override;
0108     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0109 
0110     QVariant eventData(int type, int intValue, int role) const;
0111 
0112     QString displayValue(int eventIntValue, int eventType) const;
0113 
0114 private:
0115     QStringList m_eventTypes;
0116     int m_currentEventType;
0117 
0118     QVector<int> m_eventTotals;
0119 
0120     bool m_percentageValues;
0121 
0122     QList<CallgrindFunction*> m_functions;
0123     QList<CallgrindCallInformation*> m_information;
0124 };
0125 
0126 class CallgrindFunctionEventsModel : public QAbstractTableModel
0127 {
0128     Q_OBJECT
0129 
0130 public:
0131     explicit CallgrindFunctionEventsModel(CallgrindFunctionsModel* baseModel);
0132     ~CallgrindFunctionEventsModel() override = default;
0133 
0134     void setFunction(CallgrindFunction* function);
0135 
0136     QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
0137 
0138     int rowCount(const QModelIndex& parent = QModelIndex()) const override;
0139     int columnCount(const QModelIndex& parent = QModelIndex()) const override;
0140 
0141     QVariant data(const QModelIndex& index, int role) const override;
0142     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0143 
0144 private:
0145     CallgrindFunctionsModel* m_baseModel;
0146     CallgrindFunction* m_function;
0147 };
0148 
0149 class CallgrindFunctionCallersCalleesModel : public QAbstractTableModel
0150 {
0151     Q_OBJECT
0152 
0153 public:
0154     CallgrindFunctionCallersCalleesModel(CallgrindFunctionsModel* baseModel, bool isCallerModel);
0155     ~CallgrindFunctionCallersCalleesModel() override = default;
0156 
0157     void setFunction(CallgrindFunction* function);
0158 
0159     QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
0160 
0161     int rowCount(const QModelIndex& parent = QModelIndex()) const override;
0162     int columnCount(const QModelIndex& parent = QModelIndex()) const override;
0163 
0164     QVariant data(const QModelIndex& index, int role) const override;
0165     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0166 
0167 private:
0168     CallgrindFunctionsModel* m_baseModel;
0169     bool m_isCallerModel;
0170     CallgrindFunction* m_function;
0171 };
0172 
0173 }