File indexing completed on 2024-04-28 17:02:22

0001 /*
0002    This file is part of Massif Visualizer
0003 
0004    Copyright 2010 Milian Wolff <mail@milianw.de>
0005 
0006    This library is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU Lesser General Public
0008    License as published by the Free Software Foundation; either
0009    version 2.1 of the License, or (at your option) version 3, or any
0010    later version accepted by the membership of KDE e.V. (or its
0011    successor approved by the membership of KDE e.V.), which shall
0012    act as a proxy defined in Section 6 of version 3 of the license.
0013 
0014    This library is distributed in the hope that it will be useful,
0015    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0017    Lesser General Public License for more details.
0018 
0019    You should have received a copy of the GNU Lesser General Public
0020    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 
0023 #ifndef MASSIF_DOTGRAPHGENERATOR_H
0024 #define MASSIF_DOTGRAPHGENERATOR_H
0025 
0026 #include <QTextStream>
0027 #include <QThread>
0028 #include <QTemporaryFile>
0029 
0030 namespace Massif {
0031 
0032 class SnapshotItem;
0033 class TreeLeafItem;
0034 struct GraphNode;
0035 
0036 class DotGraphGenerator : public QThread
0037 {
0038     Q_OBJECT
0039 public:
0040     /**
0041      * Generates a Dot graph file representing @p snapshot
0042      * and writes it to a temporary file.
0043      */
0044     DotGraphGenerator(const SnapshotItem* snapshot, const QString& timeUnit, QObject* parent = 0);
0045     /**
0046      * Generates a Dot graph file representing @p node
0047      * and writes it to a temporary file.
0048      */
0049     DotGraphGenerator(const TreeLeafItem* node, const QString& timeUnit, QObject* parent = 0);
0050     ~DotGraphGenerator();
0051 
0052     /**
0053      * Stops generating the Dot graph file and deletes the temp file.
0054      */
0055     void cancel();
0056 
0057     virtual void run();
0058     /**
0059      * @return A path to the generated Dot graph file. Path might be empty if errors occurred.
0060      */
0061     QString outputFile() const;
0062     /**
0063      * @return The GraphViz node ID for the most cost-intensive tree leaf item.
0064      */
0065     QString mostCostIntensiveGraphvizId() const;
0066 
0067 private:
0068     void nodeToDot(GraphNode* node, QTextStream& out, const QString& parentId = QString(), quint64 cost = 0);
0069     const SnapshotItem* m_snapshot;
0070     const TreeLeafItem* m_node;
0071     QTemporaryFile m_file;
0072     bool m_canceled;
0073     quint64 m_maxCost;
0074     QString m_timeUnit;
0075     QString m_costlyGraphvizId;
0076     quint64 m_highestCost;
0077 };
0078 
0079 }
0080 
0081 #endif // MASSIF_DOTGRAPHGENERATOR_H