1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
|
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
<!ENTITY % defs SYSTEM "/xserver/doc/xml/xserver.ent"> %defs;
]>
<article id="Xserver-DTrace">
<articleinfo>
<title>Xserver Provider for DTrace</title>
<author>
<firstname>Alan</firstname><surname>Coopersmith</surname>
<affiliation>
<orgname>Oracle Corporation</orgname>
<orgdiv>Solaris Engineering</orgdiv>
</affiliation>
</author>
<releaseinfo>X Server Version &xserver.version;</releaseinfo>
<copyright><year>2005</year><year>2006</year><year>2007</year><year>2010</year>
<holder>Oracle and/or its affiliates. All rights reserved.</holder>
</copyright>
<legalnotice id="copyright">
<para>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
</para><para>
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
</para><para>
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</para>
</legalnotice>
</articleinfo>
<sect1 id="introduction">
<title>Introduction</title>
<para>
This page provides details on a
<ulink url="http://wikis.sun.com/display/DTrace/Statically+Defined+Tracing+for+User+Applications">statically defined user application tracing provider</ulink>
for the
<ulink url="http://hub.opensolaris.org/bin/view/Community+Group+dtrace/">DTrace</ulink>
facility in <productname>Solaris</productname> 10,
<productname>MacOS X</productname> 10.5, and later releases. This
provider instruments various points in the X server, to allow
tracing what client applications are up to. DTrace probes may be used
with <ulink url="http://sourceware.org/systemtap/">SystemTap</ulink>
on GNU/Linux systems.
</para>
<para>
The provider was integrated into the X.Org git master repository
with Solaris 10 & OpenSolaris support for the Xserver 1.4 release,
released in 2007 with X11R7.3. Support for DTrace on MacOS X
was added in Xserver 1.7.
</para>
<para>
These probes expose the request and reply structure of the X protocol
between clients and the X server, so an understanding of that basic
nature will aid in learning how to use these probes.
</para>
</sect1>
<sect1 id="probes">
<title>Available probes</title>
<para>
Due to the way User-Defined DTrace probes work, arguments to
these probes all bear undistinguished names of
<parameter>arg0</parameter>, <parameter>arg1</parameter>,
<parameter>arg2</parameter>, etc. These tables should help you
determine what the real data is for each of the probe arguments.
<table id="Probes_and_their_arguments">
<title>Probes and their arguments</title>
<tgroup cols='9'>
<colspec colname="probe" colwidth="2*"/>
<colspec colname="desc" colwidth="3*"/>
<colspec colname="arg0" colwidth="1*"/>
<colspec colname="arg1" colwidth="1*"/>
<colspec colname="arg2" colwidth="1*"/>
<colspec colname="arg3" colwidth="1*"/>
<colspec colname="arg4" colwidth="1*"/>
<colspec colname="arg5" colwidth="1*"/>
<colspec colname="arg6" colwidth="1*"/>
<spanspec spanname="all" namest="probe" nameend="arg4"/>
<thead>
<row>
<entry>Probe name</entry>
<entry>Description</entry>
<entry>arg0</entry>
<entry>arg1</entry>
<entry>arg2</entry>
<entry>arg3</entry>
<entry>arg4</entry>
<entry>arg5</entry>
<entry>arg6</entry>
</row>
</thead>
<tbody>
<row>
<entry spanname="all" class="grouphead">Request Probes</entry>
</row>
<row>
<entry>request-start</entry>
<entry>Called just before processing each client request.</entry>
<entry><parameter>requestName</parameter></entry>
<entry><parameter>requestCode</parameter></entry>
<entry><parameter>requestLength</parameter></entry>
<entry><parameter>clientId</parameter></entry>
<entry><parameter>requestBuffer</parameter></entry>
<entry nameend="arg5" class="unused"/>
<entry nameend="arg6" class="unused"/>
</row>
<row>
<entry>request-done</entry>
<entry>Called just after processing each client request.</entry>
<entry><parameter>requestName</parameter></entry>
<entry><parameter>requestCode</parameter></entry>
<entry><parameter>sequenceNumber</parameter></entry>
<entry><parameter>clientId</parameter></entry>
<entry><parameter>resultCode</parameter></entry>
<entry nameend="arg5" class="unused"/>
<entry nameend="arg6" class="unused"/>
</row>
<row>
<entry spanname="all" class="grouphead">Event Probes</entry>
</row>
<row>
<entry>send-event</entry>
<entry>Called just before send each event to a client.</entry>
<entry><parameter>clientId</parameter></entry>
<entry><parameter>eventCode</parameter></entry>
<entry><parameter>eventBuffer</parameter></entry>
<entry nameend="arg3" class="unused"/>
<entry nameend="arg4" class="unused"/>
<entry nameend="arg5" class="unused"/>
<entry nameend="arg6" class="unused"/>
</row>
<row>
<entry spanname="all" class="grouphead">Client Connection Probes</entry>
</row>
<row>
<entry>client-connect</entry>
<entry>Called when a new connection is opened from a client</entry>
<entry><parameter>clientId</parameter></entry>
<entry><parameter>clientFD</parameter></entry>
<entry nameend="arg2" class="unused"/>
<entry nameend="arg3" class="unused"/>
<entry nameend="arg4" class="unused"/>
<entry nameend="arg5" class="unused"/>
<entry nameend="arg6" class="unused"/>
</row>
<row>
<entry>client-auth</entry>
<entry>Called when client authenticates (normally just after connection opened)</entry>
<entry><parameter>clientId</parameter></entry>
<entry><parameter>clientAddr</parameter></entry>
<entry><parameter>clientPid</parameter></entry>
<entry><parameter>clientZoneId</parameter></entry>
<entry nameend="arg4" class="unused"/>
<entry nameend="arg5" class="unused"/>
<entry nameend="arg6" class="unused"/>
</row>
<row>
<entry>client-disconnect</entry>
<entry>Called when a client connection is closed</entry>
<entry><parameter>clientId</parameter></entry>
<entry nameend="arg1" class="unused"/>
<entry nameend="arg2" class="unused"/>
<entry nameend="arg3" class="unused"/>
<entry nameend="arg4" class="unused"/>
<entry nameend="arg5" class="unused"/>
<entry nameend="arg6" class="unused"/>
</row>
<row>
<entry spanname="all" class="grouphead">Resource Allocation Probes</entry>
</row>
<row>
<entry>resource-alloc</entry>
<entry>Called when a new resource (pixmap, gc, colormap, etc.) is allocated</entry>
<entry><parameter>resourceId</parameter></entry>
<entry><parameter>resourceTypeId</parameter></entry>
<entry><parameter>resourceValue</parameter></entry>
<entry><parameter>resourceTypeName</parameter></entry>
<entry nameend="arg4" class="unused"/>
<entry nameend="arg5" class="unused"/>
<entry nameend="arg6" class="unused"/>
</row>
<row>
<entry>resource-free</entry>
<entry>Called when a resource is freed</entry>
<entry><parameter>resourceId</parameter></entry>
<entry><parameter>resourceTypeId</parameter></entry>
<entry><parameter>resourceValue</parameter></entry>
<entry><parameter>resourceTypeName</parameter></entry>
<entry nameend="arg4" class="unused"/>
<entry nameend="arg5" class="unused"/>
<entry nameend="arg6" class="unused"/>
</row>
<row>
<entry spanname="all" class="grouphead">Input API probes</entry>
</row>
<row>
<entry>input-event</entry>
<entry>Called when an input event was submitted for processing</entry>
<entry><parameter>deviceid</parameter></entry>
<entry><parameter>eventtype</parameter></entry>
<entry><parameter>button</parameter> or
<parameter>keycode</parameter> or
<parameter>touchid</parameter></entry>
<entry><parameter>flags</parameter></entry>
<entry><parameter>nvalues</parameter></entry>
<entry><parameter>mask</parameter></entry>
<entry><parameter>values</parameter></entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</sect1>
<sect1 id="arguments">
<title>Data Available in Probe Arguments</title>
<para>
To access data in arguments of type <type>string</type>, you will need
to use <ulink url="http://wikis.sun.com/display/DTrace/Actions+and+Subroutines#ActionsandSubroutines-{{copyinstr}}"><function>copyinstr()</function></ulink>.
To access data buffers referenced via <type>uintptr_t</type>'s, you will
need to use <ulink url="http://wikis.sun.com/display/DTrace/Actions+and+Subroutines#ActionsandSubroutines-{{copyin}}"><function>copyin()</function></ulink>.
<table id="Probe_Arguments">
<title>Probe Arguments</title>
<tgroup cols='3'>
<colspec colname="arg" colwidth="2*"/>
<colspec colname="type" colwidth="1*"/>
<colspec colname="desc" colwidth="7*"/>
<thead>
<row>
<entry>Argument name</entry>
<entry>Type</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry><parameter>clientAddr</parameter></entry>
<entry><type>string</type></entry>
<entry>String representing address client connected from</entry>
</row>
<row>
<entry><parameter>clientFD</parameter></entry>
<entry><type>int</type></entry>
<entry>X server's file descriptor for server side of each connection</entry>
</row>
<row>
<entry><parameter>clientId</parameter></entry>
<entry><type>int</type></entry>
<entry>Unique integer identifier for each connection to the
X server</entry>
</row>
<row>
<entry><parameter>clientPid</parameter></entry>
<entry><type>pid_t</type></entry>
<entry>Process id of client, if connection is local
(from <function>getpeerucred()</function>)</entry>
</row>
<row>
<entry><parameter>clientZoneId</parameter></entry>
<entry><type>zoneid_t</type></entry>
<entry>Solaris: Zone id of client, if connection is local
(from <function>getpeerucred()</function>)</entry>
</row>
<row>
<entry><parameter>eventBuffer</parameter></entry>
<entry><type>uintptr_t</type></entry>
<entry>Pointer to buffer containing X event - decode using
structures in
<<ulink url="http://cgit.freedesktop.org/xorg/proto/xproto/tree/Xproto.h"><filename class="headerfile">X11/Xproto.h</filename></ulink>>
and similar headers for each extension</entry>
</row>
<row>
<entry><parameter>eventCode</parameter></entry>
<entry><type>uint8_t</type></entry>
<entry>Event number of X event</entry>
</row>
<row>
<entry><parameter>resourceId</parameter></entry>
<entry><type>uint32_t</type></entry>
<entry>X resource id (XID)</entry>
</row>
<row>
<entry><parameter>resourceTypeId</parameter></entry>
<entry><type>uint32_t</type></entry>
<entry>Resource type id</entry>
</row>
<row>
<entry><parameter>resourceTypeName</parameter></entry>
<entry><type>string</type></entry>
<entry>String representing X resource type
(<literal>"PIXMAP"</literal>, etc.)</entry>
</row>
<row>
<entry><parameter>resourceValue</parameter></entry>
<entry><type>uintptr_t</type></entry>
<entry>Pointer to data for X resource</entry>
</row>
<row>
<entry><parameter>resultCode</parameter></entry>
<entry><type>int</type></entry>
<entry>Integer code representing result status of request</entry>
</row>
<row>
<entry><parameter>requestBuffer</parameter></entry>
<entry><type>uintptr_t</type></entry>
<entry>Pointer to buffer containing X request - decode using
structures in
<<ulink url="http://cgit.freedesktop.org/xorg/proto/xproto/tree/Xproto.h"><filename class="headerfile">X11/Xproto.h</filename></ulink>>
and similar headers for each extension</entry>
</row>
<row>
<entry><parameter>requestCode</parameter></entry>
<entry><type>uint8_t</type></entry>
<entry>Request number of X request or Extension</entry>
</row>
<row>
<entry><parameter>requestName</parameter></entry>
<entry><type>string</type></entry>
<entry>Name of X request or Extension</entry>
</row>
<row>
<entry><parameter>requestLength</parameter></entry>
<entry><type>uint16_t</type></entry>
<entry>Length of X request</entry>
</row>
<row>
<entry><parameter>sequenceNumber</parameter></entry>
<entry><type>uint32_t</type></entry>
<entry>Number of X request in in this connection</entry>
</row>
<row>
<entry><parameter>deviceid</parameter></entry>
<entry><type>int</type></entry>
<entry>The device's numerical ID</entry>
</row>
<row>
<entry><parameter>eventtype</parameter></entry>
<entry><type>int</type></entry>
<entry>Protocol event type</entry>
</row>
<row>
<entry><parameter>button, keycode, touchid</parameter></entry>
<entry><type>uint32_t</type></entry>
<entry>The button number, keycode or touch ID</entry>
</row>
<row>
<entry><parameter>flags</parameter></entry>
<entry><type>uint32_t</type></entry>
<entry>Miscellaneous event-specific server flags</entry>
</row>
<row>
<entry><parameter>nvalues</parameter></entry>
<entry><type>int8_t</type></entry>
<entry>Number of bits in <parameter>mask</parameter> and number of elements
in <parameter>values</parameter></entry>
</row>
<row>
<entry><parameter>mask</parameter></entry>
<entry><type>uint8_t*</type></entry>
<entry>Binary mask indicating which indices in <parameter>values</parameter> contain
valid data</entry>
</row>
<row>
<entry><parameter>values</parameter></entry>
<entry><type>double*</type></entry>
<entry>Valuator values. Values for indices for which the
<parameter>mask</parameter> is not set are undefined</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
</sect1>
<sect1 id="examples">
<title>Examples</title>
<example id="Counting_requests_by_request_name">
<title>Counting requests by request name</title>
<para>
This script simply increments a counter for each different request
made, and when you exit the script (such as by hitting
<keycombo action='simul'><keycap>Control</keycap><keycap>C</keycap>
</keycombo>) prints the counts.
<programlisting>
#!/usr/sbin/dtrace -s
Xserver*:::request-start
{
@counts[copyinstr(arg0)] = count();
}
</programlisting>
The output from a short run may appear as:
<screen>
QueryPointer 1
CreatePixmap 2
FreePixmap 2
PutImage 2
ChangeGC 10
CopyArea 10
CreateGC 14
FreeGC 14
RENDER 28
SetClipRectangles 40
</screen>
</para>
<para>
This can be rewritten slightly to cache the string containing the name
of the request since it will be reused many times, instead of copying
it over and over from the kernel:
<programlisting>
#!/usr/sbin/dtrace -s
string Xrequest[uintptr_t];
Xserver*:::request-start
/Xrequest[arg0] == ""/
{
Xrequest[arg0] = copyinstr(arg0);
}
Xserver*:::request-start
{
@counts[Xrequest[arg0]] = count();
}
</programlisting>
</para>
</example>
<example id="Get_average_CPU_time_per_request">
<title>Get average CPU time per request</title>
<para>This script records the CPU time used between the probes at
the start and end of each request and aggregates it per request type.
<programlisting>
#!/usr/sbin/dtrace -s
Xserver*:::request-start
{
reqstart = vtimestamp;
}
Xserver*:::request-done
{
@times[copyinstr(arg0)] = avg(vtimestamp - reqstart);
}
</programlisting>
The output from a sample run might look like:
<screen>
ChangeGC 889
MapWindow 907
SetClipRectangles 1319
PolyPoint 1413
PolySegment 1434
PolyRectangle 1828
FreeCursor 1895
FreeGC 1950
CreateGC 2244
FreePixmap 2246
GetInputFocus 2249
TranslateCoords 8508
QueryTree 8846
GetGeometry 9948
CreatePixmap 12111
AllowEvents 14090
GrabServer 14791
MIT-SCREEN-SAVER 16747
ConfigureWindow 22917
SetInputFocus 28521
PutImage 240841
</screen>
</para>
</example>
<example id="Monitoring_clients_that_connect_and_disconnect">
<title>Monitoring clients that connect and disconnect</title>
<para>
This script simply prints information about each client that
connects or disconnects from the server while it is running.
Since the provider is specified as <code>Xserver$1</code> instead
of <code>Xserver*</code> like previous examples, it won't monitor
all Xserver processes running on the machine, but instead expects
the process id of the X server to monitor to be specified as the
argument to the script.
<programlisting>
#!/usr/sbin/dtrace -s
Xserver$1:::client-connect
{
printf("** Client Connect: id %d\n", arg0);
}
Xserver$1:::client-auth
{
printf("** Client auth'ed: id %d => %s pid %d\n",
arg0, copyinstr(arg1), arg2);
}
Xserver$1:::client-disconnect
{
printf("** Client Disconnect: id %d\n", arg0);
}
</programlisting>
A sample run:
<screen>
<prompt>#</prompt> <userinput>./foo.d 5790</userinput>
<computeroutput>dtrace: script './foo.d' matched 4 probes
CPU ID FUNCTION:NAME
0 15774 CloseDownClient:client-disconnect ** Client Disconnect: id 65
2 15774 CloseDownClient:client-disconnect ** Client Disconnect: id 64
0 15773 EstablishNewConnections:client-connect ** Client Connect: id 64
0 15772 AuthAudit:client-auth ** Client auth'ed: id 64 => local host pid 2034
0 15773 EstablishNewConnections:client-connect ** Client Connect: id 65
0 15772 AuthAudit:client-auth ** Client auth'ed: id 65 => local host pid 2034
0 15774 CloseDownClient:client-disconnect ** Client Disconnect: id 64
</computeroutput>
</screen>
</para>
</example>
<example id="Monitoring_clients_creating_Pixmaps">
<title>Monitoring clients creating Pixmaps</title>
<para>
This script can be used to determine which clients are creating
pixmaps in the X server, printing information about each client
as it connects to help trace it back to the program on the other
end of the X connection.
<programlisting>
#!/usr/sbin/dtrace -qs
string Xrequest[uintptr_t];
string Xrestype[uintptr_t];
Xserver$1:::request-start
/Xrequest[arg0] == ""/
{
Xrequest[arg0] = copyinstr(arg0);
}
Xserver$1:::resource-alloc
/arg3 != 0 && Xrestype[arg3] == ""/
{
Xrestype[arg3] = copyinstr(arg3);
}
Xserver$1:::request-start
/Xrequest[arg0] == "X_CreatePixmap"/
{
printf("-> %s: client %d\n", Xrequest[arg0], arg3);
}
Xserver$1:::request-done
/Xrequest[arg0] == "X_CreatePixmap"/
{
printf("<- %s: client %d\n", Xrequest[arg0], arg3);
}
Xserver$1:::resource-alloc
/Xrestype[arg3] == "PIXMAP"/
{
printf("** Pixmap alloc: %08x\n", arg0);
}
Xserver$1:::resource-free
/Xrestype[arg3] == "PIXMAP"/
{
printf("** Pixmap free: %08x\n", arg0);
}
Xserver$1:::client-connect
{
printf("** Client Connect: id %d\n", arg0);
}
Xserver$1:::client-auth
{
printf("** Client auth'ed: id %d => %s pid %d\n",
arg0, copyinstr(arg1), arg2);
}
Xserver$1:::client-disconnect
{
printf("** Client Disconnect: id %d\n", arg0);
}
</programlisting>
Sample output from a run of this script:
<screen><computeroutput>
** Client Connect: id 17
** Client auth'ed: id 17 => local host pid 20273
-> X_CreatePixmap: client 17
** Pixmap alloc: 02200009
<- X_CreatePixmap: client 17
-> X_CreatePixmap: client 15
** Pixmap alloc: 01e00180
<- X_CreatePixmap: client 15
-> X_CreatePixmap: client 15
** Pixmap alloc: 01e00181
<- X_CreatePixmap: client 15
-> X_CreatePixmap: client 14
** Pixmap alloc: 01c004c8
<- X_CreatePixmap: client 14
** Pixmap free: 02200009
** Client Disconnect: id 17
** Pixmap free: 01e00180
** Pixmap free: 01e00181
</computeroutput></screen>
</para>
</example>
<example id="Input_API_monitoring_with_systemtap">
<title>Input API monitoring with SystemTap</title>
<para>
This script can be used to monitor events submitted by drivers to
the server for enqueuing. Due to the integration of the input API
probes, some server-enqueued events will show up too.
<programlisting>
# Compile+run with
# stap -g xorg.stp /usr/bin/Xorg
#
function print_valuators:string(nvaluators:long, mask_in:long, valuators_in:long) %{
int i;
unsigned char *mask = (unsigned char*)THIS->mask_in;
double *valuators = (double*)THIS->valuators_in;
char str[128] = {0};
char *s = str;
#define BitIsSet(ptr, bit) (((unsigned char*)(ptr))[(bit)>>3] & (1 << ((bit) & 7)))
s += sprintf(s, "nval: %d ::", (int)THIS->nvaluators);
for (i = 0; i < THIS->nvaluators; i++)
{
s += sprintf(s, " %d: ", i);
if (BitIsSet(mask, i))
s += sprintf(s, "%d", (int)valuators[i]);
}
sprintf(THIS->__retvalue, "%s", str);
%}
probe process(@1).mark("input__event")
{
deviceid = $arg1
type = $arg2
detail = $arg3
flags = $arg4
nvaluators = $arg5
str = print_valuators(nvaluators, $arg6, $arg7)
printf("Event: device %d type %d detail %d flags %#x %s\n",
deviceid, type, detail, flags, str);
}
</programlisting>
Sample output from a run of this script:
<screen><computeroutput>
Event: device 13 type 4 detail 1 flags 0x0 nval: 0 ::
Event: device 13 type 6 detail 0 flags 0xa nval: 1 :: 0: 1
Event: device 13 type 6 detail 0 flags 0xa nval: 2 :: 0: 2 1: -1
Event: device 13 type 6 detail 0 flags 0xa nval: 2 :: 0: 2 1: -1
Event: device 13 type 6 detail 0 flags 0xa nval: 2 :: 0: 4 1: -3
Event: device 13 type 6 detail 0 flags 0xa nval: 2 :: 0: 3 1: -3
Event: device 13 type 6 detail 0 flags 0xa nval: 2 :: 0: 3 1: -2
Event: device 13 type 6 detail 0 flags 0xa nval: 2 :: 0: 2 1: -2
Event: device 13 type 6 detail 0 flags 0xa nval: 2 :: 0: 2 1: -2
Event: device 13 type 6 detail 0 flags 0xa nval: 2 :: 0: 2 1: -2
Event: device 13 type 6 detail 0 flags 0xa nval: 2 :: 0: 1: -1
Event: device 13 type 6 detail 0 flags 0xa nval: 2 :: 0: 1: -1
Event: device 13 type 5 detail 1 flags 0x0 nval: 0 ::
</computeroutput></screen>
</para>
</example>
</sect1>
</article>
|