Leveraging DTrace for runtime verification Carl Martin Rosenberg - - PowerPoint PPT Presentation

leveraging dtrace for runtime verification
SMART_READER_LITE
LIVE PREVIEW

Leveraging DTrace for runtime verification Carl Martin Rosenberg - - PowerPoint PPT Presentation

Leveraging DTrace for runtime verification Carl Martin Rosenberg June 7th, 2016 Department of Informatics, University of Oslo Context: Runtime verification Desired properties Every request gets an answer System Buffers should never


slide-1
SLIDE 1

Leveraging DTrace for runtime verification

Carl Martin Rosenberg June 7th, 2016

Department of Informatics, University of Oslo

slide-2
SLIDE 2

Context: Runtime verification

slide-3
SLIDE 3

System

“Buffers should never overflow” “Every request gets an answer”

Desired properties

“Variables should never enter an inconsistent state”

1

slide-4
SLIDE 4

‘‘Runtime verification is the discipline of computer science that deals with the study, development and application of those verification techniques that allow checking whether a run of a system under scrutiny […] satisfies or violates a given correctness property.’’ [6, p. 36, emphasis mine]

2

slide-5
SLIDE 5

… … … … … … …

3

slide-6
SLIDE 6

… … … … … … …

4

slide-7
SLIDE 7

How to do runtime verification

  • 1. Rigorously specify a correctness property (typically using formal

logic).

  • 2. Collect runtime data from the system.
  • 3. Find a way to automatically check if the collected data indicates

that the correctness property is violated or satisfied.

5

slide-8
SLIDE 8

Key idea: Exploit formal connections between logic and automata theory

5

slide-9
SLIDE 9

How to do runtime verification

  • 1. There are ways of deriving automata from logical expressions

that accept or reject their input based on whether the input satisfies or falsifies a logical formula.

  • 2. This can be used to create monitors.

6

slide-10
SLIDE 10

Monitors

A monitor is a program that consumes data from the system under scrutiny, interprets this data as a run of a system and reports whether the specified property is

  • satisfied by the data,
  • falsified by the data or
  • that the data is insufficient to derive a verdict [7, p. 294–295].

7

slide-11
SLIDE 11

Monitor Trace extractor System being analyzed Monitor generator Specification formula ACCEPT REJECT INCONCLUSIVE Trace 8

slide-12
SLIDE 12

ACCEPT REJECT INCONCLUSIVE

Specification formula in LTL3

graphviz2dtrace Mapping D script Dtrace System being analyzed

9

slide-13
SLIDE 13

Specification formalism: LTL3

slide-14
SLIDE 14

LTL3 is a three-valued variety of Linear Temporal Logic (LTL): Same syntax, different semantics.

9

slide-15
SLIDE 15

LTL: Linear Temporal Logic

  • In the context of formal methods, Temporal Logic is used to

reason about the evolution of some system over time.

  • LTL is based on the notion of time as an infinite sequence of

time slices: Time is linear.

  • The idea of using Linear Temporal Logic for program verification
  • riginated with Pnueli [8].

10

slide-16
SLIDE 16

Linear time

p,q r,s p,s

11

slide-17
SLIDE 17

LTL Syntax

Syntactically, LTL extends the familiar Propositional Logic with temporal operators. The temporal operators are:

  • (always),
  • (eventually),
  • (next),
  • U (until),
  • R (release),
  • W (weak until/waiting for).

12

slide-18
SLIDE 18

LTL Semantics

  • LTL formulas are interpreted on sequences of states, where each

state contains a set of atomic propositions that are true in that state.

  • In the standard view, these sequences of states are considered

infinite, and we call such sequences of states traces.

13

slide-19
SLIDE 19

LTL Semantics

p,q r,s p,s

… Some observations:

  • σ |

= p U s,

  • σ |

= s,

  • σ |

= r,

  • σ ̸|

= p and

  • σ |

= p W s.

14

slide-20
SLIDE 20

Key idea of LTL3: A reasonable way of dealing with finite traces.

14

slide-21
SLIDE 21

LTL3 Semantics

  • LTL3 is defined for finite traces, which makes it suitable for

runtime verification: We can only observere finite runs.

15

slide-22
SLIDE 22

Key idea of LTL3: Identify good and bad prefixes [5].

15

slide-23
SLIDE 23

Good prefix

  • A trace fragment u is a good prefix with respect to some

property φ if φ holds in all possible futures following u.

16

slide-24
SLIDE 24

