mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 08:07:11 +00:00
[sdk] Add NativeRuntime.buildId to dart:developer.
TEST=vm/dart/build_id Issue: https://github.com/dart-lang/sdk/issues/51941 CoreLibraryReviewExempt: Native runtime only API Change-Id: Ib3757480f0eab6d147385a87adf657f4f709ec4e Cq-Include-Trybots: luci.dart.try:vm-aot-dwarf-linux-product-x64-try,vm-aot-linux-debug-simarm_x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-release-x64-try,vm-aot-mac-product-arm64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-linux-product-x64-try,vm-aot-win-release-x64-try,vm-aot-win-product-x64-try,vm-aot-win-debug-x64c-try,vm-aot-android-release-arm_x64-try,vm-fuchsia-release-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307122 Reviewed-by: Slava Egorov <vegorov@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Tess Strickland <sstrickl@google.com> Reviewed-by: Lasse Nielsen <lrn@google.com>
This commit is contained in:
parent
1c3011cbf0
commit
97a09b90c8
8 changed files with 66 additions and 0 deletions
|
@ -18,6 +18,7 @@
|
|||
#include "vm/object_store.h"
|
||||
#include "vm/service.h"
|
||||
#include "vm/service_isolate.h"
|
||||
#include "vm/zone_text_buffer.h"
|
||||
|
||||
namespace dart {
|
||||
|
||||
|
@ -179,6 +180,25 @@ DEFINE_NATIVE_ENTRY(Developer_reachability_barrier, 0, 0) {
|
|||
#endif
|
||||
}
|
||||
|
||||
DEFINE_NATIVE_ENTRY(Developer_NativeRuntime_buildId, 0, 0) {
|
||||
#if defined(DART_PRECOMPILED_RUNTIME)
|
||||
IsolateGroup* isolate_group = thread->isolate_group();
|
||||
ASSERT(isolate_group != nullptr);
|
||||
if (const uint8_t* instructions =
|
||||
isolate_group->source()->snapshot_instructions) {
|
||||
const auto& build_id = OS::GetAppBuildId(instructions);
|
||||
if (build_id.data != nullptr) {
|
||||
ZoneTextBuffer buffer(zone);
|
||||
for (intptr_t i = 0; i < build_id.len; i++) {
|
||||
buffer.Printf("%2.2x", build_id.data[i]);
|
||||
}
|
||||
return String::New(buffer.buffer());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return String::null();
|
||||
}
|
||||
|
||||
DEFINE_NATIVE_ENTRY(Developer_NativeRuntime_writeHeapSnapshotToFile, 0, 1) {
|
||||
#if defined(DART_ENABLE_HEAP_SNAPSHOT_WRITER)
|
||||
const String& filename =
|
||||
|
|
20
runtime/tests/vm/dart/build_id_test.dart
Normal file
20
runtime/tests/vm/dart/build_id_test.dart
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
import 'use_flag_test_helper.dart';
|
||||
|
||||
void main() {
|
||||
final buildId = NativeRuntime.buildId;
|
||||
if (isAOTRuntime) {
|
||||
Expect.isNotNull(buildId);
|
||||
Expect.isTrue(buildId!.isNotEmpty, 'Build ID is an empty string');
|
||||
} else {
|
||||
Expect.isNull(buildId); // Should be null in JIT mode.
|
||||
}
|
||||
print(buildId);
|
||||
}
|
|
@ -78,6 +78,7 @@ namespace dart {
|
|||
V(Developer_log, 8) \
|
||||
V(Developer_postEvent, 2) \
|
||||
V(Developer_webServerControl, 3) \
|
||||
V(Developer_NativeRuntime_buildId, 0) \
|
||||
V(Developer_NativeRuntime_writeHeapSnapshotToFile, 1) \
|
||||
V(Developer_reachability_barrier, 0) \
|
||||
V(Double_getIsNegative, 1) \
|
||||
|
|
|
@ -233,6 +233,9 @@ UserTag getCurrentTag() => _currentTag;
|
|||
|
||||
@patch
|
||||
abstract final class NativeRuntime {
|
||||
@patch
|
||||
static String? get buildId => null;
|
||||
|
||||
@patch
|
||||
static void writeHeapSnapshotToFile(String filepath) =>
|
||||
throw UnsupportedError(
|
||||
|
|
|
@ -153,6 +153,9 @@ UserTag getCurrentTag() => _currentTag;
|
|||
|
||||
@patch
|
||||
abstract final class NativeRuntime {
|
||||
@patch
|
||||
static String? get buildId => null;
|
||||
|
||||
@patch
|
||||
static void writeHeapSnapshotToFile(String filepath) =>
|
||||
throw UnsupportedError(
|
||||
|
|
|
@ -181,6 +181,10 @@ external String _getIsolateIDFromSendPort(SendPort sendPort);
|
|||
|
||||
@patch
|
||||
abstract final class NativeRuntime {
|
||||
@patch
|
||||
@pragma("vm:external-name", "Developer_NativeRuntime_buildId")
|
||||
external static String? get buildId;
|
||||
|
||||
@patch
|
||||
@pragma("vm:external-name", "Developer_NativeRuntime_writeHeapSnapshotToFile")
|
||||
external static void writeHeapSnapshotToFile(String filepath);
|
||||
|
|
|
@ -60,6 +60,9 @@ void _reportTaskEvent(
|
|||
|
||||
@patch
|
||||
abstract final class NativeRuntime {
|
||||
@patch
|
||||
static String? get buildId => null;
|
||||
|
||||
@patch
|
||||
static void writeHeapSnapshotToFile(String filepath) =>
|
||||
throw UnsupportedError(
|
||||
|
|
|
@ -143,6 +143,18 @@ external int get reachabilityBarrier;
|
|||
|
||||
/// Functionality available on the native runtime.
|
||||
abstract final class NativeRuntime {
|
||||
/// The build ID for the running application.
|
||||
///
|
||||
/// The build ID of an application is a string containing a hexadecimal
|
||||
/// representation of an arbitrarily sized sequence of bytes. This string
|
||||
/// can be used to match a specific ahead-of-time compiled version of an
|
||||
/// application, for example, to determine which debugging artifacts emitted
|
||||
/// during compilation should be used to translate crash and error reports.
|
||||
///
|
||||
/// The build ID is only available for ahead-of-time compiled programs. If a
|
||||
/// build ID is not available, the value is `null`.
|
||||
external static String? get buildId;
|
||||
|
||||
/// Writes a snapshot of the heap to [filepath].
|
||||
///
|
||||
/// The [filepath] should be a native file path that can be opened for writing.
|
||||
|
|
Loading…
Reference in a new issue