Anatomy of a DSL project in an industrial · PDF fileUsed many Java/Eclipse modeling...

14
Anatomy of a domain-specific language Anatomy of a domain specific language project in an industrial context Development and examination of a DSL demonstrator for elevator controllers Christoph Wienands & Michael Golm Software Engineering Architecture and Platform Technologies Copyright © Siemens AG 2009. All rights reserved Software Engineering, Architecture and Platform Technologies Siemens Corporate Research, Princeton, NJ

Transcript of Anatomy of a DSL project in an industrial · PDF fileUsed many Java/Eclipse modeling...

Page 1: Anatomy of a DSL project in an industrial · PDF fileUsed many Java/Eclipse modeling technologies toUsed many Java ... previous findings that DSLs increase ... Anatomy of a DSL project

Anatomy of a domain-specific languageAnatomy of a domain specific language project in an industrial contextDevelopment and examination of a DSL demonstrator for elevator controllers

Christoph Wienands & Michael GolmSoftware Engineering Architecture and Platform Technologies

Copyright © Siemens AG 2009. All rights reserved

Software Engineering, Architecture and Platform TechnologiesSiemens Corporate Research, Princeton, NJ

Page 2: Anatomy of a DSL project in an industrial · PDF fileUsed many Java/Eclipse modeling technologies toUsed many Java ... previous findings that DSLs increase ... Anatomy of a DSL project

OverviewOverview

Motivation and goalsElevator controllers as research subjectDomain analysisInception of new, abstract domain conceptsDSL Tooling ArchitectureMeta-modelEncountered challengesEncountered challengesSupport for another target platform (C) and code generator optimizationCollected metrics

Copyright © Siemens AG 2009. All rights reserved

10/8/2009Page 2 Christoph Wienands & Michael Golm

Page 3: Anatomy of a DSL project in an industrial · PDF fileUsed many Java/Eclipse modeling technologies toUsed many Java ... previous findings that DSLs increase ... Anatomy of a DSL project

Background of DSL project for elevator controllersBackground of DSL project for elevator controllers

Motivation GoalsIntroduction of DSLs intoorganizations is difficult.

Learning curve

Gain more experience building DSL, especially using Eclipse GMF.

Language and model evolutionInitial investment high

Development of visual DSLs

Collect metrics throughout development and evaluate them.Examine challenge of generation

typically labor-intensive task.Limited experience of DSL authorsDifficulties finding appropriate visual

t ti

of performant code.Develop a fully documented,easy-to-understand,

bli h bl DSL d t l h irepresentationsComplexity: Multi-diagram DSLs, constraints, customization,visual-text hybrids

publishable DSL and tool chain for research purposes and as a showcase.

Copyright © Siemens AG 2009. All rights reserved

visual text hybridsGenerated code said to perform poorly.

10/8/2009Page 3 Christoph Wienands & Michael Golm

Page 4: Anatomy of a DSL project in an industrial · PDF fileUsed many Java/Eclipse modeling technologies toUsed many Java ... previous findings that DSLs increase ... Anatomy of a DSL project

Elevator controllers – Research subject for DSLsElevator controllers Research subject for DSLs

