[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-01 (世界標準時間)。"],[],[],null,["# Microbenchmark instrumentation arguments\n\nConfigure the behavior of Microbenchmark with the following instrumentation\narguments. You can either add these to your Gradle configuration or apply them\ndirectly when running instrumentation from the command line. To set these\narguments for all Android Studio and command line test runs, add them to\n`testInstrumentationRunnerArguments`: \n\n android {\n defaultConfig {\n // ...\n testInstrumentationRunnerArguments[\"androidx.benchmark.dryRunMode.enable\"] = \"true\"\n }\n }\n\nYou can also set up instrumentation arguments when running the benchmarks from\nAndroid Studio. To change the arguments, do the following: \n1. Edit the run configuration by clicking **Edit** and selecting the configuration you want to edit. **Figure 1.** Edit the run configuration.\n2. Edit instrumentation arguments by clicking more_horiz next to the **Instrumentation\n arguments** field. **Figure 2.** Edit the instrumentation argument.\n3. Click add and add the required instrumentation argument. **Figure 3.** Add the instrumentation argument.\n\n\u003cbr /\u003e\n\nIf you're running the benchmark from the command line, use `-P\nandroid.testInstrumentationRunnerArguments.[name of the argument]`: \n\n ./gradlew :benchmark:connectedAndroidTest -P android.testInstrumentationRunnerArguments.androidx.benchmark.profiling.mode=StackSampling\n\nIf you're invoking am instrument command directly (which may be the case in CI\ntesting environments), pass the argument to `am instrument` with `-e`: \n\n adb shell am instrument -e androidx.benchmark.profiling.mode StackSampling -w com.example.macrobenchmark/androidx.benchmark.junit4.AndroidBenchmarkRunner\n\nFor more information about configuring benchmarks in CI, see\n[Benchmarking in CI](/topic/performance/benchmarking/benchmarking-in-ci#install-and)\n\nandroidx.benchmark.cpuEventCounter.enable (experimental)\n--------------------------------------------------------\n\nCounts the CPU events specified in `androidx.benchmark.cupEventCounter.events`.\nRequires root access.\n\n- **Argument type:** boolean\n- **Defaults to:** false\n\nandroidx.benchmark.cpuEventCounter.events (experimental)\n--------------------------------------------------------\n\nSpecifies which types of CPU events to count. To use this argument\n`androidx.benchmark.cpuEventCounter.enable` must be set to `true`.\n\n- **Argument type:** comma-separated list of strings\n- Available options:\n - `Instructions`\n - `CPUCycles`\n - `L1DReferences`\n - `L1DMisses`\n - `BranchInstructions`\n - `BranchMisses`\n - `L1IReferences`\n - `L1IMisses`\n- **Defaults to:** `Instructions`, `CpuCycles`, `BranchMisses`\n\nandroidx.benchmark.dryRunMode.enable\n------------------------------------\n\nLets you run benchmarks in single loop to verify that they work properly.\n\nThis means:\n\n- [Configuration errors](/topic/performance/benchmarking/microbenchmark-write#configuration-errors) aren't enforced (for example, to make it easier to run with regular correctness tests on emulators)\n- Benchmark runs only a single loop, with no warmup\n- Measurements and traces aren't captured to reduce runtime\n\nThis optimizes for test throughput and validating benchmark logic over build\nand measurement correctness.\n\n- **Argument type:** boolean\n- **Defaults to:** `false`\n\nandroidx.benchmark.killExistingPerfettoRecordings\n-------------------------------------------------\n\nBenchmark by default kills any existing Perfetto (System Trace) recordings when\nstarting a new trace to reduce interference. To disable this behavior, pass\n`false`.\n\n- **Argument type:** boolean\n- **Defaults to:** `true`\n\nandroidx.benchmark.output.enable\n--------------------------------\n\nEnables writing the result JSON file to external storage.\n\n- **Argument type:** boolean\n- **Defaults to:** `true`\n\nandroidx.benchmark.profiling.mode\n---------------------------------\n\nAllows capturing trace files while running the benchmarks. See [Profile a\nMicrobenchmark](/studio/profile/microbenchmark-profile) for available options.\n\nNote that some Android OS versions don't support method tracing without\nsubsequent measurements being affected. Microbenchmark throws an exception\nto prevent this, so use the default argument to capture method traces only when\nit's safe to do so. See\n[Issue #316174880](https://issuetracker.google.com/issues/316174880).\n\n- **Argument type:** string\n- Available options:\n - `MethodTracing`\n - `StackSampling`\n - `None`\n- **Defaults to:** Safe version of `MethodTracing` which only captures a method trace if the device can do so without affecting measurements.\n\nandroidx.benchmark.suppressErrors\n---------------------------------\n\nAccepts a comma-separated list of errors to turn into warnings.\n\n- **Argument type:** list of strings\n- Available options:\n - `DEBUGGABLE`\n - `LOW-BATTERY`\n - `EMULATOR`\n - `CODE-COVERAGE`\n - `UNLOCKED`\n - `SIMPLEPERF`\n - `ACTIVITY-MISSING`\n- **Defaults to:** an empty list\n\nadditionalTestOutputDir\n-----------------------\n\nConfigures where JSON benchmark reports and profiling results are saved on\ndevice.\n\n- **Argument type:** file path string\n- **Defaults to:** test APK's external directory\n\nlistener\n--------\n\nYou might get inconsistent benchmark results if unrelated background work gets\nexecuted while the benchmark is running.\n\nTo disable background work during benchmarking set the `listener`\ninstrumentation argument type to\n`androidx.benchmark.junit4.SideEffectRunListener`.\n\n- **Argument type:** string\n- Available options:\n - `androidx.benchmark.junit4.SideEffectRunListener`\n- **Defaults to:** not specified\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Macrobenchmark instrumentation arguments](/topic/performance/benchmarking/macrobenchmark-instrumentation-args)\n- [Profile a Microbenchmark](/topic/performance/benchmarking/microbenchmark-profile)\n- [Create Baseline Profiles {:#creating-profile-rules}](/topic/performance/baselineprofiles/create-baselineprofile)"]]