Bad prefix

  • A trace fragment u is a bad prefix with respect to some property

φ if φ holds in no possible futures following u.

17

slide-25
SLIDE 25

LTL3 Semantics summarized

We can thus state the truth-value of an LTL3 formula φ with respect to a finite trace u as follows: u| =3φ =        ⊤ if u is a good prefix wrt. φ ⊥ if u is a bad prefix wrt. φ ?

  • therwise.

18

slide-26
SLIDE 26

Foundational idea: For an LTL formula φ, a corresponding Büchi automaton [2] can be derived.

18

slide-27
SLIDE 27
  • Büchi Automata are defined on infinite traces and accept a trace

if and only if the automaton visits some accepting state infinitely often.

19

slide-28
SLIDE 28
  • Bauer et al. give an algorithm for creating LTL3-monitors [1,

14:10-14:13]

  • This algorithm is implemented in LamaConv [9], which we make

use of in the thesis.

20

slide-29
SLIDE 29

21

slide-30
SLIDE 30

Monitor Trace extractor System being analyzed Monitor generator Specification formula ACCEPT REJECT INCONCLUSIVE Trace 22

slide-31
SLIDE 31

Monitor Trace extractor System being analyzed ACCEPT REJECT INCONCLUSIVE Trace

Specification formula in LTL3

Monitor generator

23

slide-32
SLIDE 32

DTrace

slide-33
SLIDE 33
  • DTrace is an operating system technology for monitoring

running software systems.

  • Originally written by Bryan Cantrill, Adam Leventhal and Mike

Shapiro for the Sun Solaris 10 operating system, DTrace is now available for Mac OS X, FreeBSD and other systems [4]

  • If a running system has DTrace installed, an administrative user

can log into the system, write a DTrace script and get insights about the system without having to reboot, stop or alter the system in any way.

24

slide-34
SLIDE 34

DTrace’s two most compelling features

  • 1. DTrace gives a unified view of the whole system: Events within

the kernel and in userland processes can be analyzed simultaneously.

  • 2. DTrace provides facilities for dynamic tracing: Instrumentation

which does not rely on static artifacts in the source code.

25

slide-35
SLIDE 35

Using DTrace: The D scripting language

  • Users interact with the DTrace framework via a domain-specific

AWK-like scripting language called D.

  • D is an event-driven programming langauge, where users specify

actions that DTrace should take when an event of interest

  • ccurs.

26

slide-36
SLIDE 36

Using DTrace: The D scripting language

#!/usr/sbin/dtrace -qs syscall::read:entry /execname != "dtrace" / { printf("%s\n", execname); }

27

slide-37
SLIDE 37

Main components of D

  • Probes (4-tuples)
  • Action blocks
  • Predicates
  • Probe clauses

28

slide-38
SLIDE 38

DTrace Probes

  • DTrace provides the user with an enormous list of possible

instrumentation points representing events of interest. These instrumentation points are called probes.

  • The available probes reflect aspects of the system that can be

monitored at the current point in time.

  • Probes are identified by a four-tuple

<provider:module:function:name>.

  • When the event a probe represents occurs, one says that the

probe ‘‘fires’’).

29

slide-39
SLIDE 39

Design and Implementation of graphviz2dtrace

slide-40
SLIDE 40

Basic idea: Associate atomic propositions in LTL specifications with DTrace probe specifications (with optional predicates).

29

slide-41
SLIDE 41

push → pid$target::push:entry pop → pid$target::pop:return empty → pid$target::empty:return/arg1 == 1/

30

slide-42
SLIDE 42

graphviz2dtrace Mapping D script 31

slide-43
SLIDE 43

graphviz2dtrace

  • In essence, graphviz2dtrace is a source-to-source compiler

which takes LTL3-based automata and creates corresponding D scripts.

  • The resulting scripts have the automaton’s transition function

encoded in an array, and the automaton state stored in a variable.

  • When an event occurs, the state of the automaton is updated

according to the transition function.

32

slide-44
SLIDE 44

Anticipation

  • graphviz2dtrace creates monitors that terminate

immediately upon finding a good or bad prefix: They are anticipatory.

  • The scripts achieve this by understanding which state it is about

to enter.

33

slide-45
SLIDE 45

Anticipation

pid$target::empty:return / (arg1 == 1) && (state == 1)/ { trace("REJECTED"); HAS_VERDICT = 1; exit(0); }

34

slide-46
SLIDE 46

Implementation

  • The essential implemenation concern is creating three types of