Elevators are grouped in elevator banksHigh-level control consists of: Opening/closing doors, accelerating/decelerating individual cars, and reacting to floor calls/car calls (buttons pressed inside

d t id flcars and outside on floors.Floor calls require the concept of committed direction: The direction an elevator car will continue in after

i d l i th d t th t topening and closing the doors at the next stop.Support for multiple special modes: Maintenance, fire-fighter mode, etc.

Elevator controller domain is non-trivial and provides enough variability to justify the development of a DSL, yet it is strictly scoped.

Copyright © Siemens AG 2009. All rights reserved

DSL, yet it is strictly scoped.

10/8/2009Page 4 Christoph Wienands & Michael Golm

Page 5: Anatomy of a DSL project in an industrial · PDF fileUsed many Java/Eclipse modeling technologies toUsed many Java ... previous findings that DSLs increase ... Anatomy of a DSL project

Domain analysis of elevator controllersDomain analysis of elevator controllers

Elevator controller functionality is separated into:C b h i h d ll t llCommon behavior shared across all controllers

Accelerating / decelerating to reach target floorClosing of doors: Closing delay, reopen if obstruction detectedR l i f d b tt hi t t flReleasing of pressed buttons upon reaching target floor

Variable, mode-specific behavior:Determining next target floorS fSetting of committed directionDecision to open doors (only if stopped)

Common behavior is mostly safety-critical and will not be part of theCommon behavior is mostly safety-critical and will not be part of the modeling language.Actions strongly depend on state of elevator components and events from subsystem

Copyright © Siemens AG 2009. All rights reserved

from subsystem.Modeling language based on state machines seems most suited.

10/8/2009Page 5 Christoph Wienands SCR / SE / APT

Page 6: Anatomy of a DSL project in an industrial · PDF fileUsed many Java/Eclipse modeling technologies toUsed many Java ... previous findings that DSLs increase ... Anatomy of a DSL project

Advanced domain concepts in elevator controller DSL

Call List Projection Example “CallsAhead – SameDirection”

Advanced domain concepts in elevator controller DSL

2 named call listsDynamic lists providing trigger events

7 Four personswaiting on floors

6

Dynamic lists providing trigger events 'Added' and 'Removed' to state machine transitionsElevator calls: Buttons pressed inside carA i d fl ll A i d b ti 6

One passenger5 in car, target floor 6

4 Elevator speed 15ft/s

Assigned floor calls: Assigned by runtime

Call list projectionsDynamic filter queries.Filter configurations: Calls ahead calls 4 Elevator speed 15ft/s,

next possible stop 43

Filter configurations: Calls ahead, calls behind, all calls, same direction, opposite direction.Filter result depends on current position,

d l ti d itt d 2

1

speed, acceleration and committed direction.Can combine calls from ElevatorCalls and AssignedFloorCalls.

Copyright © Siemens AG 2009. All rights reserved

Result of call list projection query: 4, 6

`

Provide events just like underlying call lists.

10/12/2009Page 6 Michael Golm & Christoph Wienands SCR SE APT

Page 7: Anatomy of a DSL project in an industrial · PDF fileUsed many Java/Eclipse modeling technologies toUsed many Java ... previous findings that DSLs increase ... Anatomy of a DSL project

DSL Tooling ArchitectureDSL Tooling Architecture

Technology DescriptionGraphical Modeling Framework (GMF) Eclipse-based workbench for visual DSLsp g ( ) p

Eclipse Modeling Framework (EMF) Underlying (meta) model library

Graphical Editing Framework (GEF) Underlying library for editors

J E itt T l t (JET) C d ti d l t t tJava Emitter Templates (JET) Code generation, model-to-text

openArchitectureWare Xtext Parser for mini scripting language

openArchitectureWare Xpand Code generation for scripting language

JET Transformation Simulator

1 65

Model

Elevator ScriptParser

Elevator ScriptGenerator

Controller4

2

Copyright © Siemens AG 2009. All rights reserved

10/8/2009Page 7 Christoph Wienands & Michael Golm

Parser Generator3

Action/condition script

Page 8: Anatomy of a DSL project in an industrial · PDF fileUsed many Java/Eclipse modeling technologies toUsed many Java ... previous findings that DSLs increase ... Anatomy of a DSL project

Meta-modelMeta model

Copyright © Siemens AG 2009. All rights reserved

10/8/2009Page 8 Christoph Wienands & Michael Golm

Page 9: Anatomy of a DSL project in an industrial · PDF fileUsed many Java/Eclipse modeling technologies toUsed many Java ... previous findings that DSLs increase ... Anatomy of a DSL project

Example of ‘Up-Only’ elevator controllerExample of Up Only elevator controller

Call lists

Call list projections

State machine

Conditions

Copyright © Siemens AG 2009. All rights reserved

10/8/2009Page 9 Christoph Wienands & Michael Golm

Conditions Actions

Page 10: Anatomy of a DSL project in an industrial · PDF fileUsed many Java/Eclipse modeling technologies toUsed many Java ... previous findings that DSLs increase ... Anatomy of a DSL project

Encountered challengesEncountered challenges

Steep learning curve for GMF.Implementing an efficient concrete syntax:

Weak support for decomposition (subdiagram of different type) in GMFComplexity of mapping ecore meta model to concrete syntax due to EMF f ( ff)flexibility (trade-off)

Customization of DSL editor:Implemented customizations

Read-only, calculated attributePropagate attribute and reference change notificationsInitialize model graphs and prepopulate diagrams upon creationContext menuIntegration visual DSL and textual scripting language

Most customizations needed to be done manually by modifying or l ti t d d Littl t l t

Copyright © Siemens AG 2009. All rights reserved

supplementing generated code. Little tool support.

10/8/2009Page 10 Christoph Wienands & Michael Golm

Page 11: Anatomy of a DSL project in an industrial · PDF fileUsed many Java/Eclipse modeling technologies toUsed many Java ... previous findings that DSLs increase ... Anatomy of a DSL project

Support for alternative C platform:Optimizations performed by code generatorOptimizations performed by code generator

Statically allocated arraysConstant memory footprint

double* m_ElevatorSpeed;m_ElevatorSpeed = new double[m_ElevatorCount];

Constant memory footprint

Statically linked event chainsN t h O ti i d filt

void tick() {… elevatorCallsAdded(i, j); …

}

Not shown: Optimized filter queries for call list projectionsPerformant execution oft t hi

void elevatorCallsAdded(int elevator, int floor) {… elevatorCallsAheadAdded(elevator, floor); …

}

void elevatorCallsAheadAdded(int elevator, int floor) {state machine {

… if (m_State[elevator] == STATE_MOVING &&movingCallsAheadAdded4Condition(elevator)) {movingCallsAheadAdded4Action(elevator);

} …}

Conditional exclusion ofstatus updatesFaster execution for

}

for (int i = 0; i < m_ElevatorCount; i++) {#ifdef STATUS_SPEED

m_ElevatorSpeed[i] = m_Sim->getElevatorSpeed(i);

Copyright © Siemens AG 2009. All rights reserved

simple controllers_ _

#endif}

10/8/2009Page 11 Christoph Wienands SCR / SE / APT

Page 12: Anatomy of a DSL project in an industrial · PDF fileUsed many Java/Eclipse modeling technologies toUsed many Java ... previous findings that DSLs increase ... Anatomy of a DSL project

Some Collected MetricsSome Collected Metrics

Development method Effort expert (hours) Effort novice (hours)

Effort for creation of a elevator controller by domain expert vs. domain novice

Using Elevator DSL (therefore works onboth target platforms)

1.0 5.0

Manually developed against C domainframework

1.5 -

Manually developed for C platform (no 4.0 8.0+ (out of time, believed toManually developed for C platform (no domain framework)

4.0 8.0 (out of time, believed tobe at least 12h until complete)

Metric DSL-based controller Manually dev. controller

Efficiency of generated code

Static analysisLOC 791 domain framework

+ 462 generated controller= 1253 total

508 controller

Binary size 56kB 40kBBinary size 56kB 40kBImplementation effort 4 call list projections,

5 states, 13 transitions and 29 lines of TSL script (conditions, actions)

508 lines of C code

R ti l i

Copyright © Siemens AG 2009. All rights reserved

Runtime analysisAvg. instructions/cycle 184 223

10/8/2009Page 12 Christoph Wienands SCR / SE / APT

Page 13: Anatomy of a DSL project in an industrial · PDF fileUsed many Java/Eclipse modeling technologies toUsed many Java ... previous findings that DSLs increase ... Anatomy of a DSL project

Conclusion and future workConclusion and future work

FindingsD i l i d t t i i ld d t d iDomain analysis and prototyping yielded two domain concepts not found in existing elevator controllers

raising level of abstraction for users.Used many Java/Eclipse modeling technologies toUsed many Java/Eclipse modeling technologies to create user-friendly DSL

additional experienceQuantitative analysis of collected metrics support previous findings that DSLs increase productivity.

Future workPort DSL to other visual DSL workbenches for comparisonExtend DSL to support modeling call distribution algorithms across elevator bank

Copyright © Siemens AG 2009. All rights reserved

algorithms across elevator bank.

10/8/2009Page 13 Christoph Wienands SCR / SE / APT

Page 14: Anatomy of a DSL project in an industrial · PDF fileUsed many Java/Eclipse modeling technologies toUsed many Java ... previous findings that DSLs increase ... Anatomy of a DSL project

Thank you for your attentionThank you for your attention

Copyright © Siemens AG 2009. All rights reserved

Christoph [email protected]