Profiling Erlang Programs using Percept2

53
Profiling Erlang Programs using Percept2 Huiqing Li and Simon Thompson Erlang Factory Lite, London 8 November 2012

Transcript of Profiling Erlang Programs using Percept2

Page 1: Profiling Erlang Programs using Percept2

Profiling Erlang Programs using Percept2

Huiqing Li and Simon ThompsonErlang Factory Lite, London

8 November 2012

Page 2: Profiling Erlang Programs using Percept2

Overview

• Erlang multicore … RELEASE

• Percept … and Percept2

• Case study from Wrangler

• Conclusions

Page 3: Profiling Erlang Programs using Percept2

Erlang multicore

Page 4: Profiling Erlang Programs using Percept2

• Scalable distributed Erlang: systems and tools.

• Groups and implicit placement.

Page 5: Profiling Erlang Programs using Percept2

Tools

How to use these systems effectively?

Page 6: Profiling Erlang Programs using Percept2

Existing tools

• Erlang tracing

• Htop

• DTrace

• Percept

Page 7: Profiling Erlang Programs using Percept2

Percept

Page 8: Profiling Erlang Programs using Percept2

Percept

• Percept: Erlang concurrency profiling tool.

• In the Erlang/OTP distribution …

• … written by Björn-Egil Dahlberg.

• Monitors process runnability using erlang:trace/3, erlang:system_profile/2.

• Offline tool … ‘replay’ a computation.

Page 9: Profiling Erlang Programs using Percept2

Percept facilities

• Histogram of active processes vs. time.

• ‘Drill down’ to process information via Pid.

• Start/end time, parent/child processes, time spent waiting for messages, … .

• View individual process runnability.

Page 10: Profiling Erlang Programs using Percept2

Percept

Page 11: Profiling Erlang Programs using Percept2

Percept to Percept2

• Concurrency, but multicore is ‘invisible’.

• Run queue migration,

• Analysis

• Runnable vs running.

• Presentation of information

• Clarify / colour.

Page 12: Profiling Erlang Programs using Percept2

• Parallelisation

• Dynamic callgraph information.

• Scalability of the system.

• Usability (process tree)

• Parallel processing

Percept to Percept2

Page 13: Profiling Erlang Programs using Percept2

Percept2

Page 14: Profiling Erlang Programs using Percept2

Functionality

Page 15: Profiling Erlang Programs using Percept2

Scheduler activityThe number of schedulers active at any time

Page 16: Profiling Erlang Programs using Percept2

Process info treeProcess info presented in expandable tree format.

Page 17: Profiling Erlang Programs using Percept2

Process migrationMigration history of process b/w run queues

Page 18: Profiling Erlang Programs using Percept2

Message passing statsNo. of msgs, and average msg size, sent / received.

Page 19: Profiling Erlang Programs using Percept2

Information aggregation

Page 20: Profiling Erlang Programs using Percept2

Process tree

Parent-child relationships between processes.

Page 21: Profiling Erlang Programs using Percept2

Dynamic function infoCall relationships b/w fns during the program run, and number of calls.

Page 22: Profiling Erlang Programs using Percept2

Accumulated runtimeAccumulated time during which a function within this process is in a running state.

Page 23: Profiling Erlang Programs using Percept2

Process activity

Page 24: Profiling Erlang Programs using Percept2

Scalability

Page 25: Profiling Erlang Programs using Percept2

Compression

Page 26: Profiling Erlang Programs using Percept2

Parallelise

• Parallelise Percept itself.

• Multiple log files …

• … that can be processed in parallel …

• … and integrated into a single result.

Page 27: Profiling Erlang Programs using Percept2

Distribution

Page 28: Profiling Erlang Programs using Percept2
Page 29: Profiling Erlang Programs using Percept2

Case study

Page 30: Profiling Erlang Programs using Percept2

Clone detection in Wrangler

flatten trees

