Skip to content

Commit ced0ee9

Browse files
jensjohaCommit Queue
authored andcommitted
[vm] Fix set_uprobe script after offsets_extractor was coverted to json
Also add a '--dry-run' parameter as running it as sudo doesn't work for me (it times out when it tries to build because of the RBE stuff I think). Now I can run something like ``` pkg/vm/tool/precompiler2 --dwarf-stack-traces --generate-probe-points path/to/file.dart path/to/file.aot out/ReleaseX64/dart-sdk/bin/dart runtime/tools/profiling/bin/set_uprobe.dart alloc AllocationProbePoint path/to/file.aot --dry-run | sudo tee "/sys/kernel/tracing/uprobe_events" cp out/ReleaseX64/dartaotruntime out/ReleaseX64/dart-sdk/bin/dartaotruntimeNotProduct sudo perf record -g -e uprobes:alloc out/ReleaseX64/dart-sdk/bin/dartaotruntimeNotProduct path/to/file.aot <args> sudo chmod 0755 perf.data ``` Change-Id: I189c2c08ec9cef5e61698e4fb9c9444494d20815 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/450040 Reviewed-by: Slava Egorov <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent c11f911 commit ced0ee9

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

runtime/tools/profiling/bin/set_uprobe.dart

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:convert';
56
import 'dart:io';
67

78
import 'package:path/path.dart' as p;
@@ -12,6 +13,8 @@ import 'package:profiling/src/elf_utils.dart';
1213
// binaries and Flutter applications. Prototype code for that is available
1314
// in https://dart-review.googlesource.com/c/sdk/+/239661.
1415
void main(List<String> args) async {
16+
args = args.toList();
17+
bool dryRun = args.remove('--dry-run');
1518
if (args.length != 3) {
1619
print(
1720
'Usage: pkg/vm/tool/set_uprobe.dart <probe-name> <symbol> <AOT snapshot SO file>');
@@ -21,12 +24,11 @@ void main(List<String> args) async {
2124
final [probeName, symbol, sharedObject] = args;
2225

2326
final uprobeAddress =
24-
await _computeProbesVirtualAddress(sharedObject, symbol);
27+
await _computeProbesVirtualAddress(sharedObject, symbol, silent: dryRun);
2528
final loadingBias = loadingBiasOf(sharedObject);
2629

2730
final uprobeFileOffset = (uprobeAddress + loadingBias).toRadixString(16);
2831

29-
final soName = p.basename(sharedObject);
3032
final soPath = p.canonicalize(p.absolute(sharedObject));
3133

3234
// TODO(vegorov) ARM64 support
@@ -40,11 +42,14 @@ void main(List<String> args) async {
4042
final probe = 'p:$probeName $soPath:0x$uprobeFileOffset $uprobeFormat';
4143
print(probe);
4244

43-
File('/sys/kernel/tracing/uprobe_events').writeAsStringSync(probe);
45+
if (!dryRun) {
46+
File('/sys/kernel/tracing/uprobe_events').writeAsStringSync(probe);
47+
}
4448
}
4549

4650
Future<int> _computeProbesVirtualAddress(
47-
String sharedObject, String targetSymbol) async {
51+
String sharedObject, String targetSymbol,
52+
{required bool silent}) async {
4853
int offset = 0;
4954
if (targetSymbol == 'AllocationProbePoint') {
5055
offset = await _determineAllocProbeOffset(sharedObject);
@@ -65,8 +70,10 @@ Future<int> _computeProbesVirtualAddress(
6570
}
6671

6772
final entry = matches.entries.single;
68-
print('placing uprobe on ${entry.key} at '
69-
'0x${entry.value.toRadixString(16)}+$offset');
73+
if (!silent) {
74+
print('placing uprobe on ${entry.key} at '
75+
'0x${entry.value.toRadixString(16)}+$offset');
76+
}
7077
return entry.value + offset;
7178
}
7279

@@ -106,14 +113,18 @@ Future<String> _getThreadTopOffset() async {
106113
workingDirectory: sdkSrc);
107114
final offsets =
108115
await _exec(p.join(sdkSrc, 'out/ReleaseX64/offsets_extractor'), []);
109-
final line = offsets
110-
.split('\n')
111-
.firstWhere((line) => line.contains('Thread_top_offset'));
112-
final offset = RegExp(r' = (?<offset>0x[a-f\d]+);$')
113-
.firstMatch(line)!
114-
.namedGroup('offset')!;
115-
116-
return int.parse(offset).toString();
116+
var jsonOffsets = json.decode(offsets)['offsets'] as List;
117+
for (var offset in jsonOffsets) {
118+
if (offset
119+
case {
120+
'class': 'Thread',
121+
'name': 'top_offset',
122+
'value': final String value
123+
} when int.tryParse(value) != null) {
124+
return value;
125+
}
126+
}
127+
throw 'Did not find expect json entry in offsets_extractor output.';
117128
}
118129

119130
Future<String> _exec(String executable, List<String> args,

0 commit comments

Comments
 (0)