MarQ : Monitoring At Runtime with QEA Giles Reger in collaboration - - PowerPoint PPT Presentation

marq monitoring at runtime with qea
SMART_READER_LITE
LIVE PREVIEW

MarQ : Monitoring At Runtime with QEA Giles Reger in collaboration - - PowerPoint PPT Presentation

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ MarQ : Monitoring At Runtime with QEA Giles Reger in collaboration with Helena Cuenca Cruz, David Rydeheard at University of Manchester, UK April 17th, 2015 Runtime


slide-1
SLIDE 1

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

MarQ: Monitoring At Runtime with QEA

Giles Reger in collaboration with Helena Cuenca Cruz, David Rydeheard at University of Manchester, UK April 17th, 2015

slide-2
SLIDE 2

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Outline

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

slide-3
SLIDE 3

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Motivation

  • See lots of other talks for why we want formal guarantees

about correctness of software systems

  • Static verification has many successes but
  • It can have scalability issues
  • It often works with abstractions of the real system
  • It often needs to make assumptions about the environment

and input data

  • Runtime verification is a complementary technique that

tackles these issues by ‘verifying’ a single run of the system

  • Additionally, if performed at runtime it can be used to stop or

correct bad behaviour

slide-4
SLIDE 4

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Runtime Monitoring Problems

Runtime Monitoring

Checking whether an execution trace τ produced at runtime satisfies a given a (typically temporal) specification φ

Online Runtime Monitoring

Performing runtime monitoring alongside the running system.

Offline Runtime Monitoring

Performing runtime monitoring on a log file after running the system.

Parametric Runtime Monitoring

Runtime monitoring with first-order specifications i.e. ones that deal with data-carrying events

slide-5
SLIDE 5

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Online Runtime Monitoring Setup

Instrument the system to observe a trace of relevant events

system ¡ instrumenta,on ¡ monitor ¡

  • bserve ¡

verdict ¡ feedback ¡ property ¡

slide-6
SLIDE 6

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Online Runtime Monitoring Setup

The monitor uses the given property . . .

system ¡ instrumenta,on ¡ monitor ¡

  • bserve ¡

verdict ¡ feedback ¡ property ¡

slide-7
SLIDE 7

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Online Runtime Monitoring Setup

. . . to process each event . . . possibly providing feedback. . .

system ¡ instrumenta,on ¡ monitor ¡

  • bserve ¡

verdict ¡ feedback ¡ property ¡

slide-8
SLIDE 8

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Online Runtime Monitoring Setup

. . . and finally computing a verdict - did the system pass?

system ¡ instrumenta,on ¡ monitor ¡

  • bserve ¡

verdict ¡ feedback ¡ property ¡

slide-9
SLIDE 9

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Online Runtime Monitoring in Practice

  • Lots of pragmatic considerations
  • Instrumentation
  • Overhead
  • Interference
  • Commonly shown to be useful for checking usage of libraries -

successful application to large open source projects

  • Recent industrial successes in the banking industry for

monitoring reliability and correctness

  • Applicable to safety-critical systems i.e. aerospace,

automotive, medical.

slide-10
SLIDE 10

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Offline Runtime Monitoring in Practice

  • Idea: record behaviour and check afterwards
  • Gives minimal/predictable overhead
  • Applies to more general domains/settings
  • Only get what is recorded
  • Offline RV successes at NASA’s JPL
  • Used on the LADEE mission to check command sequences

sent to the spacecraft as part of a daily testing regime

  • Used daily on the MSL mission to check rules against

Spacecraft telemetry logs sent from Curiosity

slide-11
SLIDE 11

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Parametric (or first-order) Properties

  • Originally runtime verification considered properties over

event names i.e. using propositional LTL or automata

  • A parametric event consists of a name and a list of data values
  • Examples:
  • An iterator i created from a collection c should not be used

after c is updated

  • Every start(t) should have a corresponding stop(t)
  • If locks l1 and l2 are taken in one order by a thread t then later

they should not be taken in the reverse order by any thread

  • Introduces new challenges in terms of specification languages

and monitoring algorithms

slide-12
SLIDE 12

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Contributions

  • We introduce the MarQ runtime monitoring tool
  • MarQ stands for Monitoring at runtime with QEA
  • Quantified Event Automata (QEA) is a previously introduced

specification language for parametric specifications MarQ

  • Can be used offline and online
  • Supports all features of the QEA language
  • Is efficient
  • Won the Offline and Java tracks of the CRV14, the first

international competition on runtime verification.

  • Incorporates novel indexing, redundancy elimination and

structural specialisation techniques

slide-13
SLIDE 13

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Outline

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

