blob: 39cbf3803a5946e9a7685ee1fb9e9f7f67cdb53e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "callgrindtextmark.h"
#include "callgrind/callgrinddatamodel.h"
#include "callgrind/callgrindfunction.h"
#include "callgrindhelper.h"
#include "valgrindtr.h"
#include <utils/qtcassert.h>
#include <QLabel>
#include <QLayout>
using namespace Utils;
using namespace Valgrind::Internal;
using namespace Valgrind::Callgrind;
namespace Constants { const char CALLGRIND_TEXT_MARK_CATEGORY[] = "Callgrind.Textmark"; }
CallgrindTextMark::CallgrindTextMark(const QPersistentModelIndex &index,
const FilePath &fileName,
int lineNumber)
: TextEditor::TextMark(fileName,
lineNumber,
{Tr::tr("Callgrind"), Constants::CALLGRIND_TEXT_MARK_CATEGORY})
, m_modelIndex(index)
{
setPriority(TextEditor::TextMark::HighPriority);
const Function *f = function();
const QString inclusiveCost = QLocale::system().toString(f->inclusiveCost(0));
setLineAnnotation(Tr::tr("%1 (Called: %2; Incl. Cost: %3)")
.arg(CallgrindHelper::toPercent(costs() * 100.0f))
.arg(f->called())
.arg(inclusiveCost));
}
const Function *CallgrindTextMark::function() const
{
if (!m_modelIndex.isValid())
return nullptr;
return m_modelIndex.data(DataModel::FunctionRole).value<const Function *>();
}
bool CallgrindTextMark::addToolTipContent(QLayout *target) const
{
if (!m_modelIndex.isValid())
return false;
const QString tooltip = m_modelIndex.data(Qt::ToolTipRole).toString();
if (tooltip.isEmpty())
return false;
target->addWidget(new QLabel(tooltip));
return true;
}
qreal CallgrindTextMark::costs() const
{
bool ok;
qreal costs = m_modelIndex.data(RelativeTotalCostRole).toReal(&ok);
QTC_ASSERT(ok, return 0.0);
QTC_ASSERT(costs >= 0.0 && costs <= 100.0, return 0.0);
return costs;
}
|