D trace kde4presentation

28
Dynamically Tracing KDE Manish Chakravarty ThoughtWorks Studios 1

Transcript of D trace kde4presentation

Page 1: D trace kde4presentation

Dynamically TracingKDE

Manish ChakravartyThoughtWorks Studios

1

Page 2: D trace kde4presentation

Agenda

• Learn about DTrace

• Learn what and where to Trace

• Trace!

2

Page 3: D trace kde4presentation

I. What is DTrace?

While I go through the slides, please start copying the VM!

3

Page 4: D trace kde4presentation

DTrace is..

• a comprehensive Dynamic Tracing framework created by Sun Microsystems for troubleshooting kernel and application problems in real time.

4

Page 5: D trace kde4presentation

Excuse me?

5

Page 6: D trace kde4presentation

• Dtrace enables us to “look into” the internals of a running production application and allows us to instrument it

• It can do very neat stuff in the kernel as well, but that’s not the point of this session

6

Page 7: D trace kde4presentation

So how does DTrace work?

7

Page 8: D trace kde4presentation

• Dtrace allows you to dynamically modify the operating system kernel and user processes to record additional data that you specify at locations of interest, called probes

8

Page 9: D trace kde4presentation

• Dtrace probes come from a set of kernel modules called providers, each of which performs a particular type of instrumentation to create probes

9

Page 10: D trace kde4presentation

Provider:Module:Function:Name

10

Page 11: D trace kde4presentation

ProviderThe name of the DTrace provider that is publishing this

probe

11

Page 12: D trace kde4presentation

ModuleIf this probe corresponds to a specific program

location, the name of the module which the probe is located

The name is either the name of a kernel module or a user library

12

Page 13: D trace kde4presentation

FunctionIf this probe corresponds to a specific program

location, the name of the program function in which the probe is located

13

Page 14: D trace kde4presentation

NameThe final component of the probe name is a name that gives you some idea of the probe’s semantic meaning

such as BEGIN or END

14

Page 15: D trace kde4presentation

Thus:Provider:Module:Function:Name

15

Page 16: D trace kde4presentation

DTrace Architecture16

Page 17: D trace kde4presentation

Let’s start Tracing!

17

Page 18: D trace kde4presentation

manish@belenix-KDE4:~/WorkOut/DTraceTutorial$ pfexec dtrace -n BEGIN

dtrace: description 'BEGIN' matched 1 probe

CPU ID FUNCTION:NAME

0 1 :BEGIN

^C

18

Page 19: D trace kde4presentation

manish@belenix-KDE4:~/WorkOut/DTraceTutorial$ pfexec dtrace -n BEGIN -n END

dtrace: description 'BEGIN' matched 1 probe

dtrace: description 'END' matched 1 probe

CPU ID FUNCTION:NAME

0 1 :BEGIN

^C

0 2 :END 19

Page 20: D trace kde4presentation

• The probe BEGIN fires every time you start a new tracing request

• The probe END fires every time you exit DTrace. In this case hitting Ctrl-C triggered it.

20

Page 21: D trace kde4presentation

Hello, World!

21

Page 22: D trace kde4presentation

BEGIN

{

trace("hello, world");

exit(0);

}

22

Page 23: D trace kde4presentation

manish@belenix-KDE4:~/WorkOut/DTraceTutorial/1-HelloWorld$ pfexec dtrace -s hello.d

dtrace: script 'hello.d' matched 1 probe

CPU ID FUNCTION:NAME

0 1 :BEGIN hello, world

Output..

23

Page 24: D trace kde4presentation

61,809DTrace probes on the system!

pfexec dtrace -l | wc -l

24

Page 25: D trace kde4presentation

DTrace ArchitectureSource: http://wikis.sun.com/download/attachments/10390716/architecture.gif

25

Page 26: D trace kde4presentation

II. What / Where / How

26

Page 27: D trace kde4presentation

• Navigate to the directory having the Qt source code

• Find out a good place in QObject to put one

• Start writing probes!

27

Page 28: D trace kde4presentation

Hack!

28