slide-14
SLIDE 14

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

The Slicing idea

  • Based on the notion of parametric trace slicing
  • Turns a quantified problem into a set of unquantified problems
  • The basic idea of QEA
  • 1. Use a list of quantifications to define trace slices relating to

separate valuations of quantified variables

  • 2. Use an extended finite state machine to check properties over

those slices

  • 3. The quantifications define which trace slices need to be

accepted by the state machine

slide-15
SLIDE 15

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Quantified Event Automata

Definition (Event Automaton)

An Event Automaton Q, A, δ, q0, F is a tuple where

  • Q is a set of states,
  • A ⊆ SymbolicEvent is a alphabet of events,
  • δ ⊆ (Q × A × Guard ×Assign × Q) is a set of transitions,
  • q0 is an initial state, and
  • F ⊆ Q is a set of final states.

Definition (Quantified Event Automaton)

A QEA is a pair Λ, E where

  • Λ ∈ ({∀, ∃}× variables(E) × Guard)∗ is a list of quantified

variables with guards, and

  • E is an Event Automaton
slide-16
SLIDE 16

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

UnsafeMapIterator Example

Property : UnsafeMapIterator

An iterator created from a collection created from a map should not be used after the map is updated. 1 2 3 4 5 ¬∃m, ∃c, ∃i create(m,c) iterator(c,i) update(m) use(i)

slide-17
SLIDE 17

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Demonstrating slicing

create(M, C1).iterator(C1, I1).use(I1).update(M).create(M, C2). iterator(C2, I2).iterator(C2, I3).use(I3).update(M).use(I2) There are six possible bindings 1 2 3 4 5 ¬∃m, ∃c, ∃i create(m,c) iterator(c,i) update(m) use(i)

slide-18
SLIDE 18

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Demonstrating slicing

create(M, C1).iterator(C1, I1).use(I1).update(M).create(M, C2). iterator(C2, I2).iterator(C2, I3).use(I3).update(M).use(I2) For m = M, c = C1, i = I1 1 2 3 4 5 ¬∃m, ∃c, ∃i create(m,c) iterator(c,i) update(m) use(i)

slide-19
SLIDE 19

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Demonstrating slicing

create(M, C1).iterator(C1, I1).use(I1).update(M).create(M, C2). iterator(C2, I2).iterator(C2, I3).use(I3).update(M).use(I2) For m = M, c = C2, i = I2 1 2 3 4 5 ¬∃m, ∃c, ∃i create(m,c) iterator(c,i) update(m) use(i)

slide-20
SLIDE 20

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Demonstrating slicing

create(M, C1).iterator(C1, I1).use(I1).update(M).create(M, C2). iterator(C2, I2).iterator(C2, I3).use(I3).update(M).use(I2) For m = M, c = C2, i = I3 1 2 3 4 5 ¬∃m, ∃c, ∃i create(m,c) iterator(c,i) update(m) use(i)

slide-21
SLIDE 21

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Demonstrating slicing

create(M, C1).iterator(C1, I1).use(I1).update(M).create(M, C2). iterator(C2, I2).iterator(C2, I3).use(I3).update(M).use(I2) There exists a slice that reaches a final state. The quantifications mean that the trace violates the property. 1 2 3 4 5 ¬∃m, ∃c, ∃i create(m,c) iterator(c,i) update(m) use(i)

slide-22
SLIDE 22

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Free Variables

  • Some variables in the Event Automaton may not be quantified
  • These are called free variables
  • Free variables are (re)bound as the trace is processed
  • Allowing us to capture changing data values
slide-23
SLIDE 23

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Auction Bidding Example

Property : Auction Bidding

Amounts bid for an item should be strictly increasing. 1 2 3 ∀item bid(item, max) bid(item, new) new>max

max:=new

bid(item, new) new≤max

slide-24
SLIDE 24

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Auction Bidding Example

Property : Auction Bidding

Amounts bid for an item should be strictly increasing. 1 2 3 ∀item bid(item, max) bid(item, new) new>max

max:=new

bid(item, new) new≤max

slide-25
SLIDE 25

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Bidding For A Hat

bid(hat, 5).bid(hat, 10).bid(hat, 7) 1 2 3 bid(hat, max) bid(hat, new) new>max

max:=new

bid(hat, new) new≤max

slide-26
SLIDE 26

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Bidding For A Hat

bid(hat, 5).bid(hat, 10).bid(hat, 7) 1 2 3 bid(hat, max) bid(hat, new) new>max

max:=new

bid(hat, new) new≤max 1, [ ]

slide-27
SLIDE 27

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Bidding For A Hat

