• Measure Energy Impact


    测量能量的影响Measure Energy Impact

    即使是小的应用程序效率低下,也会影响整个系统的寿命、性能、响应速度和温度。作为应用程序开发人员,您有义务确保应用程序尽可能高效地运行。使用工具监视应用程序的影响,以便了解它如何利用资源和识别能源使用率高的时间。使用最佳实践来提高这些领域的效率,并在没有响应用户输入的情况下,让您的应用程序绝对空闲。通过遵循Mac应用程序能效指南中推荐的指南,您可以为系统的整体能源效率和用户的满意度做出巨大贡献。Even small inefficiencies in apps add up across the system, significantly affecting battery life, performance, responsiveness, and temperature. As an app developer, you have an obligation to make sure your app runs as efficiently as possible. Use Instruments to monitor the impact of your app in order to understand how it utilizes resources and identify times when energy usage is high. Use best practices to improve efficiency in these areas, and strive for your app to be absolutely idle when not responding to user input. By adhering to the recommended guidelines in Energy Efficiency Guide for Mac Apps, you can make big contributions to the overall energy efficiency of the system and the satisfaction of your users.

    开发过程中的调试能量Debug Energy During Development

    调试导航仪在Xcode包括能量冲击仪(参见图23-1),它提供了能源使用的高级概述为您测试您的应用程序。在应用程序的测试周期中定期检查这个指标,评估应用程序的能量影响,并找出潜在的问题领域。如有必要,深入研究仪器进行更深入的分析。The debug navigator in Xcode includes an Energy Impact gauge (see Figure 23-1), which provides a high-level overview of energy usage as you test your app. Consult this gauge regularly throughout your app’s testing cycle to assess your app’s energy impact and identify potential problem areas up-front. If necessary, dive into Instruments for more in-depth analysis.

    Figure 23-1在Xcode的能量冲击仪The Energy Impact gauge in Xcodeimage: ../Art/xcode_debug_navigator_energyimpact_gauge_2x.png

    衡量iOS应用程序的能量影响Measure the Energy Impact of an iOS App

    使用能量日志分析模板监视iOS设备上影响能量使用的各种因素,包括CPU活动、网络活动、屏幕亮度等。确定使用率最高的区域,看看是否能减少这些领域的影响。例如,您可能会发现有机会推迟任意选择或网络任务,直到更多的节能时间,例如当设备插上或在wi-fi上。Use the Energy Log profiling template to monitor a variety of factors that affect energy usage on an iOS device, including CPU activity, network activity, screen brightness, and more. Identify the areas where usage is highest, and see if you can reduce impact in those areas. For example, you might find opportunities to defer discretionary or network tasks until more energy efficient times, such as when the device is plugged in or on Wi-Fi.

    监控iOS应用程序对能源的影响To monitor the energy impact of an iOS app
    1. 启动工具,并创建一个新的跟踪文档,该文件以能量日志分析模板为设备和应用程序设置目标。Launch Instruments, and create a new trace document that targets your device and app with the Energy Log profiling template.

      image: ../Art/instruments_energydiagnosticsprofilingtemplateandtarget_2x.png
    2. 单击“记录”按钮,或按command-r,开始记录跟踪。Click the Record button (image: ../Art/inline_record_button_2x.png), or press Command-R, to begin recording a trace.

      TIP

      为了获得最佳效果,可以考虑执行无线跟踪。这样做可以让你更精确地在电池供电、加速度计等真实场景中对设备进行配置,等等。要了解如何启用无线设备剖析,请参阅无线对象的iOS设备。For best results, consider performing the trace wirelessly. Doing so allows you to more accurately profile the device in a real-world scenario—on battery power, with accelerometers, and so on. To learn how to enable wireless device profiling, see Target an iOS Device Wirelessly.

    3. 在设备上正常使用该应用程序,同时允许收集能量数据。Use the app normally on the device, while allowing energy data to be collected.

    4. 请单击“停止”按钮,或按command-r再次,当完成。Click the Stop button (image: ../Art/inline_stop_button_2x.png), or press Command-R again, when complete.

    5. 查看收集的数据,寻找异常或意想不到的活动的尖峰或区域。然后,检查这些区域中的代码,以确定是否可以进行改进。Go through the collected data and look for spikes or areas of otherwise unusual or unexpected activity. Then, review the code in these areas to determine whether improvements can be made.

      image: ../Art/instruments_energydiagnostics_data_2x.png

    TIP

    能量使用日志仪指示从0到20的水平,指示您的应用程序在给定时间内使用的能量。这些数字是主观的。如果你的应用程序的能源使用水平偶尔高,并不一定意味着你的应用程序有问题。你的应用程序可能只是需要更多的能量来完成它所执行的一些任务。例如,当执行复杂的网络操作时,它可以使用GPS。这是有效的能源使用。寻找意想不到的高能量使用的尖峰或区域,或者在更优的时间内执行。The Energy Usage Log instrument indicates a level from 0 to 20, indicating how much energy your app is using at any given time. These numbers are subjective. If your app’s energy usage level is occasionally high, it doesn’t necessarily mean that your app has a problem. Your app may simply require more energy for some of the tasks it performs. For example, it may use the GPS while performing complex network operations. This is valid energy use. Look for spikes or areas of high energy use that are unexpected or that could be performed at more optimal times.

    在iOS设备上直接使用日志能量Log Energy Usage Directly on an iOS Device

    没有让您的设备仪器(通过无线或有线),你可以登录能源相关的数据,在正常使用情况下采取现实的测量。随着能源启用日志记录,您的iOS设备的相关数据记录能悄悄地使用时。因为日志记录效率高,所以您可以全天登录。即使设备处于休眠状态,日志记录仍在继续。但是,如果设备的电池完全排水或iOS设备断电,日志数据就会丢失。Without tethering your device to Instruments (either wirelessly or wired), you can log energy-related data under normal use in order to take realistic measurements. With energy logging enabled, your iOS device records energy-related data unobtrusively while the device is used. Because logging is efficient, you can log all day. Logging continues even while the device is in sleep mode. However, if the device’s battery drains completely or the iOS device is powered off, the log data is lost.

    在iOS中记录能量数据To log energy data in iOS
    1. Go to Settings > Developer > Logging on your device.

      NOTE

      看开发商的设置,您必须提供设备的发展和它连接到你的Mac,Xcode或仪器运行。如果您的设备没有配置,请参阅配置你的Xcode项目分布和运行您的应用程序的设备上。即使设备已配置,开发商设置消失时,设备重新启动或关机。恢复设置,重新连接设备或工具Xcode。To see the Developer settings, you must provision the device for development and connect it to your Mac while Xcode or Instruments is running. If your device hasn’t been provisioned yet, see Configuring Your Xcode Project for Distribution and Launching Your App on Devices. Even after the device has been provisioned, the Developer setting disappears when the device is rebooted or powered off. To restore the setting, reconnect the device to Xcode or Instruments.

      image: ../Art/ios_settings_2x.pngimage: ../Art/ios_developer_2x.png
    2. 启用能量记录。Enable energy logging.

      image: ../Art/ios_logging_2x.png
    3. Tap Start Recording.

      image: ../Art/ios_logging_startrecording_2x.png
    4. Use your device normally.

    5. When you’re done, return to Settings > Developer > Logging and tap Stop Recording.

      image: ../Art/ios_logging_stoprecording_2x.png

    从iOS设备导入记录的能量数据To import logged energy data from an iOS device
    1. 启动工具,并创建一个新的跟踪文档,该文件以能量日志分析模板为设备和应用程序设置目标。Launch Instruments, and create a new trace document that targets your device and app with the Energy Log profiling template.

      image: ../Art/instruments_energydiagnostics_profilingtemplate_2x.png
    2. Choose File > Import Logged Data from Device.

      image: ../Art/instruments_file_menu_importloggeddatafromdevice_menuitem_2x.png

      记录的数据被导入并显示在时间轴和明细窗格中。The logged data is imported and displayed in the timeline and detail panes.

      image: ../Art/instruments_trace_document_energyusageimported_2x.png

    测量OS X应用程序的能量影响Measure the Energy Impact of an OS X App

    与iOS一样,多种因素影响应用程序在OS X中的能量影响。虽然能量日志分析模板是为与iOS一起使用而设计的,但您可以使用其他分析模板来检查和评估应用程序在OS X中的能量影响。Like iOS, a variety of factors affect the energy impact of an app in OS X. Although the Energy Log profiling template is designed for use with iOS, you can use other profiling templates to examine and assess your app’s energy impact in OS X.

    image: ../Art/templateActivityMonitor_48_2x.png

    活动监视器。使用此剖析模板监视整个CPU、磁盘I/O和网络使用情况。Activity Monitor. Use this profiling template to monitor overall CPU, disk I/O, and network usage.

    image: ../Art/templateFileActivity_48_2x.png

    文件活动。使用这个剖析模板跟踪磁盘I/O活动,包括文件打开、关闭、读取和写入。File Activity. Use this profiling template to track disk I/O activity, including file opens, closes, reads, and writes.

    image: ../Art/templateTimeProfiler_48_2x.png

    时间剖面。使用这个分析模板来监控应用程序的活动随着时间的推移。时间分析器监视应用程序中的运行线程并定期取样。一个完整的回溯是每个样本的采集,让你深入到一个样本准确地找到代码中大量的时间都花在。Time Profiler. Use this profiling template to monitor your app’s activity over time. Time Profiler watches the running threads in your app and takes samples at regular intervals. A complete backtrace is collected for each sample, allowing you to drill down into a sample to find exactly where in your code large amounts of time are being spent.

    image: ../Art/templateBlank_48_2x.png

    您的自定义模板在这里。上面的模板通过分析应用程序的多个方面提供高价值,这可能会影响能量。但是,如果您希望集中在一个更具体的区域,可以在空白分析模板中添加单独的工具。如果您认为您可能需要再次执行相同类型的分析,请确定并将您的配置保存为模板。请参阅将跟踪文档保存为分析模板。Your Custom Template Here. The templates above provide high value by analyzing multiple aspects of your app, which may affect energy. If you prefer to focus in on a more specific area, however, you can add individual instruments to the Blank profiling template. If you think you might need to perform the same type of analysis again, be sure and save your configuration as a template. See Save a Trace Document as a Profiling Template.

    同样,监视尖峰或高或意想不到的活动区域,看看是否可以改进这些区域以减少CPU和其他资源利用率。Again, monitor for spikes or areas of high or unexpected activity, and see whether you can improve those areas to reduce CPU and other resource utilization.

  • 相关阅读:
    c++ qt安装配置教程
    PKi系统
    IKE协议
    Kerberos
    RADIUS和Diameter
    RageFrame学习笔记:创建路由+导入layui
    TP6框架--EasyAdmin学习笔记:数据表添加新参数,如何强制清除缓存
    JS原生2048小游戏源码分享
    风场可视化学习笔记:openlayers
    vue3.0 demo代码记录
  • 原文地址:https://www.cnblogs.com/zyingn/p/Measure_Energy_Impact.html
Copyright © 2020-2023  润新知