Add the rest of the CUJs to the new benchmark script.

Change-Id: Iabf8875f9d77a3d50a37f6ab1230bc9f473a15dd
This commit is contained in:
Joe Onorato
2023-12-20 04:00:12 +00:00
parent 45e9ce5d49
commit 01277d4067

View File

@@ -23,9 +23,12 @@ import datetime
import json import json
import os import os
import pathlib import pathlib
import random
import re
import shutil import shutil
import subprocess import subprocess
import time import time
import uuid
import pretty import pretty
import utils import utils
@@ -137,9 +140,23 @@ def NoChange():
return Change(label="No change", change=lambda: None, undo=lambda: None) return Change(label="No change", change=lambda: None, undo=lambda: None)
def Create(filename):
"Create an action to create `filename`. The parent directory must exist."
def create():
with open(filename, "w") as f:
pass
def delete():
os.remove(filename)
return Change(
label=f"Create {filename}",
change=create,
undo=delete,
)
def Modify(filename, contents, before=None): def Modify(filename, contents, before=None):
"""Create an action to modify `filename` by appending `contents` before the last instances """Create an action to modify `filename` by appending the result of `contents`
of `before` in the file. before the last instances of `before` in the file.
Raises an error if `before` doesn't appear in the file. Raises an error if `before` doesn't appear in the file.
""" """
@@ -151,13 +168,29 @@ def Modify(filename, contents, before=None):
raise FatalError() raise FatalError()
else: else:
index = len(orig.contents) index = len(orig.contents)
modified = FileSnapshot(filename, orig.contents[:index] + contents + orig.contents[index:]) modified = FileSnapshot(filename, orig.contents[:index] + contents() + orig.contents[index:])
if False:
print(f"Modify: {filename}")
x = orig.contents.replace("\n", "\n ORIG")
print(f" ORIG {x}")
x = modified.contents.replace("\n", "\n MODIFIED")
print(f" MODIFIED {x}")
return Change( return Change(
label="Modify " + filename, label="Modify " + filename,
change=lambda: modified.write(), change=lambda: modified.write(),
undo=lambda: orig.write() undo=lambda: orig.write()
) )
def AddJavaField(filename, prefix):
return Modify(filename,
lambda: f"{prefix} static final int BENCHMARK = {random.randint(0, 1000000)};\n",
before="}")
def Comment(prefix, suffix=""):
return lambda: prefix + " " + str(uuid.uuid4()) + suffix
class BenchmarkReport(): class BenchmarkReport():
"Information about a run of the benchmark" "Information about a run of the benchmark"
@@ -506,26 +539,121 @@ benchmarks:
# Assumes that we've already chdired to the root of the tree. # Assumes that we've already chdired to the root of the tree.
self._benchmarks = [ self._benchmarks = [
Benchmark(id="full", Benchmark(id="full",
title="Full build", title="Full build",
change=Clean(), change=Clean(),
modules=["droid"], modules=["droid"],
preroll=0, preroll=0,
postroll=3 postroll=3,
), ),
Benchmark(id="nochange", Benchmark(id="nochange",
title="No change", title="No change",
change=NoChange(), change=NoChange(),
modules=["droid"], modules=["droid"],
preroll=2, preroll=2,
postroll=3 postroll=3,
), ),
Benchmark(id="unreferenced",
title="Create unreferenced file",
change=Create("bionic/unreferenced.txt"),
modules=["droid"],
preroll=1,
postroll=2,
),
Benchmark(id="modify_bp", Benchmark(id="modify_bp",
title="Modify Android.bp", title="Modify Android.bp",
change=Modify("bionic/libc/Android.bp", "// Comment"), change=Modify("bionic/libc/Android.bp", Comment("//")),
modules=["droid"], modules=["droid"],
preroll=1, preroll=1,
postroll=3 postroll=3,
), ),
Benchmark(id="modify_stdio",
title="Modify stdio.cpp",
change=Modify("bionic/libc/stdio/stdio.cpp", Comment("//")),
modules=["libc"],
preroll=1,
postroll=2,
),
Benchmark(id="modify_adbd",
title="Modify adbd",
change=Modify("packages/modules/adb/daemon/main.cpp", Comment("//")),
modules=["adbd"],
preroll=1,
postroll=2,
),
Benchmark(id="services_private_field",
title="Add private field to ActivityManagerService.java",
change=AddJavaField("frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java",
"private"),
modules=["services"],
preroll=1,
postroll=2,
),
Benchmark(id="services_public_field",
title="Add public field to ActivityManagerService.java",
change=AddJavaField("frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java",
"/** @hide */ public"),
modules=["services"],
preroll=1,
postroll=2,
),
Benchmark(id="services_api",
title="Add API to ActivityManagerService.javaa",
change=AddJavaField("frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java",
"@android.annotation.SuppressLint(\"UnflaggedApi\") public"),
modules=["services"],
preroll=1,
postroll=2,
),
Benchmark(id="framework_private_field",
title="Add private field to Settings.java",
change=AddJavaField("frameworks/base/core/java/android/provider/Settings.java",
"private"),
modules=["framework-minus-apex"],
preroll=1,
postroll=2,
),
Benchmark(id="framework_public_field",
title="Add public field to Settings.java",
change=AddJavaField("frameworks/base/core/java/android/provider/Settings.java",
"/** @hide */ public"),
modules=["framework-minus-apex"],
preroll=1,
postroll=2,
),
Benchmark(id="framework_api",
title="Add API to Settings.java",
change=AddJavaField("frameworks/base/core/java/android/provider/Settings.java",
"@android.annotation.SuppressLint(\"UnflaggedApi\") public"),
modules=["framework-minus-apex"],
preroll=1,
postroll=2,
),
Benchmark(id="modify_framework_resource",
title="Modify framework resource",
change=Modify("frameworks/base/core/res/res/values/config.xml",
lambda: str(uuid.uuid4()),
before="</string>"),
modules=["framework-minus-apex"],
preroll=1,
postroll=2,
),
Benchmark(id="add_framework_resource",
title="Add framework resource",
change=Modify("frameworks/base/core/res/res/values/config.xml",
lambda: f"<string name=\"BENCHMARK\">{uuid.uuid4()}</string>",
before="</resources>"),
modules=["framework-minus-apex"],
preroll=1,
postroll=2,
),
Benchmark(id="add_systemui_field",
title="Add SystemUI field",
change=AddJavaField("frameworks/base/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java",
"public"),
modules=["SystemUI"],
preroll=1,
postroll=2,
),
] ]
def _error(self, message): def _error(self, message):