استخدام البطارية للملف الشخصي من خلال إحصاءات البطارية وسجلّ بيانات البطارية السابقة
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يعرض هذا المستند خطوات الإعداد الأساسية وسير العمل في أداة "البطارية"
والنص البرمجي للمدرج في "البطارية" التعرّف على طريقة استخدام "Bry Historian" من أجل
فحص أنماط استهلاك البطارية، راجع تحليل استخدام الطاقة باستخدام البطارية
المؤرخ.
ميزة "البطارية" هي أداة مضمّنة في إطار عمل Android تجمع بيانات البطارية
البيانات على جهازك. يمكنك استخدام adb لتفريغ
وجمعت بيانات البطارية إلى جهاز التطوير وإنشاء تقرير يمكنك
تحليل البيانات باستخدام ميزة "مخطّط البطارية". يحوِّل تطبيق البطارية Historian التقرير من
إحصائيات البطارية في تصور HTML يمكنك عرضه في متصفحك.
تُعد إحصائيات البطارية ومسجل البطارية مفيدين لما يلي:
توضيح مكان وكيفية رسم العمليات من البطارية
تحديد المهام في تطبيقك التي يمكن تأجيلها أو إزالتها لتحسينها
عمر البطارية
تثبيت تطبيق "البطارية"
يمكنك استخدام Docker لتثبيت "مؤرخ البطارية". للتركيب البديل
بما في ذلك الإنشاء من المصدر، راجع
الدليل (README) على
لصفحة GitHub الخاصة بالمشروع. للتثبيت باستخدام Docker، نفِّذ ما يلي:
ثبِّت Docker باتّباع التعليمات الواردة في
موقع Docker الإلكتروني. أي تقييم
نوع الاشتراك
بما في ذلك اشتراك تطبيق شخصي مجاني.
للتأكد من تثبيت Docker بشكل صحيح، افتح سطر الأوامر
أدخل الأمر التالي:
docker run hello-world
إذا تم تثبيت Docker بشكل صحيح، سيعرض مخرجًا على النحو التالي:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete
Digest:
sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal
شغّل تطبيق Docker Desktop - وهي واجهة واجهة مستخدم تصويرية أمامية لـ Docker - قبل
تقوم بتشغيل صورة "Berer Historian". يؤدي تشغيل هذا إلى تهيئة Docker
لا يتم تشغيل "مسجلّ البطارية" إلا بعد تنفيذ هذا الإجراء مرة واحدة على الأقل.
شغِّل ميزة البطارية Historian من سطر الأوامر عند تشغيلها لأول مرة
الوقت. لا يسمح لك تطبيق Docker Desktop بتحديد المنفذ لتشغيل الويب
الخادم قيد التشغيل. ولا يمكنك تنفيذ هذا الإجراء إلا من سطر الأوامر. ومع ذلك، بعد
بتشغيل الحاوية بنجاح من سطر الأوامر، فسيتم إنشاء إدخال في
Docker Desktop، وبعد ذلك يمكنك تشغيله باستخدام منفذ المستمع نفسه
من Docker Desktop.
شغِّل صورة "البطارية Historian" باستخدام الأمر التالي:
docker run -p port_number:9999 gcr.io/android-battery-historian/stable:3.1 --port 9999
يستخدم تطبيق "البطارية Historian" المنفذ الذي تختاره كما هو محدَّد باستخدام
port_number
انتقِل إلى "مسجلّ البطارية" في المتصفّح للتأكّد من أنّه قيد التشغيل. تشير رسالة الأشكال البيانية
يختلف العنوان باختلاف نظام التشغيل الذي تستخدمه:
لنظامي التشغيل Linux وMac
تتوفّر ميزة "مسجلّ البطارية" في "
" في
http://localhost:port_number.
لنظام التشغيل Windows
بعد بدء تشغيل Docker، يخبرك بعنوان IP للجهاز.
التي يستخدمها. على سبيل المثال، إذا كان عنوان IP هو 123.456.78.90، يعني ذلك أنّ البطارية
المؤرخ متاح في
http://123.456.78.90:port_number
ثم تعرض الصفحة الرئيسية "Bard Historian" (البطارية)، حيث يمكنك تحميل
عرض إحصاءات البطارية.
الشكل 1. صفحة البدء الخاصة بالبطارية
المؤرخ.
جمع البيانات باستخدام ميزة "البطارية"
لجمع البيانات من جهازك باستخدام إحصاءات البطارية وفتحها في قسم "البطارية"
المؤرخ، قم بما يلي:
وصِّل جهازك الجوّال بجهاز الكمبيوتر.
من نافذة المحطة الطرفية، يمكنك إيقاف خادم adb قيد التشغيل من خلال تشغيل
الأمر التالي:
adb kill-server
إعادة تشغيل "adb" والتحقّق من الأجهزة المتصلة من خلال تنفيذ ما يلي
الأمر.
adb devices
ويتم عرض بيانات جهازك على غرار المثال التالي الذي يظهر.
الشكل 2. ناتج adb devices،
يتم الآن عرض جهاز واحد متصل
إذا لم تظهر أي أجهزة، تأكَّد من أنّ هاتفك متّصل ومنفذ USB.
تصحيح الأخطاء، ثم
إيقاف adb وإعادة تشغيله
يمكنك إعادة ضبط عملية جمع بيانات البطارية عن طريق تشغيل الأمر التالي:
adb shell dumpsys batterystats --reset
يجمع الجهاز دائمًا إحصاءات البطارية ومعلومات تصحيح الأخطاء الأخرى.
في الخلفية. تؤدي إعادة الضبط إلى محو بيانات جمع البطارية السابقة. إذا كنت
وعدم إعادة التعيين، فقد يكون الناتج كبيرًا جدًا.
اقطع اتصال جهازك بالكمبيوتر بحيث ترسم فقط
التيار من بطارية الجهاز.
استخدِم تطبيقك ونفِّذ الإجراءات التي تريد جمع بيانات لها. بالنسبة
مثلاً، قطع الاتصال بشبكة Wi-Fi وإرسال البيانات إلى السحابة.
أعِد ربط هاتفك.
تأكد من التعرف على هاتفك وشغِّل الأمر التالي:
adb devices
عليك تفريغ جميع بيانات البطارية من خلال تنفيذ الأمر التالي. يمكن أن يستغرق ذلك
حينها.
يتم إنشاء الملف batterystats.txt في الدليل الذي تحدده باستخدام
وسيطة المسار الاختياري. إذا لم تحدد مسارًا، فسيتم حفظ
الذي تم إنشاؤه في الدليل الرئيسي لديك.
أنشِئ تقريرًا من البيانات الأولية.
بالنسبة إلى الأجهزة التي تعمل بنظام التشغيل Android 7.0 والإصدارات الأحدث:
adb bugreport [path/]bugreport.zip
بالنسبة إلى الأجهزة التي تعمل بنظام التشغيل Android 6.0 والإصدارات الأقدم:
adb bugreport [path/]bugreport.txt
قد يستغرق إكمال تقرير الأخطاء عدّة دقائق. لا تلغِ ربط
الجهاز أو إلغاء العملية حتى تكتمل.
كما هو الحال مع batterystats.txt، يتم إنشاء هذه الملفات في الدليل الذي
التحديد باستخدام وسيطة path الاختيارية. إذا كنت
مسارًا، فسيتم إنشاؤها في الدليل الرئيسي.
إذا لم تكن الخدمة قيد التشغيل، يمكنك تشغيل "Bard Historian" باستخدام ما يلي:
:
docker run -p port_number:9999 gcr.io/android-battery-historian/stable:3.1 --port 9999
لعرض بياناتك في "Bard Historian"، افتح "مؤسّس البطارية" في
المتصفح. بالنسبة لنظامي التشغيل Mac وLinux، يعمل Bard Historian في
http://localhost:port_number على نظام التشغيل Windows، البطارية
يركض المؤرخ في
http://your_IP_address:port_number
انقر على تصفّح ثم اختَر ملف تقرير الأخطاء الذي أنشأته.
انقر على إرسال. يفتح صاحب هذه الخدمة رسمًا بيانيًا تم إنشاؤه من
بيانات إحصائيات البطارية.
عرض البيانات باستخدام الرسوم البيانية لسجلّ البطارية
يعرض الرسم البياني لـ "سجلّ البطارية" الرسوم البيانية الأحداث ذات الصلة بالطاقة بمرور الوقت.
يعرض كل صف مقطع شريط ملون عندما يكون أحد مكونات النظام نشطًا، وبالتالي
لرسم التيار من البطارية. لا يعرض الرسم البياني مقدار طاقة البطارية
يستخدمه المكوِّن فقط ما إذا كان التطبيق نشطًا. يتم تنظيم المخططات بواسطة
فئة، بحيث يظهر شريط لكل فئة بمرور الوقت، كما هو موضح في
x في الرسم البياني.
الشكل 3. مثال على مؤرّخ البطارية
المخطط.
أضِف مقاييس أخرى من القائمة المنسدلة.
ضع مؤشر الماوس فوق اسم المقياس للاطلاع على مزيد من المعلومات حول
كل مقياس، بما في ذلك مفتاح الألوان المستخدمة في المخطط.
مرِّر مؤشّر الماوس فوق شريط للاطّلاع على مزيد من المعلومات المفصّلة
المقياس وإحصاءات البطارية في نقطة محددة على المخطط الزمني.
مخرجات إحصاءات البطارية الإضافية
يمكنك الاطّلاع على معلومات إضافية من ملف batterystats.txt في
قسم الإحصائيات بعد مخطط "البطارية التاريخي".
الشكل 4. قسم الإحصاءات في "البطارية"
المؤرخ.
تشمل علامة التبويب 1إحصاءات النظام مستوى النظام بأكمله.
مثل مستويات إشارة الخلية وسطوع الشاشة. هذه المعلومات
صورة شاملة لما يحدث للجهاز. هذا هو
للغاية للتأكد من عدم وجود أحداث خارجية تؤثر في الاختبار.
تتضمن علامة التبويب 2إحصاءات التطبيق معلومات عن
تطبيقات محددة. ترتيب قائمة التطبيقات باستخدام الخيار 3ترتيب التطبيقات حسب القائمة المنسدلة في لوحة اختيار التطبيقات إِنْتَ
يمكنك تحديد تطبيق معين لعرض إحصاءات استخدام
4 قائمة منسدلة للتطبيقات.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Profile battery usage with Batterystats and Battery Historian\n\n| **Warning:** Battery Historian is no longer actively maintained; if possible, consider using [system tracing](/topic/performance/tracing), the [Macrobenchmark power metric](/topic/performance/benchmarking/macrobenchmark-metrics#power), or the [Power Profiler](/studio/profile/power-profiler) to get insights into battery performance.\n\nThis document shows the basic setup steps and workflow for the Batterystats tool\nand the Battery Historian script. To learn how to use Battery Historian to\ninspect battery consumption patterns, see [Analyze power use with Battery\nHistorian](/topic/performance/power/battery-historian).\n\nBatterystats is a tool included in the Android framework that collects battery\ndata on your device. You can use [`adb`](/studio/command-line/adb) to dump the\ncollected battery data to your development machine and create a report you can\nanalyze using Battery Historian. Battery Historian converts the report from\nBatterystats into an HTML visualization that you can view in your browser.\n\nBatterystats and Battery Historian are useful for the following:\n\n- Showing you where and how processes are drawing current from the battery.\n- Identifying tasks in your app that can be deferred or removed to improve battery life.\n\n| **Note:** To use Batterystats and Battery Historian, you need a mobile device with [USB debugging](/studio/debug/dev-options) enabled.\n\nInstall Battery Historian\n-------------------------\n\nYou can use Docker to install Battery Historian. For alternative installation\nmethods, including building from source, see the\n[README](https://github.com/google/battery-historian) on the\nproject's GitHub page. To install using Docker, do the following:\n\n1. Install Docker by following the instructions on the\n [Docker website](https://docs.docker.com/desktop). Any\n [subscription](https://docker.com/pricing) type works,\n including a free Personal subscription.\n\n2. To confirm Docker is correctly installed, open the command line and\n enter the following command:\n\n docker run hello-world\n\n If Docker is correctly installed, it displays an output like this: \n\n Unable to find image 'hello-world:latest' locally\n latest: Pulling from library/hello-world\n 78445dd45222: Pull complete\n Digest:\n sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7\n Status: Downloaded newer image for hello-world:latest\n\n Hello from Docker!\n This message shows that your installation appears to be working correctly.\n\n To generate this message, Docker took the following steps:\n 1. The Docker client contacted the Docker daemon.\n 2. The Docker daemon pulled the \"hello-world\" image from the Docker Hub.\n 3. The Docker daemon created a new container from that image which runs the\n executable that produces the output you are currently reading.\n 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal\n\n3. Launch the Docker Desktop app---which is a GUI frontend for Docker---before\n you run the Battery Historian image. Running this initializes the Docker\n tools. Battery Historian doesn't run until you do this at least once.\n\n4. Run Battery Historian from the command line when running it for the first\n time. The Docker Desktop app doesn't let you specify the port to run the web\n server on. You can only do this from the command line. However, after you\n successfully run the container from the command line, an entry is created in\n Docker Desktop, and then you can launch it using the same listener port\n from Docker Desktop.\n\n5. Run the Battery Historian image using the following command:\n\n ```\n docker run -p port_number:9999 gcr.io/android-battery-historian/stable:3.1 --port 9999\n ```\n\n Battery Historian uses the port of your choice, as specified using\n \u003cvar translate=\"no\"\u003eport_number\u003c/var\u003e.\n | **Note:** If you're using a Windows machine, you might need to enable virtualization in your BIOS. Check the documentation for your motherboard for more information about how to enable virtualization. If you can run the [Android Emulator](/studio/run/emulator), then virtualization is already enabled.\n6. Navigate to Battery Historian in your browser to confirm it's running. The\n address varies depending on your operating system:\n\n For Linux and Mac\n : Battery Historian is available at\n `http://localhost:`\u003cvar translate=\"no\"\u003eport_number\u003c/var\u003e.\n\n For Windows\n : After you start Docker, it tells you the IP address of the machine it\n is using. For example, if the IP address is 123.456.78.90, Battery\n Historian is available at\n `http://123.456.78.90:`\u003cvar translate=\"no\"\u003eport_number\u003c/var\u003e.\n\n \u003cbr /\u003e\n\n It then displays the Battery Historian start page, where you can upload and\n view battery statistics.\n **Figure 1.** The start page for Battery Historian.\n\nGather data with Batterystats\n-----------------------------\n\nTo collect data from your device using Batterystats and open it in Battery\nHistorian, do the following:\n\n1. Connect your mobile device to your computer.\n\n2. From a Terminal window, shut down your running `adb` server by running the\n following command:\n\n adb kill-server\n\n3. Restart `adb` and check for connected devices by running the following\n command.\n\n adb devices\n\n It lists your device, similar to the following example output.\n **Figure 2.** The output of `adb devices`, showing one connected device\n\n If it doesn't list any devices, make sure your phone is connected and [USB\n debugging](/studio/debug/dev-options#Enable-debugging) is enabled, and then\n stop and restart `adb`.\n4. Reset battery data gathering by running the following command:\n\n adb shell dumpsys batterystats --reset\n\n The device is always collecting Batterystats and other debugging information\n in the background. Resetting erases previous battery collection data. If you\n don't reset, the output can be very large.\n5. Disconnect your device from your computer so that you are only drawing\n current from the device's battery.\n\n6. Use your app and perform actions for which you want to collect data for. For\n example, disconnect from Wi-Fi and send data to the cloud.\n\n7. Reconnect your phone.\n\n8. Make sure your phone is recognized and run the following command:\n\n adb devices\n\n9. Dump all battery data by running the following command. This can take a\n while.\n\n ```\n adb shell dumpsys batterystats \u003e [path/]batterystats.txt\n ```\n\n The `batterystats.txt` file is created in the directory you specify using\n the optional path argument. If you don't specify a path, the file is\n created in your home directory.\n10. Create a report from raw data.\n\n For devices running Android 7.0 and higher:\n :\n\n ```\n adb bugreport [path/]bugreport.zip\n ```\n\n For devices running Android 6.0 and lower:\n :\n\n ```\n adb bugreport [path/]bugreport.txt\n ```\n\n \u003cbr /\u003e\n\n Bugreport can take several minutes to complete. Don't disconnect your\n device or cancel the process until it's complete.\n\n As with `batterystats.txt`, these files are created in the directory you\n specify using the optional \u003cvar translate=\"no\"\u003epath\u003c/var\u003e argument. If you\n don't specify a path, they are created in your home directory.\n\n If it's not already running, run Battery Historian using the following\n command: \n\n ```\n docker run -p port_number:9999 gcr.io/android-battery-historian/stable:3.1 --port 9999\n ```\n11. To view your data in Battery Historian, open the Battery Historian in your\n browser. For Mac and Linux, Battery Historian runs at\n `http://localhost:`\u003cvar translate=\"no\"\u003eport_number\u003c/var\u003e. For Windows, Battery\n Historian runs at\n `http://`\u003cvar translate=\"no\"\u003eyour_IP_address\u003c/var\u003e`:`\u003cvar translate=\"no\"\u003eport_number\u003c/var\u003e.\n\n12. Click **Browse** and then choose the bugreport file you created.\n\n13. Click **Submit**. Battery Historian opens a chart created from your\n Batterystats data.\n\nView data with Battery Historian charts\n---------------------------------------\n\nThe Battery Historian chart graphs power-relevant events over time.\n\nEach row shows a colored bar segment when a system component is active and thus\ndrawing current from the battery. The chart doesn't show how much battery is\nused by the component---only whether the app is active. Charts are organized by\ncategory, showing a bar for each category over time, as displayed on the\n*x*-axis of the chart.\n**Figure 3.** Example of a Battery Historian chart.\n\n1. Add additional metrics from the drop-down list.\n2. Hold the pointer over the metric name to see more information about each metric, including a key for the colors used in the chart.\n3. Hold the pointer over a bar to see more detailed information about that metric and the battery stats at a specific point on the timeline.\n\nAdditional Batterystats output\n------------------------------\n\nYou can view additional information from the `batterystats.txt` file in the\nstats section after the Battery Historian chart.\n**Figure 4.** The stats section of Battery Historian.\n\nThe 1 **System Stats** tab includes system-wide\nstatistics, such as cell signal levels and screen brightness. This information\nprovides an overall picture of what's happening with the device. This is\nespecially useful to make sure no external events are affecting your test.\n\nThe 2 **App Stats** tab includes information about\nspecific apps. Sort the list of apps using the 3\n**Sort apps by** drop-down list in the **App Selection** pane. You\ncan select a specific app to view stats for using the\n4 apps drop-down list."]]