Top Banner
OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard
39

OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

Dec 20, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

OORPTObject-Oriented Reengineering Patterns and Techniques

12. Analyzing Dynamic Behavior

Orla Greevy & Adrian Lienhard

Page 2: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.2

What is Dynamic Analysis?

The investigation of the properties of a running software system over one or more executions

(Static analysis examines the program code alone)

Page 3: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.3

Has anyone used Dynamic Analysis?

Page 4: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.4

Roadmap

MotivationSources of Runtime Information Tracing techniques and their challengesOverview of Tools (Loggers, Debuggers, Profilers, etc)Dynamic Analysis in a Reverse Engineering ContextSummary

Page 5: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.5

What does this program do?

#include <stdio.h>main(t,_,a)char *a;{return!0<t?t<3?main(-79,-13,a+main(-87,1-_,main(-86,0,a+1)+a)):1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13?main(2,_+1,"%s %d %d¥n"):9:16:t<0?t<-72?main(_,t,"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+,/+#n+,/#¥;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l ¥q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# ¥){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' ¥iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c ¥;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')# ¥}'+}##(!!/"):t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1) :0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a,"!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:¥nuwloca-O;m .vpbks,fxntdCeghiry"),a+1);}

Thomas Ball, The Concept of Dynamic Analysis, FSE’99

Page 6: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.6

Why Dynamic Analysis?

Gap between run-time structure and code structure in OO programs

Trying to understand one [structure] from the other is like trying to understand the dynamism of living ecosystems from the static taxonomy of plants and animals, and vice-versa.

-- Erich Gamma et al., Design Patterns

Page 7: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.7

Reengineering Patterns based on Dynamic Analysis

Interview during demoFind typical usage scenarios and main features

Step through the Execution with a debuggerUnderstand how objects collaborate

TestsYour life insurance

Page 8: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.8

Runtime Information Sources

Many possibilities: hardware monitoring, tracing method execution, values of variables, memory usage etc...

execute program and watch it from outside

Internal viewExternal view

instrument program and watch it from inside

Page 9: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.9

External View

Program output, UI (examine behavior, performance, …)

Analyze used resourcesCPU and memory usage (top)Network usage (netstat, tcpdump)Open files, pipes, sockets (lsof)

Examine logs (syslog, web logs, stdout/stderr, …)

Page 10: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.10

Internal View

Log statementsin code

Stack trace

Debugger

Many different tools are based on tracing: execution profilers, test coverage analyzers, tools for reverse engineering…

Execution trace

Page 11: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.11

Execution Tracing

How can we capture “full”OO program execution?

Trace entry and exit of methods

Additional information:- receiver and arguments- class instantiations- …?

Page 12: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.12

Tracing Techniques

Instrumentation approaches—Sourcecode modification—Bytecode modification—Wrapping methods (Smalltalk)

Simulate execution (using debugger infrastructure)

Sampling

At the VM level—Execution tracing by the interpreter—(Dynamic recompilation, JIT)

Page 13: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.13

Technical Challenges

> Instrumentation influences the behavior of the execution> Overhead: increased execution time> Large amount of data

> Code also used by the tracer, library and system classes cannot be instrumented

-> Trace at the VM level-> Scope instrumentation (Changeboxes)

Page 14: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.14

Roadmap

MotivationSources of Runtime Information Tracing techniques and their challengesOverview of Tools (Loggers, Debuggers, Profilers, etc)Dynamic Analysis in a Reverse Engineering ContextSummary

Page 15: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.15

Debuggers

Breakpoint Debuggersjdb, gdb,… (run, step, inspect)