probe clauses: rejecting, accepting and neutral clauses.

  • Rejecting clauses are clauses dealing with situations where bad

prefixes are found.

  • Accepting clauses are clauses dealing with situations where

good prefixes are found.

  • Neutral clauses simply update the state of the automaton.

35

slide-47
SLIDE 47

36

slide-48
SLIDE 48

Implementation

  • Since all clauses use predicates to reason about the automaton

states, and since probes are processed top to bottom, neutral clauses must be placed last in the script.

37

slide-49
SLIDE 49

Key limitation: Race conditions occur if two neutral probe clauses fire simultaneously.

37

slide-50
SLIDE 50

Monitor Trace extractor System being analyzed ACCEPT REJECT INCONCLUSIVE Trace

Specification formula in LTL3

Monitor generator

38

slide-51
SLIDE 51

ACCEPT REJECT INCONCLUSIVE

Specification formula in LTL3

graphviz2dtrace Mapping D script Dtrace System being analyzed

39

slide-52
SLIDE 52

Case study 1: The stack

slide-53
SLIDE 53

Demo time! https://vimeo.com/169470067 (03:00)

39

slide-54
SLIDE 54

Gregg’s dictum

Brendan Gregg [10]

  • ‘‘Don’t worry too much about pid provider probe cost at < 1000

events/sec.’’

  • ‘‘At > 10,000 events/sec, pid provider probe cost will be

noticeable.’’

  • ‘‘At > 100,000 events/sec, pid provider probe cost may be

painful.’’ [3]

40

slide-55
SLIDE 55

104 105 106 107 108 10−2 10−1 100 101 102 0.003 0.067 0.602 0.353 0.414 1.096 8.011 72.363 0.003 0.057 0.398 3.176 30.718 Iterations Running time in seconds Monitor overhead1 Uninstrumented with pid with printf

1Averaged, measured with time, largest of real or user+sys

41

slide-56
SLIDE 56

Case study 2: Node.js and PostgreSQL

slide-57
SLIDE 57

Demo time! https://vimeo.com/169585739 (02:55)

41

slide-58
SLIDE 58

20 40 60 80 100 1,200 1,400 1,600 1,800 2,000 N concurrent connections Mean processed requests Mean processed requests per second at various concurrency levels2 Monitored Unmonitored

2Averaged, measured with ab

42

slide-59
SLIDE 59

Conclusion and Evaluation

slide-60
SLIDE 60

Questions?

42

slide-61
SLIDE 61

References I

  • A. Bauer, M. Leucker, and C. Schallhart.

Runtime verification for ltl and tltl. ACM Trans. Softw. Eng. Methodol., 20(4):14:1–14:64, Sept. 2011.

  • J. R. Büchi.

On a decision method in restricted second order arithmetic. In Proc. Internat. Congr. Logic, Method. and Philos. Sci, pages 1–12, 1960.

  • B. Gregg.

DTrace pid Provider Overhead. http://dtrace.org/blogs/brendan/2011/02/18/ dtrace-pid-provider-overhead/, 2011.

slide-62
SLIDE 62

References II

  • B. Gregg and J. Mauro.

DTrace: Dynamic Tracing in Oracle Solaris, Mac OS X, and FreeBSD. Prentice Hall Professional, 2011.

  • O. Kupferman and M. Y. Vardi.

Model checking of safety properties. Formal Methods in System Design, 19(3):291–314, 2001.

  • M. Leucker.

Teaching runtime verification. In S. Khurshid and K. Sen, editors, Runtime Verification, volume 7186 of Lecture Notes in Computer Science, pages 34–48. Springer Berlin Heidelberg, 2012.

slide-63
SLIDE 63

References III

  • M. Leucker and C. Schallhart.

A brief account of runtime verification. The Journal of Logic and Algebraic Programming, 78(5):293 – 303, 2009.

The 1st Workshop on Formal Languages and Analysis of Contract-Oriented Software (FLACOS’07).

  • A. Pnueli.

The temporal logic of programs. In Foundations of Computer Science, 1977., 18th Annual Symposium on, pages 46–57. IEEE, 1977.

  • T. Scheffel and M. S. et al.

Lamaconv—logics and automata converter library. http://www.isp.uni-luebeck.de/lamaconv.

slide-64
SLIDE 64

References IV

  • D. Straughan.

Brendan Gregg speaking at ZFS Day, Oct 2, 2012, San Francisco., 2012. (Own work) [CC BY-SA 3.0], via Wikimedia Commons.