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

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 MASSIFDATA_UTIL_H
0024 #define MASSIFDATA_UTIL_H
0025 
0026 #include <QString>
0027 
0028 namespace Massif {
0029 
0030 class TreeLeafItem;
0031 class SnapshotItem;
0032 
0033 /**
0034  * Returns a prettified cost string.
0035  */
0036 QString prettyCost(quint64 cost);
0037 
0038 struct ParsedLabel
0039 {
0040     QByteArray address;
0041     QByteArray function;
0042     QByteArray location;
0043 
0044     bool operator==(const ParsedLabel& o) const
0045     {
0046         return o.address == address && o.function == function && o.location == location;
0047     }
0048 };
0049 
0050 ParsedLabel parseLabel(const QByteArray& label);
0051 uint qHash(const ParsedLabel& label);
0052 
0053 /**
0054  * Prepares a tree node's label for the UI.
0055  * So far, only the Mem-Address will get stripped.
0056  */
0057 QByteArray prettyLabel(const QByteArray& label);
0058 
0059 /**
0060  * If enabled in settings, removes template arguments from identifiers.
0061  */
0062 QByteArray shortenTemplates(const QByteArray& label);
0063 
0064 /**
0065  * Extracts the function name from the @p label.
0066  */
0067 QByteArray functionInLabel(const QByteArray& label);
0068 
0069 /**
0070  * Extracts the address from the @p label if it exists.
0071  */
0072 QByteArray addressInLabel(const QByteArray& label);
0073 
0074 /**
0075  * Extracts the location from the @p label if it exists.
0076  */
0077 QByteArray locationInLabel(const QByteArray& label);
0078 
0079 /**
0080  * Checks whether this label denotes a tree node
0081  * with aggregated items below massif's threshold.
0082  */
0083 bool isBelowThreshold(const QByteArray& label);
0084 
0085 /**
0086  * Formats a label to a richtext tooltip.
0087  *
0088  * Returns HTML items of a definition list (<dl>).
0089  */
0090 QString formatLabelForTooltip(const ParsedLabel& label);
0091 
0092 /**
0093  * Given a list of HTML definition list items, finalize the richtext tooltip.
0094  */
0095 QString finalizeTooltip(const QString& contents);
0096 
0097 /**
0098  * Prepares a richtext tooltip for the given node, snapshot and label.
0099  */
0100 QString tooltipForTreeLeaf(const Massif::TreeLeafItem* node, const Massif::SnapshotItem* snapshot, const QByteArray& label);
0101 
0102 }
0103 
0104 #endif // MASSIFDATA_UTIL_H