Xserver provider for DTrace

AlanCoopersmith

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:

The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.

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.

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.

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.

Available probes

Due to the way User-Defined DTrace probes work, arguments to
these probes all bear undistinguished names of
arg0, arg1,
arg2, etc. These tables should help you
determine what the real data is for each of the probe arguments.

Table 1. Probes and their arguments

Probe name

Description

arg0

arg1

arg2

arg3

arg4

Request Probes

request-start

Called just before processing each client request.

requestName

requestCode

requestLength

clientId

requestBuffer

request-done

Called just after processing each client request.

requestName

requestCode

sequenceNumber

clientId

resultCode

Event Probes

send-event

Called just before send each event to a client.

clientId

eventCode

eventBuffer

Client Connection Probes

client-connect

Called when a new connection is opened from a client

clientId

clientFD

client-auth

Called when client authenticates (normally just after connection opened)

clientId

clientAddr

clientPid

clientZoneId

client-disconnect

Called when a client connection is closed

clientId

Resource Allocation Probes

resource-alloc

Called when a new resource (pixmap, gc, colormap, etc.) is allocated

resourceId

resourceTypeId

resourceValue

resourceTypeName

resource-free

Called when a resource is freed

resourceId

resourceTypeId

resourceValue

resourceTypeName

Data Available in Probe Arguments

To access data in arguments of type string, you will need
to use copyinstr().
To access data buffers referenced via uintptr_t's, you will
need to use copyin().

Table 2. Probe Arguments

Argument name

Type

Description

clientAddr

string

String representing address client connected from

clientFD

int

X server's file descriptor for server side of each connection

clientId

int

Unique integer identifier for each connection to the
X server

clientPid

pid_t

Process id of client, if connection is local
(from getpeerucred())

clientZoneId

zoneid_t

Solaris: Zone id of client, if connection is local
(from getpeerucred())

eventBuffer

uintptr_t

Pointer to buffer containing X event - decode using
structures in
<X11/Xproto.h>
and similar headers for each extension

eventCode

uint8_t

Event number of X event

resourceId

uint32_t

X resource id (XID)

resourceTypeId

uint32_t

Resource type id

resourceTypeName

string

String representing X resource type
("PIXMAP", etc.)

resourceValue

uintptr_t

Pointer to data for X resource

resultCode

int

Integer code representing result status of request

requestBuffer

uintptr_t

Pointer to buffer containing X request - decode using
structures in
<X11/Xproto.h>
and similar headers for each extension

requestCode

uint8_t

Request number of X request or Extension

requestName

string

Name of X request or Extension

requestLength

uint16_t

Length of X request

sequenceNumber

uint32_t

Number of X request in in this connection

Examples

Example 1. Counting requests by request name

This script simply increments a counter for each different request
made, and when you exit the script (such as by hitting
Control+C) prints the counts.

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 Xserver$1 instead
of Xserver* 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.

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.