使用 Vogar 进行简单基准测试

发布于 2024-12-17 14:14:16 字数 134 浏览 1 评论 0 原文

我想为android编写简单的基准测试软件。我研究并发现了Caliper + Vogar。但没有关于它们的例子。有人用吗?我需要简单的代码来从 android Activity 调用 Caliper Benchmarks。

感谢您的帮助。

I want to write simple benchmark software for android. I researched and found Caliper + Vogar. But there is no example about them. Is there anyone use it ? I need simple code to call Caliper Benchmarks from android Activity.

Thanks for help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痴者 2024-12-24 14:14:16

中有一个适用于 Android 的 Caliper 基准测试的完整示例,但不是针对 Activity 的Android应用程序测试指南,其中还解释了:

Caliper 基准测试正常扩展 com.google.caliper.SimpleBenchmark
它实现了 Benchmark 接口。基准的结构如下
与 JUnit 3 测试类似的方式并保持相同的结构
不同之处在于这里的基准测试以前缀时间开始
反对测试。

有问题的基准如下所示:

public final void timeCelsiusToFahrenheit(int reps) {
         for (int i=0; i < reps; i++) {
           for (double t: temps) {
             TemperatureConverter.celsiusToFahrenheit(t);
           }
         }
}

最有趣的功能之一是 caliper 可以上传基准测试结果,您可以以图形方式比较它们

卡尺基准

There's a complete example of a Caliper Benchmark for Android, though not for an Activity, in Android Application Testing Guide, which also explains:

Caliper benchmark extends normally com.google.caliper.SimpleBenchmark
which implements the Benchmark interface. Benchmarks are structured in
a similar fashion as JUnit 3 tests and maintain the same structure
with the difference that here benchmarks start with the prefix time as
opposed to test.

The benchmarks in question looks like this:

public final void timeCelsiusToFahrenheit(int reps) {
         for (int i=0; i < reps; i++) {
           for (double t: temps) {
             TemperatureConverter.celsiusToFahrenheit(t);
           }
         }
}

One of the most interesting features is that caliper can upload the benchmark results and you can compare them graphically

caliper benchmarks

栀梦 2024-12-24 14:14:16

最近,我做了和你一样的事情,并且我成功了

1.download &配置构建 aosp 的环境

2.build aosp

3.build /external/vogar,您将在 out/host/linux-x86/bin/vogar 下得到 vogar

4.使用 caliper 编写测试代码

5.在主机上运行测试vogar

vogar --mode app_process --benchmark

vogar 会自动将您的代码编译为 dex 文件并将它们推送到设备,

调用 app_process(将调用注册了 android JNI 的 dalvikvm 命令)来运行 vogar 测试运行程序来运行您的测试用例

vogar 需要您指定的类路径来编译或构建您的测试用例

以下是我运行 vogar 时的日志:

dvdface@ubuntu:~/Source/aosp/out/host/linux-x86/bin$ ./vogar --mode

app_process --基准测试

~/Source/aosp/libcore/benchmarks/src/benchmarks/AdditionBenchmark.java

操作:1 个执行

