قياس أداء تطبيقك
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تُعد مقاييس الأداء طريقة لفحص أداء تطبيقك وتتبُّعه. ويمكنك إجراء مقاييس الأداء بانتظام لتحليل مشاكل الأداء وتصحيحها والمساعدة في ضمان عدم حدوث تراجع في التغييرات الأخيرة.
يوفّر نظام التشغيل Android مكتبتَين وأسلوبَين مختلفَين لقياس الأداء وتحليل أنواع مختلفة من الحالات واختبارها في تطبيقك، وهما Macrobenchmark وMicrobenchmark.
Macrobenchmark
تقيس مكتبة Macrobenchmark تفاعلات أكبر للمستخدمين النهائيين، مثل
بدء التشغيل والتفاعل مع واجهة المستخدم والرسوم المتحركة. توفّر المكتبة تحكّمًا مباشرًا في بيئة الأداء التي تختبرها. يتيح لك هذا الخيار التحكّم في عملية التجميع، كما يتيح لك بدء تطبيقك وإيقافه لقياس وقت بدء تشغيل التطبيق أو وقت التمرير مباشرةً.
تُدرِج مكتبة Macrobenchmark الأحداث وتراقب النتائج خارجيًا من تطبيق اختبار تم إنشاؤه باستخدام اختباراتك. لذلك، عند كتابة مقاييس الأداء، لا تستدعي رمز تطبيقك مباشرةً، بل تتنقّل داخل تطبيقك كمستخدم.
اختبار الأداء الدقيق
تتيح لك مكتبة Microbenchmark قياس أداء رمز التطبيق مباشرةً في حلقة.
تم تصميم هذا النوع من القياس لتقييم أداء وحدة المعالجة المركزية في أفضل الحالات، مثل عمليات الإحماء في عملية الترجمة الفورية (JIT) وعمليات الوصول إلى القرص المخزّنة مؤقتًا، والتي قد تظهر لك مع حلقة داخلية أو دالة نشطة معيّنة. يمكن للمكتبة قياس الرمز الذي يمكنك استدعاؤه مباشرةً بشكل مستقل فقط.
إذا كان تطبيقك يحتاج إلى معالجة بنية بيانات معقّدة، أو يتضمّن بعض الخوارزميات المحدّدة التي تتطلّب عمليات حسابية مكثّفة ويتم استدعاؤها عدة مرات أثناء تشغيل التطبيق، قد تكون هذه الحالات مناسبة لقياس الأداء. يمكنك أيضًا قياس أجزاء من واجهة المستخدم. على سبيل المثال، يمكنك قياس تكلفة ربط العنصر RecyclerView
، أو المدة التي يستغرقها تضخيم التنسيق، أو مدى تطلّب عملية التنسيق والقياس في الفئة View
من منظور الأداء.
ومع ذلك، لا يمكنك قياس مدى مساهمة حالات الاستخدام التي تم قياس أدائها في
تحسين تجربة المستخدم بشكل عام. في بعض السيناريوهات، لا يوضّح لك قياس الأداء ما إذا كنت بصدد تحسين مشكلة عنق الزجاجة، مثل التشويش أو وقت بدء تشغيل التطبيق. لهذا السبب، من المهم تحديد مواضع الاختناق هذه أولاً باستخدام Android Profiler.
بعد العثور على الرمز الذي تريد فحصه وتحسينه، يمكن تشغيل حلقة قياس الأداء بشكل متكرّر وبطريقة أسرع وأسهل لإنشاء نتائج أقل تشويشًا، ما يتيح لك التركيز على أحد مجالات التحسين.
لا تعرض مكتبة Microbenchmark سوى معلومات عن تطبيقك، وليس عن النظام بشكل عام. لذلك، تكون هذه الأداة في أفضل حالاتها عند تحليل أداء الحالات الخاصة بالتطبيق، وليس الحالات التي قد تكون مرتبطة بمشاكل النظام بشكل عام.
مقارنة مكتبة مقاييس الأداء
|
Macrobenchmark |
اختبار الأداء الدقيق |
إصدار واجهة برمجة التطبيقات |
23 والإصدارات الأحدث |
14 والإصدارات الأحدث |
الوظيفة
|
قياس نقاط الدخول أو التفاعلات العالية المستوى، مثل بدء نشاط أو تصفّح قائمة |
قياس الدوال الفردية
|
النطاق
|
اختبار خارج العملية للتطبيق الكامل |
اختبار أثناء المعالجة لعمل وحدة المعالجة المركزية
|
السرعة
|
متوسط سرعة التكرار يمكن أن تتجاوز مدة الفيديو دقيقة واحدة. |
سرعة تكرار عالية غالبًا ما تكون أقل من 10 ثوانٍ. |
تتبُّع
|
تتضمّن النتائج عمليات تتبُّع للتحليل. |
أخذ عيّنات من الطرق الاختيارية وتتبُّعها |
اقتراحات مخصصة لك
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-08-21 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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-21 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["Benchmarking is a way to inspect and monitor the performance of your app. You\ncan regularly run benchmarks to analyze and debug performance problems and help\nensure that you don't introduce regressions in recent changes.\n\nAndroid offers two benchmarking libraries and approaches for analyzing and\ntesting different kinds of situations in your app: Macrobenchmark and\nMicrobenchmark.\n\nMacrobenchmark\n\nThe [Macrobenchmark](/studio/profile/macrobenchmark) library measures larger end-user interactions, such as\nstartup, interacting with the UI, and animations. The library provides direct\ncontrol over the performance environment you're testing. It lets you control\ncompiling and lets you start and stop your app to directly measure actual app\nstartup or scrolling.\n\nThe Macrobenchmark library injects events and monitors results externally from a\ntest app that is built with your tests. Therefore, when writing the benchmarks,\nyou don't call your app code directly and instead navigate within your app as a\nuser.\n\nMicrobenchmark\n\nThe [Microbenchmark](/studio/profile/benchmark) library lets you benchmark app code directly in a loop.\nThis is designed for measuring CPU work that assesses best-case performance---such\nas warmed up Just in Time (JIT) and disk accesses cached---that you might see with\nan inner-loop or a specific hot function. The library can only measure the\ncode that you can call directly in isolation.\n\nIf your app needs to process a complex data structure, or have some specific\ncomputation-heavy algorithm that is called multiple times during the app run,\nthese might be good cases for benchmarking. You can also measure parts of your\nUI. For example, you can measure the cost of the `RecyclerView` item binding,\nhow long it takes to inflate a layout, or how demanding the layout-and-measure\npass of your `View` class is from a performance perspective.\n\nHowever, you aren't able to measure how the benchmarked cases contribute to the\noverall user experience. In some scenarios, benchmarking doesn't tell you if\nyou're improving a bottleneck like jank or app startup time. For this reason,\nit's crucial to identify those bottlenecks first with the [Android Profiler](/studio/profile).\nAfter you find the code you want to investigate and optimize, the benchmarked\nloop can run repeatedly in a quick and easier fashion to create less noisy\nresults, which lets you focus on one area of improvement.\n\nThe Microbenchmark library only reports information about your app, not about\nthe system overall. Therefore, it's best at analyzing performance of situations\nspecific to the app, not ones that might relate to overall system issues.\n\nBenchmark library comparison\n\n| | Macrobenchmark | Microbenchmark |\n|-------------|-----------------------------------------------------------------------------------------------|---------------------------------------------------|\n| API version | 23 and later | 14 and later |\n| Function | Measure high-level entry points or interactions, such as activity launch or scrolling a list. | Measure individual functions. |\n| Scope | Out-of-process test of full app. | In-process test of CPU work. |\n| Speed | Medium iteration speed. It can exceed a minute. | Fast iteration speed. Often less than 10 seconds. |\n| Tracing | Results come with profiling traces. | Optional method sampling and tracing. |\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- [JankStats Library](/topic/performance/jankstats)\n- [Overview of measuring app performance](/topic/performance/measuring-performance)"]]