bid(hat, 5).bid(hat, 10).bid(hat, 7) 1 2 3 bid(hat, max) bid(hat, new) new>max

max:=new

bid(hat, new) new≤max 1, [ ]

bid(hat,5)

− → 2, [max → 5]

slide-28
SLIDE 28

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Bidding For A Hat

bid(hat, 5).bid(hat, 10).bid(hat, 7) 1 2 3 bid(hat, max) bid(hat, new) new>max

max:=new

bid(hat, new) new≤max 1, [ ]

bid(hat,5)

− → 2, [max → 5]

bid(hat,10)

− → 2, [new → 10, max → 10]

slide-29
SLIDE 29

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Bidding For A Hat

bid(hat, 5).bid(hat, 10).bid(hat, 7) 1 2 3 bid(hat, max) bid(hat, new) new>max

max:=new

bid(hat, new) new≤max 1, [ ]

bid(hat,5)

− → 2, [max → 5]

bid(hat,10)

− → 2, [new → 10, max → 10]

bid(hat,7)

− → 3, [new → 7, max → 10]

slide-30
SLIDE 30

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Outline

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

slide-31
SLIDE 31

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

UnsafeMapIterator Example

Property : UnsafeMapIterator

An iterator created from a collection created from a map should not be used after the map is updated. 1 2 3 4 5 ¬∃m, ∃c, ∃i create(m,c) iterator(c,i) update(m) use(i)

slide-32
SLIDE 32

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Monitoring algorithm

The monitoring algorithm is organised as follows

  • There is a map M from bindings (of quantified variables) to

sets of configurations (reached by that slice)

  • For each incoming event
  • Decides if new bindings need to be created, possibly extending

existing bindings

  • Updates configurations related to existing relevant bindings
  • Produces a verdict based on the quantifications and M

bindings configurations m=M1,c=C1 − → { 2 } m=M1,c=C1,i=I1 − → { 3 }

slide-33
SLIDE 33

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Monitoring algorithm

The monitoring algorithm is organised as follows

  • There is a map M from bindings (of quantified variables) to

sets of configurations (reached by that slice)

  • For each incoming event
  • Decides if new bindings need to be created, possibly extending

existing bindings

  • Updates configurations related to existing relevant bindings
  • Produces a verdict based on the quantifications and M

bindings configurations m=M1,c=C1 − → { 2 } m=M1,c=C1,i=I1 − → { 3 }

slide-34
SLIDE 34

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Monitoring algorithm

The monitoring algorithm is organised as follows

  • There is a map M from bindings (of quantified variables) to

sets of configurations (reached by that slice)

  • For each incoming event

iterator(C1,I2)

  • Decides if new bindings need to be created, possibly extending

existing bindings

  • Updates configurations related to existing relevant bindings
  • Produces a verdict based on the quantifications and M

bindings configurations m=M1,c=C1 − → { 2 } m=M1,c=C1,i=I1 − → { 3 }

slide-35
SLIDE 35

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Monitoring algorithm

The monitoring algorithm is organised as follows

  • There is a map M from bindings (of quantified variables) to

sets of configurations (reached by that slice)

  • For each incoming event

iterator(C1,I2)

  • Decides if new bindings need to be created, possibly extending

existing bindings

  • Updates configurations related to existing relevant bindings
  • Produces a verdict based on the quantifications and M

bindings configurations m=M1,c=C1 − → { 2 } m=M1,c=C1,i=I1 − → { 3 } m=M1,c=C1,i=I2 − → { 3 }

slide-36
SLIDE 36

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Monitoring algorithm

The monitoring algorithm is organised as follows

  • There is a map M from bindings (of quantified variables) to

sets of configurations (reached by that slice)

  • For each incoming event

iterator(C1,I2)

  • Decides if new bindings need to be created, possibly extending

existing bindings

  • Updates configurations related to existing relevant bindings
  • Produces a verdict based on the quantifications and M

bindings configurations m=M1,c=C1 − → { 2 } m=M1,c=C1,i=I1 − → { 3 } m=M1,c=C1,i=I2 − → { 3 }

slide-37
SLIDE 37

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Monitoring algorithm

The monitoring algorithm is organised as follows

  • There is a map M from bindings (of quantified variables) to

sets of configurations (reached by that slice)

  • For each incoming event

update(M1)

  • Decides if new bindings need to be created, possibly extending

existing bindings

  • Updates configurations related to existing relevant bindings
  • Produces a verdict based on the quantifications and M

bindings configurations m=M1,c=C1 − → { 2 } m=M1,c=C1,i=I1 − → { 3 } m=M1,c=C1,i=I2 − → { 3 }

slide-38
SLIDE 38

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Monitoring algorithm