identify candidates

parse files

check candidates

Page 31: Profiling Erlang Programs using Percept2

Active Processes

Page 32: Profiling Erlang Programs using Percept2

Processes

Page 33: Profiling Erlang Programs using Percept2

Process activity

Page 34: Profiling Erlang Programs using Percept2

Critical process

Page 35: Profiling Erlang Programs using Percept2

Active functions

Page 36: Profiling Erlang Programs using Percept2

Callgraph timeslice

Page 37: Profiling Erlang Programs using Percept2

[generalise_and_hash_file_ast_1( File, Threshold, ASTPid, true,SearchPaths, TabWidth) ||File<-Files].

para_lib:pmap( fun(File) -> generalise_and_hash_file_ast_1( File, Threshold, ASTPid, true, SearchPaths, TabWidth) end, Files).

Refactoring #1

Page 38: Profiling Erlang Programs using Percept2

Active Processes

Page 39: Profiling Erlang Programs using Percept2

Processes

Page 40: Profiling Erlang Programs using Percept2

Callgraph

Page 41: Profiling Erlang Programs using Percept2

lists:foreach(fun (Form) -> F(Form) end, Forms).

para_lib:pforeach(fun (Form) -> F(Form) end, Forms, 5).

Refactoring #2

Page 42: Profiling Erlang Programs using Percept2

Active Processes

Page 43: Profiling Erlang Programs using Percept2

Processes

Page 44: Profiling Erlang Programs using Percept2

Callgraph

Page 45: Profiling Erlang Programs using Percept2

examine_clone_candidates([],_Thresholds,CloneCheckerPid,_Num) -> get_final_clone_classes(CloneCheckerPid);examine_clone_candidates([C|Cs],Thresholds,CloneCheckerPid,Num) -> output_progress_msg(Num), C1 = get_clone_in_range(C), NewClones=examine_a_clone_candidate(C1,Thresholds), add_new_clones(CloneCheckerPid,{C1, NewClones}), examine_clone_candidates(Cs,Thresholds,CloneCheckerPid,Num+1).

examine_clone_candidates(Cs, Thresholds, CloneCheckerPid) -> NumberedCs = lists:zip(Cs, lists:seq(1, length(Cs))), para_lib:pforeach( fun({C, Nth}) -> examine_a_clone_candidate( {C,Nth},Thresholds,CloneCheckerPid) end,NumberedCs), get_final_clone_classes(CloneCheckerPid).

examine_a_clone_candidate({C,_Nth},Thresholds,CloneCheckerPid) -> output_progress_msg(Nth), C1 = get_clone_in_range(C), NewClones=examine_a_clone_candidate(C1,Thresholds), add_new_clones(CloneCheckerPid,{C1,NewClones}).

Refactoring #3

Page 46: Profiling Erlang Programs using Percept2

Active Processes

Page 47: Profiling Erlang Programs using Percept2

flatten trees

identify candidates

parse files

check candidates

parse filesparse files

flatten treesflatten trees

check candidates

check candidates

Parallel clone detection in Wrangler

Page 48: Profiling Erlang Programs using Percept2
Page 49: Profiling Erlang Programs using Percept2
Page 50: Profiling Erlang Programs using Percept2

Next steps

• Looking at the front end … HTML5 version.

• Online SD Erlang Profiling

• Refactoring Tools

Page 51: Profiling Erlang Programs using Percept2

• Dialyzer parallelisation at Uppsala … 

• … paper in Erlang Workshop 2012.

• BenchErl: benchmarking

• Extended tracing in Erlang and DTrace.

Page 52: Profiling Erlang Programs using Percept2

Conclusions

• RELEASE project.

• Tool to support scalable parallelisation.

• SD Erlang release and tools in 2013.

• Thanks to the percept team!

Page 53: Profiling Erlang Programs using Percept2

Get involved!

git://github.com/huiqing/percept2.git