הגדרת הסביבה לבדיקת ביצועים
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
כדי לזהות צווארי בקבוק פוטנציאליים ולשפר את הביצועים הכוללים של האפליקציה, אפשר לתעד את פעילות המכשיר במשך תקופה קצרה ולאסוף עקבות של תקופת ההפעלה של האפליקציה. בדף הזה מוסבר איך להגדיר את הסביבה לבדיקת ביצועים.
שימוש בספריית Macrobenchmark
ספריית Macrobenchmark מודדת אינטראקציות גדולות יותר של משתמשי קצה, כמו הפעלה, אינטראקציה עם ממשק המשתמש ואנימציות. הספרייה מאפשרת שליטה ישירה בסביבת הביצועים שאתם בודקים. היא מאפשרת לכם לשלוט בהידור, בהפעלה ובהפסקה של האפליקציה כדי למדוד באופן ישיר את זמן ההפעלה המדויק של האפליקציה. הוא גם פועל לצמצום הרעשים וההבדלים בין הרצות הבדיקה.
שימוש במכשירים בינוניים כדי לזהות בעיות פוטנציאליות בביצועים
בודקים את הביצועים בכל סוג מכשיר שחשוב לכם. במכשירים מתקדמים עם רכיבים מהירים, יכול להיות שבעיות בביצועים לא יורגשו, אבל הן יורגשו במכשירים ישנים יותר, איטיים יותר או עם זיכרון RAM נמוך.
במכשירים פחות מתקדמים, טעינת הנתונים או הפעלת הקוד עשויות להימשך זמן רב יותר, ולכן קל יותר לזהות צווארי בקבוק. אופטימיזציה של הביצועים למכשירים פשוטים בדרך כלל משפרת גם את האופטימיזציה למכשירים מתקדמים.
הפחתת רעש
- רשת: בדיקת האפליקציות או התהליכים עם מהירויות אינטרנט חזקות ויציבות ב-Wi-Fi. אם זמן ההפעלה של האפליקציה כולל בקשה לרשת, צריך לציין את זה כמקום שבו יכולה להתרחש שונות.
- שימוש בזיכרון RAM: אל תפעילו אפליקציות אחרות ברקע של המכשיר בזמן בדיקת ביצועי ההפעלה של האפליקציה.
- סוללה: חשוב לוודא שהמכשיר טעון כדי למנוע הגבלת ביצועים ספציפית לחומרה בגלל צריכת חשמל נמוכה.
בדיקה בגרסאות הפצה
כדאי להשתמש בגרסאות build של גרסאות כדי לבדוק את הביצועים. גרסאות build לניפוי באגים לא מתאימות לניפוי באגים של ביצועים, כי הן לא מספקות אופטימיזציה של קומפילציה ומשפיעות באופן משמעותי על הביצועים.
עם זאת, אפשר להשתמש בגרסת build של מהדורת הפצה לא מוצפנת כדי לזהות מחלקות ושמות של פעולות. מומלץ להפעיל את האפשרות minify
(R8) ולהשבית את האפשרות obfuscation, עם -dontobfuscate
בקובץ proguard.
קל יותר לזהות פריסות, נכסים ומשאבים אם הגרסה לא עברה טשטוש.
חשוב לוודא שכוללים את הדגל profileable במניפסט כדי שהאירועים המותאמים אישית יהיו גלויים בגרסאות שלא ניתן לבצע בהן ניפוי באגים. הסימון הבוליאני הזה זמין ב-Android 10 (רמת API 29) ואילך.
הוספת עקבות בהתאמה אישית לפעולות באפליקציה
כדי להקל על זיהוי הפעולות שהאפליקציה מבצעת בהשוואה לספריות אחרות, אפשר להוסיף עקבות מותאמים אישית באפליקציה. כך תוכלו לקבל יותר הקשר לגבי הפעולות שהאפליקציה מבצעת בכל רגע.
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-27 (שעון UTC).
[[["התוכן קל להבנה","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-07-27 (שעון UTC)."],[],[],null,["# Set up your environment for performance testing\n\nYou can identify potential bottlenecks and improve overall app performance by\nrecording device activity over a short period of time and [collecting traces of\nyour app's startup period](/topic/performance/tracing). This page shows how to\nset up your environment for performance testing.\n\nUse the Macrobenchmark library\n------------------------------\n\nThe [Macrobenchmark\nlibrary](/topic/performance/benchmarking/macrobenchmark-overview) measures\nlarger end-user interactions, such as startup, interacting with the UI, and\nanimations. The library provides direct control over the performance environment\nyou're testing. It lets you control compiling, starting, and stopping your app\nto directly measure precise app startup time. It also works to minimize the\nnoise and differences between test runs.\n\nUse mid-range devices to identify potential performance issues\n--------------------------------------------------------------\n\nTest performance on each device type you care about. High-end devices with fast\ncomponents can hide performance problems on earlier, slower, or low RAM devices.\nLower-end devices can take longer to load data or run code, making it easier to\nidentify bottlenecks. Optimizing performance for low-end devices usually also\nbenefits optimization for high-end devices.\n\nReduce noise\n------------\n\n- Network: test your apps or processes with strong and stable internet Wi-Fi speeds. If the app startup time includes a network request, note this as a place where variability might occur.\n- RAM usage: don't have any other apps running in the background of your device while testing app startup performance.\n- Battery: ensure your device is charged to avoid any hardware-specific low power performance throttling.\n\nTest on release builds\n----------------------\n\nUse release builds to test performance. Debug builds are [unsuitable for\nperformance\ndebugging](/studio/profile/measuring-performance#apk-considerations), as they\ndon't provide compilation optimization and significantly impact performance.\n\nHowever, it's okay to use an unobfuscated release build to identify classes and\noperation names. Specifically, we recommend enabling [minify\n(R8)](/studio/build/shrink-code) and disabling obfuscation, with\n[`-dontobfuscate`](/studio/build/shrink-code#obfuscate) in the proguard file.\nIt's easier to identify layouts, assets, and resources if the build is\nunobfuscated.\n\nMake sure you include the\n[profileable](/guide/topics/manifest/profileable-element) flag in the manifest\nso that your custom events are visible in non-debuggable builds. This flag is\navailable on Android 10 (API level 29) and later.\n\nAdd custom traces to your app operations\n----------------------------------------\n\nAdd [custom traces](/topic/performance/tracing/custom-events) within your app to\nmake it easier to identify what operations are performed by your app compared to\nother libraries. This helps give you more context about what the app is doing at\nall times."]]