The monitoring algorithm is organised as follows

  • There is a map M from bindings (of quantified variables) to

sets of configurations (reached by that slice)

  • For each incoming event

update(M1)

  • Decides if new bindings need to be created, possibly extending

existing bindings

  • Updates configurations related to existing relevant bindings
  • Produces a verdict based on the quantifications and M

bindings configurations m=M1,c=C1 − → { 2 } m=M1,c=C1,i=I1 − → { 3 } m=M1,c=C1,i=I2 − → { 3 }

slide-39
SLIDE 39

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Monitoring algorithm

The monitoring algorithm is organised as follows

  • There is a map M from bindings (of quantified variables) to

sets of configurations (reached by that slice)

  • For each incoming event

update(M1)

  • Decides if new bindings need to be created, possibly extending

existing bindings

  • Updates configurations related to existing relevant bindings
  • Produces a verdict based on the quantifications and M

bindings configurations m=M1,c=C1 − → { 2 } m=M1,c=C1,i=I1 − → { 4 } m=M1,c=C1,i=I2 − → { 4 }

slide-40
SLIDE 40

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Monitoring algorithm

The monitoring algorithm is organised as follows

  • There is a map M from bindings (of quantified variables) to

sets of configurations (reached by that slice)

  • For each incoming event
  • Decides if new bindings need to be created, possibly extending

existing bindings

  • Updates configurations related to existing relevant bindings
  • Produces a verdict based on the quantifications and M

bindings configurations m=M1,c=C1 − → { 2 } m=M1,c=C1,i=I1 − → { 4 } m=M1,c=C1,i=I2 − → { 4 }

slide-41
SLIDE 41

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Efficient monitoring with MarQ

  • Obviously for online monitoring overhead and interference are

very important

  • For offline monitoring we still need practically efficient trace

processing

  • MarQ achieves efficient monitoring in three ways
  • Indexing
  • Redundancy elimination
  • Structural specialisation
  • We give a flavour of these techniques here
slide-42
SLIDE 42

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Indexing

  • The monitor needs to track the status of different valuations
  • f quantified variables
  • Given an event it needs to quickly find what needs to be
  • updated. This is the indexing problem.
  • MarQ uses symbol-based indexing

m,c m,c m,c,i m,c,i m,c,i

slide-43
SLIDE 43

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Indexing

  • MarQ uses symbol-based indexing

m,c m,c m,c,i m,c,i m,c,i m=M1,c=C1 create(M1,C1) iterator(C1, ) update(M1) use( ) m=M1,c=C1,i=I1 create(M1,C1) iterator(C1,I1) update(M1) use(I1)

slide-44
SLIDE 44

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Indexing

  • MarQ uses symbol-based indexing

m,c m,c m,c,i m,c,i m,c,i m=M1,c=C1 create(M1,C1) iterator(C1, ) update(M1) use( ) m=M1,c=C1,i=I1 create(M1,C1) iterator(C1,I1) update(M1) use(I1)

slide-45
SLIDE 45

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Indexing

  • MarQ uses symbol-based indexing

m,c m,c m,c,i m,c,i m,c,i create(M1,C1) iterator(C1, ) iterator(C1,I1) update(M1) use( ) use(I1)

slide-46
SLIDE 46

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Indexing

  • MarQ uses symbol-based indexing

m,c m,c m,c,i m,c,i m,c,i create(M1,C1) iterator(C1, ) iterator(C1,I1) update(M1) use( ) use(I1) On receiving update(M1)

slide-47
SLIDE 47

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Indexing

  • MarQ uses symbol-based indexing

m,c m,c m,c,i m,c,i m,c,i create(M1,C1) iterator(C1, ) iterator(C1,I1) update(M1) use( ) use(I1) On receiving update(M1)

slide-48
SLIDE 48

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Indexing

  • MarQ uses symbol-based indexing

m,c m,c m,c,i m,c,i m,c,i create(M1,C1) iterator(C1, ) iterator(C1,I1) update(M1) use( ) use(I1) On receiving update(M1)

slide-49
SLIDE 49

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Indexing

  • MarQ uses symbol-based indexing

m,c m,c m,c,i m,c,i m,c,i create(M1,C1) iterator(C1, ) iterator(C1,I1) update(M1) use( ) use(I1) On receiving iterator(C1,I2)

slide-50
SLIDE 50

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Indexing

  • MarQ uses symbol-based indexing

m,c m,c m,c,i m,c,i m,c,i create(M1,C1) iterator(C1, ) iterator(C1,I1) update(M1) use( ) use(I1) On receiving iterator(C1,I2)

slide-51
SLIDE 51

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Indexing

  • MarQ uses symbol-based indexing

