Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qohosjscallbatchtrace.cpp
Go to the documentation of this file.
1
// Copyright (C) 2026 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
#
include
<
qohosjscallbatchtrace
.
h
>
5
6
#
include
<
QtCore
/
qloggingcategory
.
h
>
7
8
QT_BEGIN_NAMESPACE
9
10
namespace
QtOhos
{
11
12
Q_STATIC_LOGGING_CATEGORY(
lcJsCallBatch
,
"qt.ohos.jscallbatch"
,
QtWarningMsg
)
13
14
void
JsCallBatchTrace
::
recordBatchStart
(
const
char
*batchContextName)
15
{
16
++m_liveBatchCount;
17
if
(m_liveBatchCount == 1 && (lcJsCallBatch().isInfoEnabled() || lcJsCallBatch().isDebugEnabled())) {
18
m_optTracedBatch = TracedBatch{
19
.contextName = batchContextName,
20
};
21
}
22
}
23
24
void
JsCallBatchTrace
::
recordBatchEnd
(
const
char
*batchContextName,
std
::size_t queuedCallCount)
25
{
26
--m_liveBatchCount;
27
if
(m_optTracedBatch) {
28
if
(m_liveBatchCount > 0) {
29
recordRunForcedBy
(queuedCallCount, std::string(
"end of nested batch "
) + batchContextName);
30
}
else
{
31
recordRunAtEnd(queuedCallCount);
32
logSummary();
33
m_optTracedBatch.reset();
34
}
35
}
36
}
37
38
void
JsCallBatchTrace
::
recordQueuedCall
(
const
std
::string &callerContextName)
39
{
40
if
(!m_optTracedBatch)
41
return
;
42
43
auto
&tracedBatch = *m_optTracedBatch;
44
if
(tracedBatch.optPendingSplitCause)
45
tracedBatch.splitCauses.push_back(*std::exchange(tracedBatch.optPendingSplitCause, std::nullopt));
46
47
++tracedBatch.callCount;
48
qCDebug(
49
lcJsCallBatch,
"batch %s: call %d queued: %s"
,
50
tracedBatch.contextName, tracedBatch.callCount, callerContextName.c_str());
51
}
52
53
void
JsCallBatchTrace
::
recordBlockingCall
(
std
::size_t queuedCallCount,
const
std
::string &callerContextName)
54
{
55
if
(!m_optTracedBatch)
56
return
;
57
58
auto
&tracedBatch = *m_optTracedBatch;
59
++tracedBatch.roundTripCount;
60
++tracedBatch.callCount;
61
if
(queuedCallCount == 0) {
62
qCDebug(
63
lcJsCallBatch,
"batch %s: round trip %d runs only call %d: %s"
,
64
tracedBatch.contextName, tracedBatch.roundTripCount, tracedBatch.callCount, callerContextName.c_str());
65
}
else
{
66
tracedBatch.optPendingSplitCause = callerContextName;
67
qCDebug(
68
lcJsCallBatch,
"batch %s: round trip %d runs %s and then call %d: %s"
,
69
tracedBatch.contextName, tracedBatch.roundTripCount, describeQueuedCalls(queuedCallCount).c_str(),
70
tracedBatch.callCount, callerContextName.c_str());
71
}
72
tracedBatch.firstQueuedCall = tracedBatch.callCount + 1;
73
}
74
75
void
JsCallBatchTrace
::
recordRunForcedBy
(
std
::size_t queuedCallCount,
const
std
::string &runCause)
76
{
77
if
(!m_optTracedBatch || queuedCallCount == 0)
78
return
;
79
80
auto
&tracedBatch = *m_optTracedBatch;
81
++tracedBatch.roundTripCount;
82
tracedBatch.optPendingSplitCause = runCause;
83
qCDebug(
84
lcJsCallBatch,
"batch %s: round trip %d runs %s, forced by %s"
,
85
tracedBatch.contextName, tracedBatch.roundTripCount, describeQueuedCalls(queuedCallCount).c_str(),
86
runCause.c_str());
87
tracedBatch.firstQueuedCall = tracedBatch.callCount + 1;
88
}
89
90
void
JsCallBatchTrace
::recordRunAtEnd(
std
::size_t queuedCallCount)
91
{
92
if
(queuedCallCount == 0)
93
return
;
94
95
auto
&tracedBatch = *m_optTracedBatch;
96
++tracedBatch.roundTripCount;
97
qCDebug(
98
lcJsCallBatch,
"batch %s: round trip %d runs %s at the end of the batch"
,
99
tracedBatch.contextName, tracedBatch.roundTripCount, describeQueuedCalls(queuedCallCount).c_str());
100
}
101
102
void
JsCallBatchTrace
::logSummary()
const
103
{
104
const
auto
&tracedBatch = *m_optTracedBatch;
105
if
(tracedBatch.callCount == 0) {
106
qCInfo(lcJsCallBatch,
"summary of batch %s: no calls"
, tracedBatch.contextName);
107
return
;
108
}
109
110
auto
summary = describeCount(tracedBatch.callCount,
"call"
) +
" in "
111
+ describeCount(tracedBatch.roundTripCount,
"round trip"
);
112
for
(
const
auto
&splitCause : tracedBatch.splitCauses)
113
summary +=
"; split by "
+ splitCause;
114
115
qCInfo(lcJsCallBatch,
"summary of batch %s: %s"
, tracedBatch.contextName, summary.c_str());
116
}
117
118
std
::string
JsCallBatchTrace
::describeQueuedCalls(
std
::size_t queuedCallCount)
const
119
{
120
const
auto
firstCall = m_optTracedBatch->firstQueuedCall;
121
if
(queuedCallCount == 1)
122
return
"call "
+
std
::to_string(firstCall);
123
124
const
auto
lastCall = firstCall +
static_cast
<
int
>(queuedCallCount) - 1;
125
return
"calls "
+
std
::to_string(firstCall) +
"-"
+
std
::to_string(lastCall);
126
}
127
128
std
::string
JsCallBatchTrace
::describeCount(
int
count,
const
char
*noun)
129
{
130
return
std
::to_string(count) +
" "
+ noun + (count == 1 ?
""
:
"s"
);
131
}
132
133
}
134
135
QT_END_NAMESPACE
QtOhos::JsCallBatchTrace
Definition
qohosjscallbatchtrace.h:19
QtOhos::JsCallBatchTrace::recordRunForcedBy
void recordRunForcedBy(std::size_t queuedCallCount, const std::string &runCause)
Definition
qohosjscallbatchtrace.cpp:75
QtOhos::JsCallBatchTrace::recordBatchStart
void recordBatchStart(const char *batchContextName)
Definition
qohosjscallbatchtrace.cpp:14
QtOhos::JsCallBatchTrace::recordBatchEnd
void recordBatchEnd(const char *batchContextName, std::size_t queuedCallCount)
Definition
qohosjscallbatchtrace.cpp:24
QtOhos::JsCallBatchTrace::recordQueuedCall
void recordQueuedCall(const std::string &callerContextName)
Definition
qohosjscallbatchtrace.cpp:38
QtOhos::JsCallBatchTrace::recordBlockingCall
void recordBlockingCall(std::size_t queuedCallCount, const std::string &callerContextName)
Definition
qohosjscallbatchtrace.cpp:53
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QtOhos
Definition
qcore_ohos.cpp:59
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qtbase
src
plugins
platforms
ohos
qohosjscallbatchtrace.cpp
Generated on
for Qt by
1.18.0