{"id":885,"date":"2021-04-22T08:00:49","date_gmt":"2021-04-22T07:00:49","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/sustainable-software\/?p=885"},"modified":"2021-04-20T15:59:52","modified_gmt":"2021-04-20T14:59:52","slug":"how-to-measure-the-energy-consumption-of-your-apps","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/sustainable-software\/how-to-measure-the-energy-consumption-of-your-apps\/","title":{"rendered":"How to measure the energy consumption of your apps"},"content":{"rendered":"<p><span data-contrast=\"none\">The second principle of\u00a0<\/span><a href=\"https:\/\/principles.green\/\"><span data-contrast=\"none\">Sustainable Software Engineering<\/span><\/a><span data-contrast=\"none\">\u00a0 is to build energy efficient applications. The very first step in that direction is to measure the energy your application consumes, also known as its energy cost. Once you measure or estimate the energy cost of your application, you can start to reason over how your application can become more energy efficient. Measuring your energy cost will also allow you to observe whether your changes are improving your energy cost over time. This approach\u00a0leads\u00a0to the question, what is the best way to measure the energy consumption of your application?<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">This\u00a0third\u00a0post\u00a0in my series\u00a0is\u00a0about native applications running on mobile devices such as phones and tablets.\u00a0I am aspiring to be operating system agnostic.\u00a0For more details on measuring the energy cost of server-side applications, see my previous post on the\u00a0<\/span><a href=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/how-to-measure-the-power-consumption-of-your-backend-service\/\"><span data-contrast=\"none\">power consumption of backend services<\/span><\/a><span data-contrast=\"none\">.<\/span><span data-contrast=\"auto\">\u00a0\u00a0The second post in this series has a set of tips and\u00a0trick\u00a0for measuring the\u00a0<\/span><a href=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/how-to-measure-the-power-consumption-of-your-frontend-application\/?WT.mc_id=green-8991-cxa\"><span data-contrast=\"none\">power consumption of frontend applications<\/span><\/a><span data-contrast=\"auto\">.\u00a0<\/span><span data-contrast=\"none\">My colleague Scott Chamberlin is writing a series of how to measure the energy and carbon impact of Windows client applications. The first post in Scott\u2019s series is\u00a0available\u00a0<\/span><a href=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/measuring-your-application-power-and-carbon-impact-part-1\/\"><span data-contrast=\"none\">here<\/span><\/a><span data-contrast=\"none\">.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h2><span data-contrast=\"none\">What is driving energy consumption?<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h2>\n<p><span data-contrast=\"none\">Keeping down energy consumption of mobile apps is\u00a0good for the environment in that less carbon is emitted. It is also a way to use less of the battery on the device, which tends to make your customers happy.\u00a0In order to measure this cost, it is good to first\u00a0understand\u00a0the major contributions to\u00a0the energy\u00a0consumption.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\"><a href=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2021\/04\/Energy-Consumption-Of-Apps.jpg\"><img decoding=\"async\" class=\"alignnone size-full wp-image-889\" src=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2021\/04\/Energy-Consumption-Of-Apps.jpg\" alt=\"A green image of a phone screen, a phone camera, a CPU and a network symbol\" width=\"800\" height=\"490\" srcset=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2021\/04\/Energy-Consumption-Of-Apps.jpg 800w, https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2021\/04\/Energy-Consumption-Of-Apps-300x184.jpg 300w, https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2021\/04\/Energy-Consumption-Of-Apps-768x470.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/span><\/p>\n<p><span data-contrast=\"none\">The paper,\u00a0&#8220;<\/span><a href=\"https:\/\/ts.data61.csiro.au\/publications\/papers\/Carroll:phd.pdf\"><span data-contrast=\"none\">Understanding and Reducing Smartphone Energy Consumption<\/span><\/a><span data-contrast=\"none\">&#8221; by A. Carroll, University of New South Wales, 2017, provides a deep dive into the energy consumption of mobile phones and a plethora of different applications. I recommend reading it in full, but in short, I will summarize a few key elements here. Energy consumption differs based on the characteristics of your application, but the screen will always be a major driver of energy cost. The CPU is another component that is frequently one of the big spenders along with network and camera when those are in use.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">The network will be a big driver of the overall energy consumption of your application. The paper,\u00a0<\/span><span data-contrast=\"none\"><a href=\"https:\/\/dl.acm.org\/doi\/abs\/10.1145\/2602044.2602054\">When mice consume like elephants from Proceedings of the 5th international conference on Future energy systems (acm.org)<\/a><\/span><span data-contrast=\"none\">, by E. J. Vergara, S. Andersson, S. Nadjm-Tehrani, 2014, discusses the energy consumption of instant message (IM) applications. In this paper, they show the energy cost based on IM data patterns and the cost of typing notifications.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h1 aria-level=\"1\"><span data-contrast=\"none\">Measuring\u00a0energy\u00a0consumption<\/span><\/h2>\n<p><span data-contrast=\"none\">The best, and least intrusive,\u00a0way to measure\u00a0energy\u00a0consumption is always going to be by\u00a0using a watt-hour meter,\u00a0directly plugged into the wall. This way\u00a0you can measure the total\u00a0power\u00a0consumption of your device, which helps you calculate energy cost.\u00a0In my previous post for frontend applications, I\u00a0outlined\u00a0<\/span><a href=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/how-to-measure-the-power-consumption-of-your-frontend-application\/?WT.mc_id=green-8991-cxa#measure-power-consumption-directly-from-the-wall-socket\"><span data-contrast=\"none\">some considerations which are useful when considering the watt-hour meter approach<\/span><\/a><span data-contrast=\"none\">\u00a0and they are just as relevant for mobile applications.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/09\/Sara-Measuring-Illustration-1-small.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-230\" src=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/09\/Sara-Measuring-Illustration-1-small.png\" alt=\"A drawing of a watt meter being plugged into a wall, there are also some leaves in the drawinf\" width=\"1117\" height=\"720\" srcset=\"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/09\/Sara-Measuring-Illustration-1-small.png 1117w, https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/09\/Sara-Measuring-Illustration-1-small-300x193.png 300w, https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/09\/Sara-Measuring-Illustration-1-small-1024x660.png 1024w, https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-content\/uploads\/sites\/60\/2020\/09\/Sara-Measuring-Illustration-1-small-768x495.png 768w\" sizes=\"(max-width: 1117px) 100vw, 1117px\" \/><\/a><\/p>\n<p><span data-contrast=\"none\">There are also other options available, some of these are already on the developing stage, which can be very useful to make sure you are making energy saving decisions from the start.\u00a0\u00a0For Android apps, Android Studio has a built-in <\/span><a href=\"https:\/\/developer.android.com\/studio\/profile\/energy-profiler\"><span data-contrast=\"none\">energy profiler<\/span><\/a><span data-contrast=\"none\">. This profiler estimates the energy consumption of the CPU, the network radio, and GPS sensors as well as showing the occurrence of different system events that may affect energy consumption. When developing iOS apps in XCode there is a similar profiler that can be used when <\/span><a href=\"https:\/\/developer.apple.com\/library\/archive\/documentation\/DeveloperTools\/Conceptual\/debugging_with_xcode\/chapters\/about_debugging_w_xcode.html\"><span data-contrast=\"none\">debugging<\/span><\/a><span data-contrast=\"none\">. The benefits of both solutions are that they allow analysis on the code stage, without deploying your app anywhere.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">For measuring the energy cost of wireless transmission in mobile devices,\u00a0which can be quite significant depending on your app,\u00a0the\u00a0tool\u00a0<\/span><a href=\"https:\/\/github.com\/rtslab\/EnergyBox\"><span data-contrast=\"none\">EnergyBox<\/span><\/a><span data-contrast=\"none\">\u00a0can be used. It was first presented in the paper \u201c<\/span><a href=\"https:\/\/www.sciencedirect.com\/science\/article\/pii\/S2210537914000195\"><span data-contrast=\"none\">EnergyBox: Disclosing the wireless transmission energy cost for mobile devices<\/span><\/a><span data-contrast=\"none\">\u201d\u00a0by\u00a0Vergara et al. Sustainable Computing: Informatics and Systems 4.2,\u00a02014.\u00a0This tool needs real traffic traces, which makes it a bit harder to use in the development phase. It also focuses mostly on WIFI and 3G, which depending on\u00a0the\u00a0market you are targeting may be an issue.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h1 aria-level=\"1\"><span data-contrast=\"none\">Take\u00a0action<\/span><\/h2>\n<p><span data-contrast=\"none\">To measure the energy efficiency of an already deployed webpage,\u00a0<\/span><a href=\"http:\/\/mobile-efficiency-index.com\/en\/\"><span data-contrast=\"none\">Green Spector<\/span><\/a><span data-contrast=\"none\">\u00a0can be used. It will test your webpage of an actual mobile device and give you a score between 0 and 100.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The second principle of Sustainable Software Engineering is to build energy efficient applications. The very first step in that direction is to measure the energy cost of your application. This post will answer the question &#8220;what is the best way to measure the energy consumption of your apps?&#8221;.<\/p>\n","protected":false},"author":37028,"featured_media":889,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[91,71,22],"tags":[139,127,70,24],"class_list":["post-885","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-applications","category-measurement","category-sustainable-software-engineering","tag-apps","tag-energy","tag-power-measurement","tag-sse"],"acf":[],"blog_post_summary":"<p>The second principle of Sustainable Software Engineering is to build energy efficient applications. The very first step in that direction is to measure the energy cost of your application. This post will answer the question &#8220;what is the best way to measure the energy consumption of your apps?&#8221;.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-json\/wp\/v2\/posts\/885","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-json\/wp\/v2\/users\/37028"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-json\/wp\/v2\/comments?post=885"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-json\/wp\/v2\/posts\/885\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-json\/wp\/v2\/media\/889"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-json\/wp\/v2\/media?parent=885"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-json\/wp\/v2\/categories?post=885"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/sustainable-software\/wp-json\/wp\/v2\/tags?post=885"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}