با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
معیارها نوع اصلی اطلاعات استخراج شده از معیارهای شما هستند. آنها بهعنوان یک List به تابع measureRepeated ارسال میشوند که به شما امکان میدهد چندین معیار اندازهگیری شده را همزمان مشخص کنید. حداقل یک نوع معیار برای اجرای معیار لازم است.
قطعه کد زیر زمان بندی فریم و معیارهای بخش ردیابی سفارشی را ثبت می کند:
نتایج بنچمارک همانطور که در شکل 1 نشان داده شده است به Android Studio خروجی می شود. اگر چندین معیار تعریف شده باشد، همه آنها در خروجی ترکیب می شوند.
شکل 1. نتایج TraceSectionMetric و FrameTimingMetric .
StartupTimingMetric
StartupTimingMetric معیارهای زمان بندی راه اندازی برنامه را با مقادیر زیر ثبت می کند:
timeToInitialDisplayMs : مدت زمانی از زمانی که سیستم قصد راه اندازی را دریافت می کند تا زمانی که اولین فریم از Activity مقصد را ارائه می دهد.
timeToFullDisplayMs : مدت زمانی است که سیستم قصد راه اندازی را دریافت می کند تا زمانی که برنامه به طور کامل با استفاده از متد reportFullyDrawn() رسم شده است. اندازهگیری در پایان رندر کردن اولین فریم پس از فراخوانی reportFullyDrawn() یا حاوی آن متوقف میشود. این اندازهگیری ممکن است در Android 10 (سطح API 29) و قبل از آن در دسترس نباشد.
StartupTimingMetric مقادیر حداقل، میانه و حداکثر را از تکرارهای راه اندازی خروجی می دهد. برای ارزیابی بهبود استارتآپ، باید روی مقادیر متوسط تمرکز کنید، زیرا آنها بهترین تخمین را از زمان معمول راهاندازی ارائه میدهند. برای اطلاعات بیشتر در مورد آنچه که در زمان راهاندازی برنامه نقش دارد، به زمان راهاندازی برنامه مراجعه کنید.
شکل 2. نتایج StartupTimingMetric .
FrameTimingMetric
FrameTimingMetric اطلاعات زمانبندی را از فریمهای تولید شده توسط یک معیار، مانند پیمایش یا انیمیشن میگیرد و مقادیر زیر را خروجی میدهد:
frameOverrunMs : مدت زمانی است که یک فریم معین ضرب الاجل خود را از دست می دهد. اعداد مثبت نشان دهنده افت فریم و ژانک یا لکنت قابل مشاهده است. اعداد منفی نشان می دهد که سرعت یک فریم چقدر بیشتر از ضرب الاجل است. توجه: این فقط در Android 12 (سطح API 31) و بالاتر در دسترس است.
frameDurationCpuMs : مدت زمانی که فریم طول می کشد تا بر روی CPU در رشته UI و RenderThread تولید شود.
این اندازه گیری ها در توزیع صدک 50، 90، 95 و 99 جمع آوری شده است.
برای اطلاعات بیشتر در مورد نحوه شناسایی و بهبود فریم های آهسته، به رندر آهسته مراجعه کنید.
شکل 3. نتایج FrameTimingMetric .
TraceSectionMetric
TraceSectionMetric تعداد دفعاتی که بخش ردیابی مطابق با sectionName ارائه شده رخ می دهد و مدت زمانی که طول می کشد را ثبت می کند. برای زمان، حداقل، میانه و حداکثر زمان ها را بر حسب میلی ثانیه خروجی می دهد. بخش trace یا با فراخوانی تابع trace(sectionName) یا کد بین Trace.beginSection(sectionName) و Trace.endSection() یا انواع غیر همگام آنها تعریف می شود. همیشه اولین نمونه از بخش ردیابی گرفته شده در طول اندازه گیری را انتخاب می کند. به طور پیش فرض تنها بخش های ردیابی را از بسته شما خروجی می دهد. برای گنجاندن فرآیندهای خارج از بسته خود، targetPackageOnly = false تنظیم کنید.
PowerMetric تغییر در توان یا انرژی را در طول مدت آزمایش شما برای دسته های توان ارائه شده ثبت می کند. هر دسته انتخاب شده به اجزای فرعی قابل اندازه گیری خود تقسیم می شود و دسته های انتخاب نشده به متریک "انتخاب نشده" اضافه می شوند.
این معیارها مصرف کل سیستم را اندازهگیری میکنند، نه مصرف را بر اساس هر برنامه، و به Pixel 6، Pixel 6 Pro و دستگاههای بعدی محدود میشوند:
power<category>Uw : میزان توان مصرفی در طول مدت آزمایش شما در این دسته.
energy<category>Uws : مقدار انرژی منتقل شده در واحد زمان برای مدت زمان آزمون شما در این دسته.
دسته بندی ها شامل موارد زیر است:
CPU
DISPLAY
GPU
GPS
MEMORY
MACHINE_LEARNING
NETWORK
UNCATEGORIZED
در برخی از دستهها، مانند CPU ، ممکن است جدا کردن کارهای انجام شده توسط سایر فرآیندها از کارهای انجام شده توسط برنامه شخصی شما دشوار باشد. برای به حداقل رساندن تداخل، برنامه ها و حساب های غیر ضروری را حذف یا محدود کنید.
شکل 5. نتایج PowerMetric . {% کلمه به کلمه %} {% آخر کلمه %}
برای شما توصیه می شود
توجه: وقتی جاوا اسکریپت خاموش است، متن پیوند نمایش داده می شود
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-08-27 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-27 بهوقت ساعت هماهنگ جهانی."],[],[],null,["Metrics are the main type of information extracted from your benchmarks. They\nare passed to the [`measureRepeated`](/reference/kotlin/androidx/benchmark/macro/junit4/MacrobenchmarkRule#measureRepeated(kotlin.String,kotlin.collections.List,androidx.benchmark.macro.CompilationMode,androidx.benchmark.macro.StartupMode,kotlin.Int,kotlin.Function1,kotlin.Function1))\nfunction as a `List`, which lets you specify\nmultiple measured metrics at once. At least one type of metric is required for\nthe benchmark to run.\n\nThe following code snippet captures frame timing and custom trace section\nmetrics: \n\nKotlin \n\n```kotlin\nbenchmarkRule.measureRepeated(\n packageName = TARGET_PACKAGE,\n metrics = listOf(\n FrameTimingMetric(),\n TraceSectionMetric(\"RV CreateView\"),\n TraceSectionMetric(\"RV OnBindView\"),\n ),\n iterations = 5,\n // ...\n)\n```\n\nJava \n\n```java\nbenchmarkRule.measureRepeated(\n TARGET_PACKAGE, // packageName\n Arrays.asList( // metrics\n new StartupTimingMetric(),\n new TraceSectionMetric(\"RV CreateView\"),\n new TraceSectionMetric(\"RV OnBindView\"),\n ),\n 5, // Iterations\n // ...\n);\n```\n\nIn this example, [`RV CreateView`](https://cs.android.com/search?q=TRACE_CREATE_VIEW_TAG&sq=&ss=androidx%2Fplatform%2Fframeworks%2Fsupport)\nand [`RV OnBindView`](https://cs.android.com/search?q=TRACE_BIND_VIEW_TAG)\nare the IDs of traceable blocks that are defined in\n[`RecyclerView`](/reference/androidx/recyclerview/widget/RecyclerView). The\n[source code for the `createViewHolder()`](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:recyclerview/recyclerview/src/main/java/androidx/recyclerview/widget/RecyclerView.java;l=7950-7964)\nmethod is an example of how you can define traceable blocks within your own\ncode.\n\n[`StartupTimingMetric`](#startup-timing), [`TraceSectionMetric`](#trace-section), [`FrameTimingMetric`](#frame-timing),\nand [`PowerMetric`](#power), are covered in detail later in this document.\nFor a full list of metrics, check out subclasses of [`Metric`](/reference/kotlin/androidx/benchmark/macro/Metric).\n\nBenchmark results are output to Android Studio, as shown in figure 1.\nIf multiple metrics are defined, all of them are combined in the output.\n**Figure 1.** Results of `TraceSectionMetric` and `FrameTimingMetric`.\n\nStartupTimingMetric\n\n[`StartupTimingMetric`](/reference/kotlin/androidx/benchmark/macro/StartupTimingMetric)\ncaptures app startup timing metrics with the following values:\n\n- `timeToInitialDisplayMs`: The amount of time from when the system receives a launch intent to when it renders the first frame of the destination [`Activity`](/reference/android/app/Activity).\n- `timeToFullDisplayMs`: The amount of time from when the system receives a launch intent to when the app reports fully drawn using the [`reportFullyDrawn()`](/reference/android/app/Activity#reportFullyDrawn()) method. The measurement stops at the completion of rendering the first frame after---or containing---the `reportFullyDrawn()` call. This measurement might not be available on Android 10 (API level 29) and earlier.\n\n`StartupTimingMetric` outputs the min, median, and max values from the startup\niterations. To assess startup improvement you should focus on median values,\nsince they provide the best estimate of the typical startup time. For more\ninformation about what contributes to app startup time, see [App startup\ntime](/topic/performance/vitals/launch-time).\n**Figure 2.** `StartupTimingMetric` results.\n\nFrameTimingMetric\n\n[`FrameTimingMetric`](/reference/kotlin/androidx/benchmark/macro/FrameTimingMetric)\ncaptures timing information from frames produced by a benchmark, such as a\nscrolling or animation, and outputs the following values:\n\n- `frameOverrunMs`: the amount of time a given frame misses its deadline by. Positive numbers indicate a dropped frame and visible jank or stutter. Negative numbers indicate how much faster a frame is than the deadline. Note: This is available only on Android 12 (API level 31) and higher.\n- `frameDurationCpuMs`: the amount of time the frame takes to be produced on the CPU on both the UI thread and the `RenderThread`.\n\nThese measurements are collected in a distribution of 50th, 90th, 95th, and 99th\npercentile.\n\nFor more information on how to identify and improve slow frames, see\n[Slow rendering](/topic/performance/vitals/render).\n**Figure 3.** `FrameTimingMetric` results.\n\nTraceSectionMetric **Experimental:** This class is experimental.\n\n[`TraceSectionMetric`](/reference/kotlin/androidx/benchmark/macro/TraceSectionMetric)\ncaptures the number of times a trace section matching the provided `sectionName`\noccurs and the amount of time it takes. For the time, it outputs the minimum,\nmedian, and maximum times in milliseconds. The trace section is defined either\nby the function call\n[`trace(sectionName)`](/reference/kotlin/androidx/tracing/package-summary#trace(kotlin.String,kotlin.Function0))\nor the code between\n[`Trace.beginSection(sectionName)`](/reference/kotlin/androidx/tracing/Trace#beginSection(java.lang.String))\nand\n[`Trace.endSection()`](/reference/kotlin/androidx/tracing/Trace#endSection()) or\ntheir async variants. It always selects the first instance of a trace section\ncaptured during a measurement. It only outputs trace sections from your package\nby default; to include processes outside your package, set\n`targetPackageOnly = false`.\n\nFor more information about tracing, see [Overview of system\ntracing](/topic/performance/tracing) and [Define custom\nevents](/topic/performance/tracing/custom-events).\n**Figure 4.** `TraceSectionMetric` results.\n\nPowerMetric **Experimental:** This class is experimental.\n\n[`PowerMetric`](/reference/kotlin/androidx/benchmark/macro/PowerMetric) captures\nthe change in power or energy over the duration of your test for the provided\n[power categories](/reference/kotlin/androidx/benchmark/macro/PowerCategory).\nEach selected category is broken down into its measurable subcomponents, and\nunselected categories are added to the \"unselected\" metric.\n\nThese metrics measure\nsystem-wide consumption, not the consumption on a per-app basis, and are limited\nto Pixel 6, Pixel 6 Pro, and later devices:\n\n- `power\u003ccategory\u003eUw`: the amount of power consumed over the duration of your test in this category.\n- `energy\u003ccategory\u003eUws`: the amount of energy transferred per unit of time for the duration of your test in this category.\n\nCategories include the following:\n\n- `CPU`\n- `DISPLAY`\n- `GPU`\n- `GPS`\n- `MEMORY`\n- `MACHINE_LEARNING`\n- `NETWORK`\n- `UNCATEGORIZED`\n\nWith some categories, like `CPU`, it might be difficult to separate work done by\nother processes from work done by your own app. To minimize the interference,\nremove or restrict unnecessary apps and accounts.\n**Figure 5.** `PowerMetric` results.\n\nRecommended for you\n\n- Note: link text is displayed when JavaScript is off\n- [Create Baseline Profiles {:#creating-profile-rules}](/topic/performance/baselineprofiles/create-baselineprofile)\n- [Writing a Macrobenchmark](/topic/performance/benchmarking/macrobenchmark-overview)\n- [App startup analysis and optimization {:#app-startup-analysis-optimization}](/topic/performance/appstartup/analysis-optimization)"]]