Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
shell
platform
android
io
flutter
util
TraceSection.java
Go to the documentation of this file.
1
// Copyright 2013 The Flutter Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
package
io.flutter.util;
6
7
import
androidx.annotation.NonNull;
8
import
androidx.tracing.Trace;
9
10
public
final
class
TraceSection
implements
AutoCloseable {
11
/**
12
* Factory used to support the try-with-resource construct.
13
*
14
* <p>To get scoped trace events, use the try-with-resource construct, for instance:
15
*
16
* <pre>{@code
17
* try (TraceSection e = TraceSection.scoped("MyTraceEvent")) {
18
* // code.
19
* }
20
* }</pre>
21
*/
22
public
static
TraceSection
scoped
(String
name
) {
23
return
new
TraceSection
(
name
);
24
}
25
26
/** Constructor used to support the try-with-resource construct. */
27
private
TraceSection
(String
name
) {
28
begin
(
name
);
29
}
30
31
@Override
32
public
void
close
() {
33
end
();
34
}
35
36
private
static
String cropSectionName(@NonNull String sectionName) {
37
return
sectionName.length() < 124 ? sectionName : sectionName.substring(0, 124) +
"..."
;
38
}
39
40
/**
41
* Wraps Trace.beginSection to ensure that the line length stays below 127 code units.
42
*
43
* @param sectionName The string to display as the section name in the trace.
44
*/
45
public
static
void
begin
(@NonNull String sectionName) {
46
Trace.beginSection(cropSectionName(sectionName));
47
}
48
49
/** Wraps Trace.endSection. */
50
public
static
void
end
() throws RuntimeException {
51
Trace.endSection();
52
}
53
54
/**
55
* Wraps Trace.beginAsyncSection to ensure that the line length stays below 127 code units.
56
*
57
* @param sectionName The string to display as the section name in the trace.
58
* @param cookie Unique integer defining the section.
59
*/
60
public
static
void
beginAsyncSection
(String sectionName,
int
cookie) {
61
Trace.beginAsyncSection(cropSectionName(sectionName), cookie);
62
}
63
64
/** Wraps Trace.endAsyncSection to ensure that the line length stays below 127 code units. */
65
public
static
void
endAsyncSection
(String sectionName,
int
cookie) {
66
Trace.endAsyncSection(cropSectionName(sectionName), cookie);
67
}
68
}
io.flutter.util.TraceSection
Definition
TraceSection.java:10
io.flutter.util.TraceSection.end
static void end()
Definition
TraceSection.java:50
io.flutter.util.TraceSection.close
void close()
Definition
TraceSection.java:32
io.flutter.util.TraceSection.scoped
static TraceSection scoped(String name)
Definition
TraceSection.java:22
io.flutter.util.TraceSection.begin
static void begin(@NonNull String sectionName)
Definition
TraceSection.java:45
io.flutter.util.TraceSection.beginAsyncSection
static void beginAsyncSection(String sectionName, int cookie)
Definition
TraceSection.java:60
io.flutter.util.TraceSection.endAsyncSection
static void endAsyncSection(String sectionName, int cookie)
Definition
TraceSection.java:65
name
const char * name
Definition
fuchsia.cc:50
Generated on Fri Apr 26 2024 06:14:21 for Flutter Engine by
1.9.8