Revert "add a benchmark test for stack size (#75039)" (#75383)

This reverts commit 9d9109aa6f.
This commit is contained in:
Shi-Hao Hong
2021-02-03 18:26:04 -08:00
committed by GitHub
parent 4dcfa28ce2
commit de683de9d5
9 changed files with 33 additions and 355 deletions

View File

@@ -19,8 +19,5 @@ const String kImageFilteredTransformAnimationRouteName = '/imagefiltered_transfo
const String kMultiWidgetConstructionRouteName = '/multi_widget_construction';
const String kHeavyGridViewRouteName = '/heavy_gridview';
const String kSimpleScrollRouteName = '/simple_scroll';
const String kStackSizeRouteName = '/stack_size';
const String kScrollableName = '/macrobenchmark_listview';
const String kStackSizeKey = 'stack_size';

View File

@@ -21,7 +21,6 @@ import 'src/picture_cache.dart';
import 'src/post_backdrop_filter.dart';
import 'src/simple_animation.dart';
import 'src/simple_scroll.dart';
import 'src/stack_size.dart';
import 'src/text.dart';
const String kMacrobenchmarks = 'Macrobenchmarks';
@@ -55,7 +54,6 @@ class MacrobenchmarksApp extends StatelessWidget {
kMultiWidgetConstructionRouteName: (BuildContext context) => const MultiWidgetConstructTable(10, 20),
kHeavyGridViewRouteName: (BuildContext context) => HeavyGridViewPage(),
kSimpleScrollRouteName: (BuildContext context) => SimpleScroll(),
kStackSizeRouteName: (BuildContext context) => StackSizePage(),
},
);
}
@@ -183,13 +181,6 @@ class HomePage extends StatelessWidget {
Navigator.pushNamed(context, kLargeImageChangerRouteName);
},
),
ElevatedButton(
key: const Key(kStackSizeRouteName),
child: const Text('Stack Size'),
onPressed: () {
Navigator.pushNamed(context, kStackSizeRouteName);
},
),
],
),
);

View File

@@ -1,122 +0,0 @@
// Copyright 2014 The Flutter Authors. 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' as ffi;
import 'dart:io' as io;
import 'package:flutter/material.dart';
import '../common.dart';
typedef GetStackPointerCallback = int Function();
// c interop function:
// void* mmap(void* addr, size_t len, int prot, int flags, int fd, off_t offset);
typedef CMmap = ffi.Pointer<ffi.Void> Function(
ffi.Pointer<ffi.Void>, ffi.IntPtr, ffi.Int32, ffi.Int32, ffi.Int32, ffi.IntPtr);
typedef DartMmap = ffi.Pointer<ffi.Void> Function(
ffi.Pointer<ffi.Void>, int, int, int, int, int);
final DartMmap mmap = ffi.DynamicLibrary.process().lookupFunction<CMmap, DartMmap>('mmap');
// c interop function:
// int mprotect(void* addr, size_t len, int prot);
typedef CMprotect = ffi.Int32 Function(ffi.Pointer<ffi.Void>, ffi.IntPtr, ffi.Int32);
typedef DartMprotect = int Function(ffi.Pointer<ffi.Void>, int, int);
final DartMprotect mprotect = ffi.DynamicLibrary.process()
.lookupFunction<CMprotect, DartMprotect>('mprotect');
const int kProtRead = 1;
const int kProtWrite = 2;
const int kProtExec = 4;
const int kMapPrivate = 0x02;
const int kMapJit = 0x0;
const int kMapAnon = 0x20;
const int kMemorySize = 16;
const int kInvalidFileDescriptor = -1;
const int kkFileMappingOffset = 0;
const int kMemoryStartingIndex = 0;
const int kExitCodeSuccess = 0;
final GetStackPointerCallback getStackPointer = () {
// Makes sure we are running on an Android arm64 device.
if (!io.Platform.isAndroid)
throw 'This benchmark test can only be run on Android arm64 devices.';
final io.ProcessResult result = io.Process.runSync('getprop', <String>['ro.product.cpu.abi']);
if (result.exitCode != 0)
throw 'Failed to retrieve CPU information.';
if (!result.stdout.toString().contains('arm64'))
throw 'This benchmark test can only be run on Android arm64 devices.';
// Creates a block of memory to store the assembly code.
final ffi.Pointer<ffi.Void> region = mmap(ffi.nullptr, kMemorySize, kProtRead | kProtWrite,
kMapPrivate | kMapAnon | kMapJit, kInvalidFileDescriptor, kkFileMappingOffset);
if (region == ffi.nullptr) {
throw 'Failed to acquire memory for the test.';
}
// Writes the assembly code into the memory block. This assembly code returns
// the memory address of the stack pointer.
region.cast<ffi.Uint8>().asTypedList(kMemorySize).setAll(
kMemoryStartingIndex,
<int>[
// "mov x0, sp" in machine code: E0030091.
0xe0, 0x03, 0x00, 0x91,
// "ret" in machine code: C0035FD6.
0xc0, 0x03, 0x5f, 0xd6
]
);
// Makes sure the memory block is executable.
if (mprotect(region, kMemorySize, kProtRead | kProtExec) != kExitCodeSuccess) {
throw 'Failed to write executable code to the memory.';
}
return region
.cast<ffi.NativeFunction<ffi.IntPtr Function()>>()
.asFunction<int Function()>();
}();
class StackSizePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Material(
child: Column(
children: <Widget>[
Container(
width: 200,
height: 100,
child: ParentWidget(),
),
],
),
);
}
}
class ParentWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final int myStackSize = getStackPointer();
return ChildWidget(parentStackSize: myStackSize);
}
}
class ChildWidget extends StatelessWidget {
const ChildWidget({this.parentStackSize, Key key}) : super(key: key);
final int parentStackSize;
@override
Widget build(BuildContext context) {
final int myStackSize = getStackPointer();
// Captures the stack size difference between parent widget and child widget
// during the rendering pipeline, i.e. one layer of stateless widget.
return Text(
'${parentStackSize - myStackSize}',
key: const ValueKey<String>(kStackSizeKey),
);
}
}