#!/usr/sbin/dtrace -Cs #pragma D option quiet #include #include BEGIN { print_details=0; print_request_start=0; print_request_done=0; printall_send_events=1; } proc:::exec { process_name[pid] = args[0]; } /* arg0 -> client id * arg1 -> client host address (string) * arg2 -> client pid (-1 for remote) * arg3 -> client zoneid (-1 for remote) */ X*:::client-auth / arg2 == -1 / { printf("client-auth: client=%d, from remote host %s\n", arg0, copyinstr(arg1)); } X*:::client-auth / arg2 != -1 / { printf("client-auth: client=%d, from local pid=%d (%s)\n", arg0, arg2, process_name[arg2]); clients[arg0]=process_name[arg2]; } /* arg0 -> client id */ X*:::client-disconnect { printf("client disconnect: %4d (%s)\n", arg0, clients[arg0]); } X*:::request-start /print_request_start/ { printf("request-start: from client=%d (%s), request = %s\n",arg3, clients[arg3],copyinstr(arg0)); } X*:::request-done /print_request_done/ { printf("request-done: from client=%d (%s), request = %s, resultCode = %d\n", arg3, clients[arg3],copyinstr(arg0),arg4); } X*:::send-event /printall_send_events/ { printf("send-event: to client=%d (%s), event type = ",arg0, clients[arg0]); event_type = (arg1==KeyPress) ? "KeyPress" : (arg1==KeyRelease) ? "KeyRelease" : (arg1==ButtonPress) ? "ButtonPress" : (arg1==ButtonRelease) ? "ButtonRelease" : (arg1==MotionNotify) ? "MotionNotify" : (arg1==EnterNotify) ? "EnterNotify" : (arg1==LeaveNotify) ? "LeaveNotify" : (arg1==FocusIn) ? "FocusIn" : (arg1==FocusOut) ? "FocusOut" : (arg1==KeymapNotify) ? "KeymapNotify" : (arg1==Expose) ? "Expose" : (arg1==GraphicsExpose) ? "GraphicsExpose" : (arg1==NoExpose) ? "NoExpose" : (arg1==VisibilityNotify) ? "VisibilityNotify" : (arg1==CreateNotify) ? "CreateNotify" : (arg1==DestroyNotify) ? "DestroyNotify" : (arg1==UnmapNotify) ? "UnmapNotify" : (arg1==MapNotify) ? "MapNotify" : (arg1==MapRequest) ? "MapRequest" : (arg1==ReparentNotify) ? "ReparentNotify" : (arg1==ConfigureNotify) ? "ConfigureNotify" : (arg1==GravityNotify) ? "GravityNotify" : (arg1==ResizeRequest) ? "ResizeRequest" : (arg1==CirculateNotify) ? "CirculateNotify" : (arg1==CirculateRequest) ? "CirculateRequest" : (arg1==PropertyNotify) ? "PropertyNotify" : (arg1==SelectionClear) ? "SelectionClear" : (arg1==SelectionRequest) ? "SelectionRequest" : (arg1==SelectionNotify) ? "SelectionNotify" : (arg1==ColormapNotify) ? "ColormapNotify" : (arg1==ClientMessage) ? "ClientMessage" : (arg1==MappingNotify) ? "MappingNotify" : "Unknown"; printf(" %s (%d)\n",event_type,arg1); } /* Example of tracing an individual event */ X*:::send-event /arg1==PropertyNotify && print_details/ { /* xEvent is defined in Xproto.h */ event = (xEvent *)copyin(arg2, sizeof (xEvent)); window = event->u.property.window; atom = event->u.property.atom; state = event->u.property.state; time = event->u.property.time; printf("PropertyNotify: window=0x%x, atom=0x%x, state=%d, time=%d\n", window,atom,state,time); }