Omniscent Debuggers (http://www.lambdacs.com/debugger/debugger.html)

Memory Debuggersjmp - java memory profilerpurify (IBM Rational) - a tool for detecting

memory leaks in C,C++ code

Page 16: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.16

Loggers - low tech debugging

“…debugging statements stay with the program; debugging sessions are transient. “

Kerningham and Pikepublic class Main {public static void main(String[] args) {

Clingon aAlien = new Clingon();System.out.println(“in main “); aAlien.spendLife();}

}

Very messy!

Page 17: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.17

- defacto standard for Java

Pros- easy to use, widely used by open source and java projects- Configurable and flexible (format the output, log levels)

- Allows enabling of logging at runtime without modifying the application binary

- Remote servers for remote monitoring …Cons- Performance overhead- Requires effort to decide where to put log statements- Code Cluttering - Logging accounts for ~ 4% of code

export TOMCAT_OPTS="-Dlog4j.debug -Dlog4j.configuration=foobar.xml

Page 18: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.18

Short Demo of log4j usage

> …

import org.apache.log4j.Logger; … public class Main {

static Logger logger = Logger.getLogger(MyApp.class); public static void main(String[] args) {

Clingon aAlien = new Clingon();logger.info(“Entering Application“); aAlien.spendLife();}

}

1 [main] (Main.java) - Entering Application.

Page 19: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.19

Profilers are used to track performance for optimization

- Timing information to detect bottlenecks- Compare the cost of various implementations- Understand what is happening?- Produces an execution Trace and statistical summary

Page 20: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.20

JProfiler Example Views

Page 21: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.21

JWireTap: An Interactive Profiler for Eclipse (Demo)

Page 22: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.22

Roadmap

MotivationSources of Runtime Information Tracing techniques and their challengesOverview of Tools (Loggers, Debuggers, Profilers, etc)Dynamic Analysis in a Reverse Engineering ContextSummary

Page 23: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.23

Reverse Engineering

static view

QuickTime™ and aTIFF (Uncompressed) decompressor

are needed to see this picture.

+

execution traces dynamic view

+ Dynamic Analysis

Page 24: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.24

Dynamic Analysis for Program Comprehension

Post Mortem Analysis of execution tracesMetrics Based Approaches

-Frequency Analysis [Ball, Zaidman]-Runtime Coupling Metrics based on Web mining techniques to detect key classses in a trace. [Zaidman 2005] -High-Level Polymetric Views of Condensed Run-Time Information [Ducasse, Lanza and Bertoulli 2004]

-Query-based approaches Recoverind high-level views from runtime data

[Richner and Ducasse 1999]

Page 25: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.25

Visualization of Runtime Behavior

Problem of

Large traces

[JinSight, De Pauw 1993]

Page 26: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.26

Feature-Centric Reverse Engineering

F2F1

Fn

F1

Fn

F2

Software System

Users Software developer

Page 27: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.27

Bug reports often expressed in terms of Features.

I can’t add new contacts!!!

The “add contacts“

feature

Page 28: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.28

Dividing a trace into features

Feature 1 Feature 2 Feature n

Page 29: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.29

Feature Identification is a technique to map features to source code.

“A feature is an observable unit of behavior of a system triggered by the user” [Eisenbarth etal. 2003]

Software Reconnaissance [Wilde and Scully ]Run a (1) feature exhibiting scenario and a (2) non-exhibiting scenario and compare the traces. Then browse the source code.

Page 30: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.30

Feature-Centric Analysis:3 Complementary Perspectives

F1

F3

F2

F4

F5

Features Perspective

Features RelationshipsPerspective

Classes Perspective

Page 31: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.31

Dynamix - A Model for Dynamic Analysis

Page 32: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.32

DynaMoose - An Environment for Feature Analysis

Page 33: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.33

Demo of Feature Analysis - Feature Views of Classes

Feature Views of PhoneSim Classes

PhoneButtonEventBackSpace

PhoneStateContactPhoneStateContactFormEditableTextCustomTextArea

Page 34: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.34

Feature Views of ‘Phonesim’ Methods

Feature Views of PhoneSim Methods

Page 35: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.35

Feature Relationships based on shared usage of classes or methods.

browseContacts,addContacts

Page 36: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.36

Object Flow Analysis

Method execution traces do not reveal how… objects refer to each other… object references evolve

Trace and analyze object flow— Object-centric debugger:

Trace back flow from errors to code that produced the objects

— Detect object dependencies between features

Page 37: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.37

Dynamic vs. Static Analysis

Static analyses extract properties that hold for all possible program runs

Dynamic analysis provides more precise information…but only for the execution under consideration

Dynamic analysis cannot show that a program satisfies a particular property, but can detect violations of the property

Page 38: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.38

Conclusions: Pros and Cons

Dependent on input—Advantage: Input or features can be directly related to execution—Disadvantage: May fail to exercise certain important paths and poor choice of input may be unrepresentative

Broad scope: dynamic analyses follow long paths and may discover semantic dependencies between program entities widely separated in space and time

However, understanding dynamic behavior of OO systems is difficultLarge number of executed methodsExecution paths crosscut abstraction layersSide effects

Page 39: OORPT Object-Oriented Reengineering Patterns and Techniques 12. Analyzing Dynamic Behavior Orla Greevy & Adrian Lienhard.

12.39

License

> http://creativecommons.org/licenses/by-sa/2.5/

Attribution-ShareAlike 2.5You are free:• to copy, distribute, display, and perform the work• to make derivative works• to make commercial use of the work

Under the following conditions:

Attribution. You must attribute the work in the manner specified by the author or licensor.

Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one.

• For any reuse or distribution, you must make clear to others the license terms of this work.• Any of these conditions can be waived if you get permission from the copyright holder.

Your fair use and other rights are in no way affected by the above.

Attribution-ShareAlike 2.5You are free:• to copy, distribute, display, and perform the work• to make derivative works• to make commercial use of the work

Under the following conditions:

Attribution. You must attribute the work in the manner specified by the author or licensor.

Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one.

• For any reuse or distribution, you must make clear to others the license terms of this work.• Any of these conditions can be waived if you get permission from the copyright holder.

Your fair use and other rights are in no way affected by the above.