A word about energy consumption

With the increased popularity of smart-phones, tablets and laptop, and the rise of environmental concerns in our society, energy efficiency has become a critical point when developing applications. Either for battery-saving purposes, lowering the electricity bill of data-centers, or simply for the sake of having a green computation unit, reducing the energy consumption is more than ever a major consideration when writing a program.

Usually, those concerns tend to be addressed at the hardware levels, and several strategies have been proposed, developed and added in our computers, smartphones or data-centers, such as Dynamic Voltage Frequency Scaling, PowerNap, or Clock-Gating [LSH10, MGW09, KAN11]. However, energy consumption is highly application dependent: even a very energy-efficient architecture can over-consume if the program executed on it is written in an energy-oblivious way.

Hence for developing energy-efficient applications, the implication of developers is necessary. Indeed, the right design choices have to be made, especially since software-level energy management approaches have proven themselves to be effective for lowering energy consumption [MPC14]. Nonetheless, some other studies show that most developers only have little to no knowledge about energy-efficiency: common misconceptions are often made, solutions used are not always efficient, and a general lack of energy-management tooling has to be deplored [PCL14,PHAH16].

Most developers only have little to no knowledge about energy-efficiency Click To Tweet

We believe giving developers insights about the energy consumption of their programs would help in understanding how they behave and could be a valuable asset for writing greener software. This article presents our approach for generating a model of the energy consumption of programs. First, a model is built from source code using reverse engineering. Then energy measurements are gathered at runtime and injected in this source-code model. This model can finally be used as a basis for improving energy awareness during the software development life-cycle. This article is based on an existing paper, presented in MeGSuS’18. The source code of the framework used is available on Github.

Model-Driven reverse engineering and energy consumption

Reverse Engineering aims at creating high-level representations of existing systems from software artifacts, in order to be understandable for humans [CDPC11]. In the realm of Model-Driven Engineering (MDE), this representation is a model, conforming to a meta-model describing its syntax and semantics.

Here, we propose a Model-Driven approach for representing the source code of a program along with its energy consumption. We use the MoDisco reverse engineering framework to generate a model out of a Java program [BCDM14]. A dynamic analysis is performed in order to gather energy measurements from the Java program execution. Those measurements are then modeled using the standard Structured Metrics Metamodel (SMM) and associated with the MoDisco model. This model can then be used as a basis for analyzing the energy consumption of a program, locating and understanding the energy-consuming parts of the code, and optimizing it with model-driven techniques.

Let us consider a running example for describing our process, the following source code is going to be used for that:

public class App {
    public static void main(String [] args) {
        App app = new App();
        app.methodA ();
        app.methodB ();
    }
    public void methodA () {
        // some lightweight computations
    }
    public void methodB () {
        // some heavy computations
    }
}

Step 1 – Reverse engineering

First of all, we need to generate a model from this source code. Using the model-driven reverse engineering Framework MoDisco on this program generates a model representing all the aspects of the source code: packages, classes, methods, statements, expressions, and so on. This static model provides a high-level view of our system, and can be used in a standalone way for program understanding, transformation or refactoring using dedicated tools. An excerpt of this model is shown below:

MoDisco model of the source code

 

Step 2 – Dynamic analysis

Whereas the MoDisco model is generated statically, collecting energy metrics requires the execution of the program. The standard behavior of this program does not allow energy measurements, thus it has to be instrumented beforehand, in order to add energy-measuring probes inside it.

For that purpose, we modify the JVM byte-code of that program at runtime, using the ASM library. Probes are added at the entry point and exit points of each method. The entry probe computes the energy consumption before executing the method, and the exit one computes the energy consumption after executing the method. Comparing the two values gives a rough estimation of the method’s energy consumption. Furthermore, we trace each method call. This allows us to reproduce a call graph of the program execution, used later in the approach. The following byte-code presents an example of such instrumentation. On the left side, the byte-code is generated from the main method presented earlier, and is not instrumented. On the right side the byte-code is instrumented: the red statements have been injected.