m,c m,c m,c,i m,c,i m,c,i create(M1,C1) iterator(C1, ) iterator(C1,I1) update(M1) use( ) use(I1) On receiving iterator(C1,I2)

slide-52
SLIDE 52

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Indexing

  • MarQ uses symbol-based indexing

m,c m,c m,c,i m,c,i m,c,i create(M1,C1) iterator(C1, ) iterator(C1,I1) update(M1) use( ) use(I1) On receiving iterator(C1,I2)

slide-53
SLIDE 53

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Indexing

  • MarQ uses symbol-based indexing

m,c m,c m,c,i m,c,i m,c,i m,c,i create(M1,C1) iterator(C1, ) iterator(C1,I1) update(M1) use( ) use(I1) On receiving iterator(C1,I2)

slide-54
SLIDE 54

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Redundancy elimination

1 2 3 4 5 ¬∃m, ∃c, ∃i create(m,c) iterator(c,i) update(m) use(i)

  • Given this specification there are two observations
  • 1. A binding m=M,c=C does not need to be extended for use(I)

as this does not tell us anything new

  • 2. If a monitored object is garbage collected it can no longer

contribute to a failing trace slice

  • Generalising these gives us a theory of redundancy elimination

that ignores or removes bindings of quantified variables

slide-55
SLIDE 55

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Structural specialisation

  • Not all features of the QEA specification language are needed

for every specification i.e. non-determinism, free variables

  • However supporting these features makes the monitoring

algorithm more complex

  • Structural specialisation produces a monitoring algorithm

based on the structure of the specification using special data structures

  • Motivation: monitoring is the frequent repetition of the same

small bit of code

slide-56
SLIDE 56

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Results of the 1st compeititon on Runtime Verification Offline Track

slide-57
SLIDE 57

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Results of the 1st compeititon on Runtime Verification Java Track

slide-58
SLIDE 58

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Writing specifications with efficiency in mind

  • Efficiency of the monitoring algorithm depends on the

structure of the specification

  • Therefore the way the specification is written matters
  • Can achieve an order of magnitude speedup by changing the

way the property is expressed

slide-59
SLIDE 59

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Outline

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

slide-60
SLIDE 60

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Separating specification and usage

slide-61
SLIDE 61

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Writing QEA specifications in MarQ

  • The QEA Builder uses an API to construct a QEA
  • The MonitorFactory constructs a monitor from that

specification

slide-62
SLIDE 62

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

The QEA Builder

QEABuilder q = new QEABuilder("safeiter"); int ITERATOR = 1; int NEXT = 2; final int i = -1; final int size = 1; q.addQuantification(FORALL, i) q.addTransition(1,ITERATOR, i, size, 2); q.addTransition(2,NEXT, i, isGreaterThanConstant(size,0), decrement(size), 2); q.addFinalStates(1, 2); q.setSkipStates(1); QEA qea = q.make();

slide-63
SLIDE 63

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

The QEA Builder

QEABuilder q = new QEABuilder("safeiter"); int ITERATOR = 1; int NEXT = 2; final int i = -1; final int size = 1; q.addQuantification(FORALL, i) q.addTransition(1,ITERATOR, i, size, 2); q.addTransition(2,NEXT, i, isGreaterThanConstant(size,0), decrement(size), 2); q.addFinalStates(1, 2); q.setSkipStates(1); QEA qea = q.make();

slide-64
SLIDE 64

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

The QEA Builder

QEABuilder q = new QEABuilder("safeiter"); int ITERATOR = 1; int NEXT = 2; final int i = -1; final int size = 1; q.addQuantification(FORALL, i) q.addTransition(1,ITERATOR, i, size, 2); q.addTransition(2,NEXT, i, isGreaterThanConstant(size,0), decrement(size), 2); q.addFinalStates(1, 2); q.setSkipStates(1); QEA qea = q.make();

slide-65
SLIDE 65

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

The QEA Builder

QEABuilder q = new QEABuilder("safeiter"); int ITERATOR = 1; int NEXT = 2; final int i = -1; final int size = 1; q.addQuantification(FORALL, i) q.addTransition(1,ITERATOR, i, size, 2); q.addTransition(2,NEXT, i, isGreaterThanConstant(size,0), decrement(size), 2); q.addFinalStates(1, 2); q.setSkipStates(1); QEA qea = q.make();

slide-66
SLIDE 66

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

The QEA Builder

QEABuilder q = new QEABuilder("safeiter"); int ITERATOR = 1; int NEXT = 2; final int i = -1; final int size = 1; q.addQuantification(FORALL, i) q.addTransition(1,ITERATOR, i, size, 2); q.addTransition(2,NEXT, i, isGreaterThanConstant(size,0), decrement(size), 2); q.addFinalStates(1, 2); q.setSkipStates(1); QEA qea = q.make();

