dart-sdk/benchmarks/FfiCall/dart/dlopen_helper.dart
Daco Harkes fbf13f561f [benchmarks/ffi] Add micro and macro benchmarks for dart:ffi
Adds micro benchmarks to measure low level (1) C memory reads and writes from Dart and (2) calls from Dart into C. This CL also adds a macro benchmark to measure overall performance using BoringSSL to digest data. The shared libraries are precompiled for Linux and live in cipd packages. The benchmarks run on all hardware architectures (with the exception of Linux'es hardfp on Arm32: https://github.com/dart-lang/sdk/issues/36309).

Issue: https://github.com/dart-lang/sdk/issues/36247

Change-Id: I8dfb30cc66a26a2942bb09194c5eb0da0b6ca1b5
Cq-Include-Trybots: luci.dart.try:benchmark-linux-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/108724
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Jonas Termansen <sortie@google.com>
Auto-Submit: Daco Harkes <dacoharkes@google.com>
2019-07-19 14:59:57 +00:00

59 lines
1.7 KiB
Dart

// Copyright (c) 2019, 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:ffi';
import 'dart:io';
const kArm = "arm";
const kArm64 = "arm64";
const kIa32 = "ia32";
const kX64 = "x64";
// https://stackoverflow.com/questions/45125516/possible-values-for-uname-m
final _unames = {
"arm": kArm,
"aarch64_be": kArm64,
"aarch64": kArm64,
"armv8b": kArm64,
"armv8l": kArm64,
"i386": kIa32,
"i686": kIa32,
"x86_64": kX64,
};
String _checkRunningMode(String architecture) {
// Check if we're running in 32bit mode.
final int pointerSize = sizeOf<IntPtr>();
if (pointerSize == 4 && architecture == kX64) return kIa32;
if (pointerSize == 4 && architecture == kArm64) return kArm;
return architecture;
}
String _architecture() {
final String uname = Process.runSync("uname", ["-m"]).stdout.trim();
final String architecture = _unames[uname];
if (architecture == null)
throw Exception("Unrecognized architecture: '$uname'");
// Check if we're running in 32bit mode.
return _checkRunningMode(architecture);
}
String _platformPath(String name, {String path = ""}) {
if (Platform.isMacOS || Platform.isIOS)
return "${path}mac/${_architecture()}/lib$name.dylib";
if (Platform.isWindows)
return "${path}win/${_checkRunningMode(kX64)}/$name.dll";
// Unknown platforms default to Unix implementation.
return "${path}linux/${_architecture()}/lib$name.so";
}
DynamicLibrary dlopenPlatformSpecific(String name, {String path}) {
final String fullPath = _platformPath(name, path: path);
return DynamicLibrary.open(fullPath);
}