Energy aware bytecode

In order to measure the energy consumed by each method, we used jRAPL [LPL15]. jRAPL proposes a Java API for querying the Running Average Power Limit (RAPL) feature, available on Intel CPUs. RAPL provides the energy consumed by the CPU cores on-demand. Despite the fact that it is easy to use, the energy metrics provided by jRAPL are imprecise: they include the energy consumption of the system. Our current model does not aim at containing accurate energy consumption measurements, but only storing them in a standard model. However, improving the accuracy of our energy measurement tools is part of our future work.

Step 3 – Annotating the model via the Structured Metrics Meta-model

Once gathered, those measurements can be persisted in a model conforming to SMM. All the metrics gathered during execution are contained in an Observation element. Each energy measurement is modeled in a Measurement element, with the “value” attribute corresponding to the value measured. This Measurement element is linked to the corresponding MoDisco MethodDeclaration using the Measurand relationship: hence associating MoDisco and SMM. Furthermore, an ordered relationship is created between the Measurements, using the call graph information gathered at runtime. This relationship is used to retrace the execution of the program. In fact, a single method can be called several times during the execution of another method. This relationship is mandatory to understand the dynamic behavior of the program and its energy consumption. An excerpt of this model is available below.

SMM-based energy model

Using this model, we can understand the energy consumption behavior of the program. As an example, we can see that if the main() method energy consumption is important, it is because it called methodB(), which consumed a lot.

Fostering MDE for improving energy awareness

The model presented earlier can be used as a basis for improving energy awareness among developers. This model is standardized and persisted in order to be easily usable by other Model-Driven Engineering solutions. For instance, we used this model within the Sirius Framework to provide a graphical representation of the program. This graphical representation highlights the energy-consuming methods. The purpose is to help developers localizing the methods that should be optimized, in order to reduce the green footprint of their application. A first graphical representation of this model is proposed:

Graphical representation of the energy consumption model with Sirius

This representation shows the method calls in the system, and their corresponding energy consumption. Here, App$main called App$init, App$methodA and App$methodB. For demonstration purposes, we added an extra method call from App$methodB to App$methodC. The sizes and colors of the circle correspond to the energy consumption of the methods: a big red circle meaning that the method is energy consuming, and a small green circle means the opposite. The root method (App$main) is a white square.

Furthermore, we propose a representation at the method level, in order to help to understand the energy consumption of a specific method. The energy consumption of the method, and the energy consumption of each internal method calls, are shown. An example of this representation is proposed:

We can see that in App$main, App$methodB is the most energy consuming method call, whereas on its own, the App$main body consumed only 9% of the overall energy consumption.

Writing graphical representations of our model is fairly easy using Model-Driven tools such as Sirius or similar tools for building graphical editors. In fact, those tools are based upon modeling standards, that have been used in our approach. Besides proposing a graphical representation of a program, we believe our model can be used for energy optimization, especially through refactoring. As stated by G. Pinto et. al., energy-focused refactoring approaches are lacking [PSNC15]. MoDisco has proven itself to be efficient for modernizing and improving programs using model transformations.

Associated with SMM, such transformations can consider the energy consumption of methods, and could aim at optimizing the most energy-consuming ones. Several approaches for optimizing the energy consumption of programs have been identified [PCS+16, PFL16, SDF+11, dSBCC10], and could be implemented as model transformations to apply on our model.

Conclusion

This article presented our work for leveraging Model-Driven Engineering for energy-aware computing. We gather energy measurements at runtime, persist them in a model conforming to the SMM standard, and associate it with a model of the source code generated by MoDisco. We finally use this model to give developers feedbacks of their program energy consumption, through Graphical User Interfaces, hence helping them locating energy consuming methods.

We believe this model can be used for optimizing the energy consumption of programs through refactoring, though no experimentations have been performed on that yet.