slide-67
SLIDE 67

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

The QEA Builder

QEABuilder q = new QEABuilder("safeiter"); int ITERATOR = 1; int NEXT = 2; final int i = -1; final int size = 1; q.addQuantification(FORALL, i) q.addTransition(1,ITERATOR, i, size, 2); q.addTransition(2,NEXT, i, isGreaterThanConstant(size,0), decrement(size), 2); q.addFinalStates(1, 2); q.setSkipStates(1); QEA qea = q.make();

slide-68
SLIDE 68

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

The QEA Builder

QEABuilder q = new QEABuilder("safeiter"); int ITERATOR = 1; int NEXT = 2; final int i = -1; final int size = 1; q.addQuantification(FORALL, i) q.addTransition(1,ITERATOR, i, size, 2); q.addTransition(2,NEXT, i, isGreaterThanConstant(size,0), decrement(size), 2); q.addFinalStates(1, 2); q.setSkipStates(1); QEA qea = q.make();

slide-69
SLIDE 69

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

The QEA Builder

QEABuilder q = new QEABuilder("safeiter"); int ITERATOR = 1; int NEXT = 2; final int i = -1; final int size = 1; q.addQuantification(FORALL, i) q.addTransition(1,ITERATOR, i, size, 2); q.addTransition(2,NEXT, i, isGreaterThanConstant(size,0), decrement(size), 2); q.addFinalStates(1, 2); q.setSkipStates(1); QEA qea = q.make();

slide-70
SLIDE 70

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

The QEA Builder

QEABuilder q = new QEABuilder("safeiter"); int ITERATOR = 1; int NEXT = 2; final int i = -1; final int size = 1; q.addQuantification(FORALL, i) q.addTransition(1,ITERATOR, i, size, 2); q.addTransition(2,NEXT, i, isGreaterThanConstant(size,0), decrement(size), 2); q.addFinalStates(1, 2); q.setSkipStates(1); QEA qea = q.make();

slide-71
SLIDE 71

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

The QEA Builder

QEABuilder q = new QEABuilder("safeiter"); int ITERATOR = 1; int NEXT = 2; final int i = -1; final int size = 1; q.addQuantification(FORALL, i) q.addTransition(1,ITERATOR, i, size, 2); q.addTransition(2,NEXT, i, isGreaterThanConstant(size,0), decrement(size), 2); q.addFinalStates(1, 2); q.setSkipStates(1); QEA qea = q.make();

slide-72
SLIDE 72

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

The Monitor Factory