[/home/dvdface/Source/aosp/prebuilts/sdk/tools/jack, -D,

jack.java.source.version=1.8,-D,jack.android.min-api-level=o-b1,

-cp, /home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/core-libart_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/core-oj_intermediat es/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/conscrypt_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/好的http _intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/legacy-test_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/ JAVA_LI BRARIES/bouncycastle_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/ext_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common /obj/JAVA_LIBRARIES/framework_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/telephony-common_intermediates/classes.jack:/home/dvdface/Source /aosp/out/target/common/obj/JAVA_LIBRARIES/mms-common_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jack:/hom e/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/android.policy_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/services_intermediate s/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/apache-xml_intermediates/classes.jack:/home/dvdface/Source/aosp/out/host/linux-x86/框架/vogar.jar,

--输出插孔,/tmp/vogar/24a8baa0-30f1-4861-99c1-6660e97bf1d8/benchmarks.AdditionBenchmark/benchmarks.AdditionBenchmark.jack,

--导入资源,/tmp/vogar/24a8baa0-30f1-4861-99c1-6660e97bf1d8/benchmarks.AdditionBenchmarkexecuting

[adb、shell、mkdir、

/data/local/tmp/vogar/run/benchmarks.AdditionBenchmark]

正在执行[/home/dvdface/Source/aosp/prebuilts/sdk/tools/jack,

--output-dex-zip,/tmp/vogar/24a8baa0-30f1-4861-99c1-6660e97bf1d8/benchmarks.AdditionBenchmark/benchmarks.AdditionBenchmark.dex.jar,

-D,jack.java.source.version=1.8,-D,jack.android.min-api-level=o-b1,--multi-dex,本机,--import,/tmp/vogar/ 24a8baa0-30f1-4861-99c1-6660e97bf1d8/benchmarks.AdditionBenchmark/benchmarks.AdditionBenchmark.jackAction

benchmarks.AdditionBenchmark 执行 [adb, shell, cd

/data/local/tmp/vogar/run/benchmarks.AdditionBenchmark &&

ANDROID_DATA=/data/local/tmp/vogar app_process

-Djava.class.path=/data/local/tmp/vogar/run/benchmarks.AdditionBenchmark.dex.jar

-Djava.io.tmpdir=/data/local/tmp/vogar/run/benchmarks.AdditionBenchmark

-Duser.home=/data/local/tmp/vogar/run/user.home /data/local/tmp/vogar/run/benchmarks.AdditionBenchmark

vogar.target.TestRunn 实验选择:

 基准方法:[timeAddConstantToLocalDouble、timeAddConstantToLocalFloat、timeAddConstantToLocalInt、

timeAddConstantToLocalLong,timeAddTwoLocalDoubles,

timeAddTwoLocalFloats、timeAddTwoLocalInts、timeAddTwoLocalLongs]

 仪器:[运行时]

  用户参数:{}

  虚拟机:[app_process]

  选择类型:完全笛卡尔积

该选择产生 8 个实验。

试验报告(8 中的 1):

  实验 {instrument=runtime, benchmarkMethod=timeAddConstantToLocalDouble, vm=app_process,

参数={}}

<前><代码> 结果:

运行时间(ns):最小值=3.48,第一部分=3.48,中位数=3.48,平均值=3.48,第三部分=3.48,最大值=3.48

试验报告(8 之 2):

实验 {instrument=runtime, benchmarkMethod=timeAddConstantToLocalFloat, vm=app_process,

参数={}}

<前><代码> 结果:

运行时间(ns):最小值=5.28,第一部分=5.28,中位数=5.28,平均值=5.28,第三部分=5.28,最大值=5.28

试验报告(8 中的 3):

实验 {instrument=runtime, benchmarkMethod=timeAddConstantToLocalInt, vm=app_process,

参数={}}

<前><代码> 结果:

运行时间(ns):最小值=2.11,第一部分=2.11,中位数=2.11,平均值=2.11,第三部分=2.11,最大值=2.11

试用报告(8 中的 4):

实验 {instrument=runtime, benchmarkMethod=timeAddConstantToLocalLong, vm=app_process,

参数={}}

<前><代码> 结果:

运行时间(ns):最小值=2.10,第一部分=2.10,中位数=2.10,平均值=2.10,第三部分=2.10,最大值=2.10

试用报告(8 中的 5):

实验 {instrument=runtime、 benchmarkMethod=timeAddTwoLocalDoubles、vm=app_process、parameters={}}

结果:

运行时间(ns):最小值=5.31,第一部分=5.31,中位数=5.31,平均值=5.31,第三部分=5.31,最大值=5.31

试用报告(8 中的 6):

实验 {instrument=runtime、 benchmarkMethod=timeAddTwoLocalFloats、vm=app_process、parameters={}}

结果:

运行时间(ns):最小值=5.23,第一部分=5.23,中位数=5.23,平均值=5.23,第三部分=5.23,最大值=5.23

试用报告(8 中的 7):

实验 {instrument=runtime、 benchmarkMethod=timeAddTwoLocalInts、vm=app_process、parameters={}}

结果:

运行时间(ns):最小值=1.63,第一部分=1.63,中位数=1.63,平均值=1.63,第三部分=1.63,最大值=1.63

试用报告(8 / 8):

实验 {instrument=runtime、 benchmarkMethod=timeAddTwoLocalLongs、vm=app_process、parameters={}}

结果:

运行时间(ns):最小值=2.14,第一部分=2.14,中位数=2.14,平均值=2.14,第三部分=2.14,最大值=2.14

收集了 8 个测量值:

1 台仪器

1 个虚拟机

8 个基准

执行完成:19.90 秒。

Dalvik 不支持 Instrument com.google.caliper.runner.AllocationInstrument,忽略

Dalvik 不支持 Instrument com.google.caliper.runner.AllocationInstrument,忽略

有些试验无法上传。考虑手动上传它们。 benchmarks.AdditionBenchmark OK (SUCCESS) 收到退出值 0

破坏命令 adb shell cd

/data/local/tmp/vogar/run/benchmarks.AdditionBenchmark &&

ANDROID_DATA=/data/local/tmp/vogar app_process

-Djava.class.path=/data/local/tmp/vogar/run/benchmarks.AdditionBenchmark.dex.jar

-Djava.io.tmpdir=/data/local/tmp/vogar/run/benchmarks.AdditionBenchmark

-Duser.home=/data/local/tmp/vogar/run/user.home /data/local/tmp/vogar/run/benchmarks.AdditioMoving

/data/local/tmp/vogar/run/benchmarks.AdditionBenchmark/benchmarks.AdditionBenchmark.2018-04-01T15:43:17Z.json

to ./vogar-results 结果: 1. 全部成功。花了 10 分 35 秒。

recently , I do the same thing as you, and I succeed

1.download & configure environment for build aosp

2.build aosp

3.build /external/vogar, you will get vogar under out/host/linux-x86/bin/vogar

4.write your test code using caliper

5.run you test on the host with vogar

vogar --mode app_process --benchmark

vogar will automatically compile your code to dex file and push them to device,

call the app_process(which will call dalvikvm command with android JNI registerd) to run vogar test runner to run your testcase

vogar need your specifing classpath to compile or to build your testcase

the following is my log when I ran the vogar:

dvdface@ubuntu:~/Source/aosp/out/host/linux-x86/bin$ ./vogar --mode

app_process --benchmark

~/Source/aosp/libcore/benchmarks/src/benchmarks/AdditionBenchmark.java

Actions: 1 executing

[/home/dvdface/Source/aosp/prebuilts/sdk/tools/jack, -D,

jack.java.source.version=1.8, -D, jack.android.min-api-level=o-b1,

-cp, /home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/core-libart_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/core-oj_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/conscrypt_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/okhttp_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/legacy-test_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/bouncycastle_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/ext_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/telephony-common_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/mms-common_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/android.policy_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/services_intermediates/classes.jack:/home/dvdface/Source/aosp/out/target/common/obj/JAVA_LIBRARIES/apache-xml_intermediates/classes.jack:/home/dvdface/Source/aosp/out/host/linux-x86/framework/vogar.jar,

--output-jack, /tmp/vogar/24a8baa0-30f1-4861-99c1-6660e97bf1d8/benchmarks.AdditionBenchmark/benchmarks.AdditionBenchmark.jack,

--import-resource, /tmp/vogar/24a8baa0-30f1-4861-99c1-6660e97bf1d8/benchmarks.AdditionBenchmarkexecuting

[adb, shell, mkdir,

/data/local/tmp/vogar/run/benchmarks.AdditionBenchmark]

executing [/home/dvdface/Source/aosp/prebuilts/sdk/tools/jack,

--output-dex-zip, /tmp/vogar/24a8baa0-30f1-4861-99c1-6660e97bf1d8/benchmarks.AdditionBenchmark/benchmarks.AdditionBenchmark.dex.jar,

-D, jack.java.source.version=1.8, -D, jack.android.min-api-level=o-b1, --multi-dex, native, --import, /tmp/vogar/24a8baa0-30f1-4861-99c1-6660e97bf1d8/benchmarks.AdditionBenchmark/benchmarks.AdditionBenchmark.jackAction

benchmarks.AdditionBenchmark executing [adb, shell, cd

/data/local/tmp/vogar/run/benchmarks.AdditionBenchmark &&

ANDROID_DATA=/data/local/tmp/vogar app_process

-Djava.class.path=/data/local/tmp/vogar/run/benchmarks.AdditionBenchmark.dex.jar

-Djava.io.tmpdir=/data/local/tmp/vogar/run/benchmarks.AdditionBenchmark

-Duser.home=/data/local/tmp/vogar/run/user.home /data/local/tmp/vogar/run/benchmarks.AdditionBenchmark

vogar.target.TestRunn Experiment selection:

  Benchmark Methods:   [timeAddConstantToLocalDouble, timeAddConstantToLocalFloat, timeAddConstantToLocalInt,

timeAddConstantToLocalLong, timeAddTwoLocalDoubles,

timeAddTwoLocalFloats, timeAddTwoLocalInts, timeAddTwoLocalLongs]

  Instruments:   [runtime]

  User parameters:   {}

  Virtual machines:  [app_process]

  Selection type:    Full cartesian product

This selection yields 8 experiments.

Trial Report (1 of 8):

  Experiment {instrument=runtime, benchmarkMethod=timeAddConstantToLocalDouble, vm=app_process,

parameters={}}

  Results:

    runtime(ns): min=3.48, 1st qu.=3.48, median=3.48, mean=3.48, 3rd qu.=3.48, max=3.48

Trial Report (2 of 8):

  Experiment {instrument=runtime, benchmarkMethod=timeAddConstantToLocalFloat, vm=app_process,

parameters={}}

  Results:

    runtime(ns): min=5.28, 1st qu.=5.28, median=5.28, mean=5.28, 3rd qu.=5.28, max=5.28

Trial Report (3 of 8):

  Experiment {instrument=runtime, benchmarkMethod=timeAddConstantToLocalInt, vm=app_process,

parameters={}}

  Results:

    runtime(ns): min=2.11, 1st qu.=2.11, median=2.11, mean=2.11, 3rd qu.=2.11, max=2.11

Trial Report (4 of 8):

  Experiment {instrument=runtime, benchmarkMethod=timeAddConstantToLocalLong, vm=app_process,

parameters={}}

  Results:

    runtime(ns): min=2.10, 1st qu.=2.10, median=2.10, mean=2.10, 3rd qu.=2.10, max=2.10

Trial Report (5 of 8):

  Experiment {instrument=runtime, benchmarkMethod=timeAddTwoLocalDoubles, vm=app_process, parameters={}}

  Results:

    runtime(ns): min=5.31, 1st qu.=5.31, median=5.31, mean=5.31, 3rd qu.=5.31, max=5.31

Trial Report (6 of 8):

  Experiment {instrument=runtime, benchmarkMethod=timeAddTwoLocalFloats, vm=app_process, parameters={}}

  Results:

    runtime(ns): min=5.23, 1st qu.=5.23, median=5.23, mean=5.23, 3rd qu.=5.23, max=5.23

Trial Report (7 of 8):

  Experiment {instrument=runtime, benchmarkMethod=timeAddTwoLocalInts, vm=app_process, parameters={}}

  Results:

    runtime(ns): min=1.63, 1st qu.=1.63, median=1.63, mean=1.63, 3rd qu.=1.63, max=1.63

Trial Report (8 of 8):

  Experiment {instrument=runtime, benchmarkMethod=timeAddTwoLocalLongs, vm=app_process, parameters={}}

  Results:

    runtime(ns): min=2.14, 1st qu.=2.14, median=2.14, mean=2.14, 3rd qu.=2.14, max=2.14

Collected 8 measurements from:

  1 instrument(s)

  1 virtual machine(s)

  8 benchmark(s)

Execution complete: 19.90 s.

Instrument com.google.caliper.runner.AllocationInstrument not supported on Dalvik, ignoring

Instrument com.google.caliper.runner.AllocationInstrument not supported on Dalvik, ignoring

Some trials failed to upload. Consider uploading them manually.   benchmarks.AdditionBenchmark OK (SUCCESS) received exit value 0 from

destroyed command adb shell cd

/data/local/tmp/vogar/run/benchmarks.AdditionBenchmark &&

ANDROID_DATA=/data/local/tmp/vogar app_process

-Djava.class.path=/data/local/tmp/vogar/run/benchmarks.AdditionBenchmark.dex.jar

-Djava.io.tmpdir=/data/local/tmp/vogar/run/benchmarks.AdditionBenchmark

-Duser.home=/data/local/tmp/vogar/run/user.home /data/local/tmp/vogar/run/benchmarks.AdditioMoving

/data/local/tmp/vogar/run/benchmarks.AdditionBenchmark/benchmarks.AdditionBenchmark.2018-04-01T15:43:17Z.json

to ./vogar-results Outcomes: 1. All successful. Took 10m35s.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文