References

[BCDM14] Hugo Bruneliere, Jordi Cabot, Grégoire Dupé, and Frédéric Madiot. Modisco: A model driven reverse engineering framework. Information and Software Technology, 56(8):1012–1032, 2014.

[CDPC11] Gerardo Canfora, Massimiliano Di Penta, and Luigi Cerulo. Achievements and challenges in software reverse engineering. Commun. ACM, 54(4):142–151, 2011.

[dSBCC10] Wellisson GP da Silva, Lisane Brisolara, Ulisses B Corrêa, and Luigi Carro. Evaluation of the impact of code refactoring on embeddedsoftware efficiency. In Proceedings of the 1st Workshop de Sistemas Embarcados, pages 145–150, 2010.7

[KAN11] Jagrit Kathuria, M Ayoubkhan, and Arti Noor. A review of clock gating techniques. MIT International Journal of Electronics and Communication Engineering, 1(2):106–114, 2011.

[LFMTS18] Thibault Béziers La Fosse, Jean-Marie Mottu, Massimo Tisi, and Gerson Sunyé. Characterizing a source code model with energy measurements. In Workshop on Measurement and Metrics for Green and Sustainable Software Systems, 2018.

[LFTM17] Thibault Béziers La Fosse, Massimo Tisi, and Jean-Marie Mottu. Injecting execution traces into a model-driven framework for program analysis. In Federation of International Conferences on Software Technologies: Applications and Foundations, pages 3–13. Springer, 2017.

[LPL15] Kenan Liu, Gustavo Pinto, and Yu David Liu. Data-oriented characterization of application-level energy optimization. In International Conference on Fundamental Approaches to Software Engineering, pages 316–331. Springer, 2015.

[LSH10] Etienne Le Sueur and Gernot Heiser. Dynamic voltage and frequencyscaling: The laws of diminishing returns. In Proceedings of the 2010 international conference on Power aware computing and systems, pages 1–8, 2010.

[MGW09] David Meisner, Brian T Gold, and Thomas F Wenisch. Powernap: eliminating server idle power. In ACM sigplan notices, volume 44,pages 205–216. ACM, 2009.

[MPC14] Irene Manotas, Lori Pollock, and James Clause. Seeds: a software engineer’s energy-optimization decision support framework. In Proceedings of the 36th International Conference on Software Engineering, pages 503–514. ACM, 2014.

[PCL14] Gustavo Pinto, Fernando Castor, and Yu David Liu. Mining ques-tions about software energy consumption. InProceedings of the 11thWorking Conference on Mining Software Repositories, pages 22–31.ACM, 2014.

[PCS+16] Rui Pereira, Marco Couto, João Saraiva, Jácome Cunha, and João Paulo Fernandes. The influence of the java collection framework on overall energy consumption. In Proceedings of the 5th International Workshop on Green and Sustainable Software, pages 15–21.ACM, 2016.

[PFL16] Giuseppe Procaccianti, Héctor Fernández, and Patricia Lago. Empirical evaluation of two best practices for energy-efficient software development. Journal of Systems and Software, 117:185–198, 2016.

[PHAH16] Candy Pang, Abram Hindle, Bram Adams, and Ahmed E Hassan. What do programmers know about software energy consumption? IEEE Software, 33(3):83–89, 2016.

[PSNC15] Gustavo Pinto, Francisco Soares-Neto, and Fernando Castor. Refactoring for energy efficiency: a reflection on the state of the art. In Proceedings of the Fourth International Workshop on Green and Sustainable Software, pages 29–35. IEEE Press, 2015.

[SDF+11] Adrian Sampson, Werner Dietl, Emily Fortuna, Danushen Gnanapra-gasam, Luis Ceze, and Dan Grossman. Enerj: Approximate datatypes for safe and general low-power computation. In ACM SIG-PLAN Notices, volume 46, pages 164–174. ACM, 2011.

Pin It on Pinterest

Share This