public interface Monitor{ public Verdict step(int name, Object[] args); } Monitor monitor = MonitorFactory.create( qea, GarbageMode.LAZY, //Optional RestartMode.REMOVE); // Optional

  • A monitor is an object accepting events and producing verdicts
  • The factory will analyse the specification and produce the best

monitor it can (i.e. using structural specialisation)

  • Optional modes
  • Garbage: handling monitored objects that are garbage collected
  • Restart: what to do when a violation occurs
slide-73
SLIDE 73

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

The Monitor Factory

public interface Monitor{ public Verdict step(int name, Object[] args); } Monitor monitor = MonitorFactory.create( qea, GarbageMode.LAZY, //Optional RestartMode.REMOVE); // Optional

  • A monitor is an object accepting events and producing verdicts
  • The factory will analyse the specification and produce the best

monitor it can (i.e. using structural specialisation)

  • Optional modes
  • Garbage: handling monitored objects that are garbage collected
  • Restart: what to do when a violation occurs
slide-74
SLIDE 74

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

The Monitor Factory

public interface Monitor{ public Verdict step(int name, Object[] args); } Monitor monitor = MonitorFactory.create( qea, GarbageMode.LAZY, //Optional RestartMode.REMOVE); // Optional

  • A monitor is an object accepting events and producing verdicts
  • The factory will analyse the specification and produce the best

monitor it can (i.e. using structural specialisation)

  • Optional modes
  • Garbage: handling monitored objects that are garbage collected
  • Restart: what to do when a violation occurs
slide-75
SLIDE 75

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

The Monitor Factory

public interface Monitor{ public Verdict step(int name, Object[] args); } Monitor monitor = MonitorFactory.create( qea, GarbageMode.LAZY, //Optional RestartMode.REMOVE); // Optional

  • A monitor is an object accepting events and producing verdicts
  • The factory will analyse the specification and produce the best

monitor it can (i.e. using structural specialisation)

  • Optional modes
  • Garbage: handling monitored objects that are garbage collected
  • Restart: what to do when a violation occurs
slide-76
SLIDE 76

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Offline monitoring with MarQ

  • We first create a Translator object for the trace
  • Then using a QEA object and trace string we create a monitor
  • Finally we call monitor to get a result
slide-77
SLIDE 77

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Offline monitoring with MarQ

OfflineTranslator translator = new DefaultTranslator(‘‘a’’, ‘‘b’’,‘‘c’’); String trace = ‘‘trace_dir/trace.csv’’; QEA qea = builder.make(); CSVFileMonitor m = new CSVFileMonitor(trace_name, qea, translator); Verdict v = m.monitor();

  • We first create a Translator object for the trace
  • Then using a QEA object and trace string we create a monitor
  • Finally we call monitor to get a result
slide-78
SLIDE 78

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Offline monitoring with MarQ

OfflineTranslator translator = new DefaultTranslator(‘‘a’’, ‘‘b’’,‘‘c’’); String trace = ‘‘trace_dir/trace.csv’’; QEA qea = builder.make(); CSVFileMonitor m = new CSVFileMonitor(trace_name, qea, translator); Verdict v = m.monitor();

  • We first create a Translator object for the trace
  • Then using a QEA object and trace string we create a monitor
  • Finally we call monitor to get a result
slide-79
SLIDE 79

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Offline monitoring with MarQ

OfflineTranslator translator = new DefaultTranslator(‘‘a’’, ‘‘b’’,‘‘c’’); String trace = ‘‘trace_dir/trace.csv’’; QEA qea = builder.make(); CSVFileMonitor m = new CSVFileMonitor(trace_name, qea, translator); Verdict v = m.monitor();

  • We first create a Translator object for the trace
  • Then using a QEA object and trace string we create a monitor
  • Finally we call monitor to get a result
slide-80
SLIDE 80

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Offline monitoring with MarQ

OfflineTranslator translator = new DefaultTranslator(‘‘a’’, ‘‘b’’,‘‘c’’); String trace = ‘‘trace_dir/trace.csv’’; QEA qea = builder.make(); CSVFileMonitor m = new CSVFileMonitor(trace_name, qea, translator); Verdict v = m.monitor();

  • We first create a Translator object for the trace
  • Then using a QEA object and trace string we create a monitor
  • Finally we call monitor to get a result
slide-81
SLIDE 81

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Trace formats

  • We support three trace formats proposed by the RV

competition

  • CSV
  • JSON
  • XML
  • We also provide tools for translating between formats
  • Parsing is surprisingly important.
  • MarQ has an optimised parser for the CSV format
  • Also aparallel option that separates trace processing and

monitoring.

  • Parsers produce abstract event objects handled by translators

before being passed to the monitor

slide-82
SLIDE 82

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Translators

  • Translators map abstract events to monitor step calls
  • They tackle three pragmatic issues
  • 1. Name mappings
  • Map between event names used in the trace and specification
  • May not be one-to-one
  • 2. Reordering parameters
  • The events recorded in the trace may not have the same

structure as in the specification

  • Parameters may be reordered or removed
  • 3. Interpreting values
  • Data values in events may need to be treated semantically
  • i.e. parsing into integers
  • May need to ensure values are interned
slide-83
SLIDE 83

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Online monitoring with MarQ

  • Currently MarQ supports monitoring Java programs via

AspectJ

  • Instrumentation should handle verdicts
  • However, we do not yet automatically generate AspectJ
  • This is work in process, along with targetting other languages
slide-84
SLIDE 84

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Instrumentation with AspectJ

public aspect SafeIterAspect { private int ITERATOR = 1; private int NEXT = 2; private Monitor monitor; SafeIterAspect(){ QEA qea = SafeIter.get(); monitor = MonitorFactory.create(qea); } ...

slide-85
SLIDE 85

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Instrumentation with AspectJ

public aspect SafeIterAspect { private int ITERATOR = 1; private int NEXT = 2; private Monitor monitor; SafeIterAspect(){ QEA qea = SafeIter.get(); monitor = MonitorFactory.create(qea); } ...

slide-86
SLIDE 86

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Instrumentation with AspectJ

pointcut iter(Collection c) : (call(Iterator Collection+.iterator()) && target(c)); pointcut next(Iterator i) : (call(* Iterator.next()) && target(i)); after (Collection c) returning (Iterator i) : iter(c) { synchronized(monitor){ check(monitor.step(ITERATOR,i,c.size())); } } before(Iterator i) : next(i) { synchronized(monitor){ check(monitor.step(NEXT,i)); } }

slide-87
SLIDE 87

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Instrumentation with AspectJ

pointcut iter(Collection c) : (call(Iterator Collection+.iterator()) && target(c)); pointcut next(Iterator i) : (call(* Iterator.next()) && target(i)); after (Collection c) returning (Iterator i) : iter(c) { synchronized(monitor){ check(monitor.step(ITERATOR,i,c.size())); } } before(Iterator i) : next(i) { synchronized(monitor){ check(monitor.step(NEXT,i)); } }

slide-88
SLIDE 88

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Instrumentation with AspectJ

pointcut iter(Collection c) : (call(Iterator Collection+.iterator()) && target(c)); pointcut next(Iterator i) : (call(* Iterator.next()) && target(i)); after (Collection c) returning (Iterator i) : iter(c) { synchronized(monitor){ check(monitor.step(ITERATOR,i,c.size())); } } before(Iterator i) : next(i) { synchronized(monitor){ check(monitor.step(NEXT,i)); } }

slide-89
SLIDE 89

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Instrumentation with AspectJ

pointcut iter(Collection c) : (call(Iterator Collection+.iterator()) && target(c)); pointcut next(Iterator i) : (call(* Iterator.next()) && target(i)); after (Collection c) returning (Iterator i) : iter(c) { synchronized(monitor){ check(monitor.step(ITERATOR,i,c.size())); } } before(Iterator i) : next(i) { synchronized(monitor){ check(monitor.step(NEXT,i)); } }

slide-90
SLIDE 90

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Instrumentation with AspectJ

pointcut iter(Collection c) : (call(Iterator Collection+.iterator()) && target(c)); pointcut next(Iterator i) : (call(* Iterator.next()) && target(i)); after (Collection c) returning (Iterator i) : iter(c) { synchronized(monitor){ check(monitor.step(ITERATOR,i,c.size())); } } before(Iterator i) : next(i) { synchronized(monitor){ check(monitor.step(NEXT,i)); } }

slide-91
SLIDE 91

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Instrumentation with AspectJ

... private void check(Verdict verdict){ if(verdict==Verdict.FAILURE){ <report error here> } } }

slide-92
SLIDE 92

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Future work

  • External specification language
  • Automated generation of instrumentation code
  • Transformations from other Runtime Monitoring specification

languages into QEA i.e. temporal logics, rule-based systems

  • Automated transformations into syntactic classes with better

efficiency guarantees

  • Violation explanation
slide-93
SLIDE 93

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

And finally...

  • The tool is available online

https://github.com/selig/qea

  • Thanks for listening
slide-94
SLIDE 94

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Non-determinism

1 2 3 ∀u∀t withdraw(u, a, t) a≤10k

s:=a

withdraw(u, a, t2) s+a≤10k

s+=a

withdraw(u, a, t2) t2−t>28 1 2 3 ¬∃u withdraw(u, a, t) withdraw(u, a, t) a≤10k

s:=a

withdraw(u, a, t2) t2−t≤28 ∧ s+a≤10k

s+=a

withdraw(u, a, t2) t2−t≤28 ∧ s+a>10k

  • By introducing non-determinism we can remove a quantifier
  • The idea is to have a path through the automata for each t
  • There is a trade-off between complexity in quantification and

non-determinism

slide-95
SLIDE 95

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Counting

1 2 ∀s ∀o add(s, o) h:=o.hashCode() remove(s, o) h=o.hashCode()

  • bserve(s, o) h=o.hashCode(),

add(s, o) h=o.hashCode() 1 2 ∀o add(o) h:=o.hashCode();c:=1 remove(o) h=o.hashCode()∧c=0

  • bserve(o) h=o.hashCode(),

add(o) h=o.hashCode()

c:=c+1

, remove(o) h=o.hashCode()∧c>0

c:=c−1

  • By making certain assumptions about how trace slices for a

quantifier are related we can track instances with a counter

  • Transformation needs more information than is in the

specification

slide-96
SLIDE 96

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Quantifier stripping

1 2 3 ∀p∃s send(p, s) reply(s, p) 1 2 3 ∀p send(p, s) reply(s, p)

  • Existential quantifiers on the right can be stripped
  • This is a trivial case, more complex cases involve the

introduction of guards and non-determinism

slide-97
SLIDE 97

Runtime Monitoring Quantified Event Automata Efficient monitoring Using MarQ

Big impact

Property Trace length Runtime (milliseconds) Speedup Original Translated withdrawal 150k 3,050 2,106 1.44 persistenthash 4M 12,267 864 14.12 publishers 200k 355 37 9.59

  • Can achieve an order of magnitude speedup
  • A phenomenon not often talked about in RV papers
  • Further work: automate these transformations