diff options
author | Alan Coopersmith <alan.coopersmith@sun.com> | 2006-11-03 12:54:43 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@sun.com> | 2006-11-03 12:54:43 -0800 |
commit | 49a26681b2bdd95ed65c425f1fa1441d2f092a6e (patch) | |
tree | 6aaa2377b67a5d1f1a7b1da6967ff4222339dd1b /dix | |
parent | 037f23e6f8fbe6e6fc8e71ed21958fc553df72d0 (diff) |
Add DTrace probe points for X server <-> client communications
See http://people.freedesktop.org/~alanc/dtrace/ for more details
Diffstat (limited to 'dix')
-rw-r--r-- | dix/Makefile.am | 20 | ||||
-rw-r--r-- | dix/Xserver-dtrace.h.in | 100 | ||||
-rw-r--r-- | dix/Xserver.d | 59 | ||||
-rw-r--r-- | dix/dispatch.c | 119 | ||||
-rw-r--r-- | dix/events.c | 14 | ||||
-rw-r--r-- | dix/extension.c | 14 | ||||
-rw-r--r-- | dix/resource.c | 56 |
7 files changed, 380 insertions, 2 deletions
diff --git a/dix/Makefile.am b/dix/Makefile.am index 724d1d1f6..d0d6e8785 100644 --- a/dix/Makefile.am +++ b/dix/Makefile.am @@ -38,4 +38,22 @@ libxpstubs_la_SOURCES = \ INCLUDES = -I$(top_srcdir)/Xprint -EXTRA_DIST = buildatoms BuiltInAtoms CHANGES +EXTRA_DIST = buildatoms BuiltInAtoms CHANGES Xserver.d Xserver-dtrace.h.in + +if XSERVER_DTRACE +# Generate dtrace header file for C sources to include +BUILT_SOURCES = Xserver-dtrace.h + +Xserver-dtrace.h: $(srcdir)/Xserver.d + $(DTRACE) -C -h -o $@ -s $(srcdir)/Xserver.d \ + || cp Xserver-dtrace.h.in $@ + +# Generate dtrace object code for probes in libdix +dtrace-dix.o: $(top_srcdir)/dix/Xserver.d $(am_libdix_la_OBJECTS) + $(DTRACE) -G -C -o $@ -s $(top_srcdir)/dix/Xserver.d .libs/*.o + +noinst_LIBRARIES = dix.O + +dix.O: dtrace-dix.o $(am_libdix_la_OBJECTS) + ld -r -o $@ .libs/*.o +endif diff --git a/dix/Xserver-dtrace.h.in b/dix/Xserver-dtrace.h.in new file mode 100644 index 000000000..26a8b4099 --- /dev/null +++ b/dix/Xserver-dtrace.h.in @@ -0,0 +1,100 @@ +/* Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * + * 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, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * 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 + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL + * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, use + * or other dealings in this Software without prior written authorization + * of the copyright holder. + */ + +/* + * Generated by dtrace(1M), and then modified for backwards compatibility + * with older versions of dtrace. Used if dtrace -h fails. + * (Since _ENABLED support was added after dtrace -h, this assumes if + * dtrace -h fails, _ENABLED will too.) + */ + +#ifndef _XSERVER_DTRACE_H +#define _XSERVER_DTRACE_H + +#include <unistd.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#if _DTRACE_VERSION + +#define XSERVER_CLIENT_AUTH(arg0, arg1, arg2, arg3) \ + __dtrace_Xserver___client__auth(arg0, arg1, arg2, arg3) +#define XSERVER_CLIENT_CONNECT(arg0, arg1) \ + __dtrace_Xserver___client__connect(arg0, arg1) +#define XSERVER_CLIENT_DISCONNECT(arg0) \ + __dtrace_Xserver___client__disconnect(arg0) +#define XSERVER_REQUEST_DONE(arg0, arg1, arg2, arg3, arg4) \ + __dtrace_Xserver___request__done(arg0, arg1, arg2, arg3, arg4) +#define XSERVER_REQUEST_START(arg0, arg1, arg2, arg3, arg4) \ + __dtrace_Xserver___request__start(arg0, arg1, arg2, arg3, arg4) +#define XSERVER_RESOURCE_ALLOC(arg0, arg1, arg2, arg3) \ + __dtrace_Xserver___resource__alloc(arg0, arg1, arg2, arg3) +#define XSERVER_RESOURCE_FREE(arg0, arg1, arg2, arg3) \ + __dtrace_Xserver___resource__free(arg0, arg1, arg2, arg3) +#define XSERVER_SEND_EVENT(arg0, arg1, arg2) \ + __dtrace_Xserver___send__event(arg0, arg1, arg2) + + +extern void __dtrace_Xserver___client__auth(int, string, pid_t, zoneid_t); +extern void __dtrace_Xserver___client__connect(int, int); +extern void __dtrace_Xserver___client__disconnect(int); +extern void __dtrace_Xserver___request__done(string, uint8_t, uint32_t, int, int); +extern void __dtrace_Xserver___request__start(string, uint8_t, uint16_t, int, void *); +extern void __dtrace_Xserver___resource__alloc(uint32_t, uint32_t, void *, string); +extern void __dtrace_Xserver___resource__free(uint32_t, uint32_t, void *, string); +extern void __dtrace_Xserver___send__event(int, uint8_t, void *); + +#else + +#define XSERVER_CLIENT_AUTH(arg0, arg1, arg2, arg3) +#define XSERVER_CLIENT_CONNECT(arg0, arg1) +#define XSERVER_CLIENT_DISCONNECT(arg0) +#define XSERVER_REQUEST_DONE(arg0, arg1, arg2, arg3, arg4) +#define XSERVER_REQUEST_START(arg0, arg1, arg2, arg3, arg4) +#define XSERVER_RESOURCE_ALLOC(arg0, arg1, arg2, arg3) +#define XSERVER_RESOURCE_FREE(arg0, arg1, arg2, arg3) +#define XSERVER_SEND_EVENT(arg0, arg1, arg2) + +#endif + +#define XSERVER_CLIENT_AUTH_ENABLED() (1) +#define XSERVER_CLIENT_CONNECT_ENABLED() (1) +#define XSERVER_CLIENT_DISCONNECT_ENABLED() (1) +#define XSERVER_REQUEST_DONE_ENABLED() (1) +#define XSERVER_REQUEST_START_ENABLED() (1) +#define XSERVER_RESOURCE_ALLOC_ENABLED() (1) +#define XSERVER_RESOURCE_FREE_ENABLED() (1) +#define XSERVER_SEND_EVENT_ENABLED() (1) + +#ifdef __cplusplus +} +#endif + +#endif /* _XSERVER_DTRACE_H */ diff --git a/dix/Xserver.d b/dix/Xserver.d new file mode 100644 index 000000000..e4c9b8320 --- /dev/null +++ b/dix/Xserver.d @@ -0,0 +1,59 @@ +/* Copyright 2005-2006 Sun Microsystems, Inc. All rights reserved. + * + * 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, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * 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 + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL + * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, use + * or other dealings in this Software without prior written authorization + * of the copyright holder. + */ + +/* + * Xserver dtrace provider definition + */ + +#include <sys/types.h> + +provider Xserver { + /* reqType, data, length, client id, request buffer */ + probe request__start(string, uint8_t, uint16_t, int, void *); + /* reqType, data, sequence, client id, result */ + probe request__done(string, uint8_t, uint32_t, int, int); + /* client id, client fd */ + probe client__connect(int, int); + /* client id, client address, client pid, client zone id */ + probe client__auth(int, string, pid_t, zoneid_t); + /* client id */ + probe client__disconnect(int); + /* resource id, resource type, value, resource type name */ + probe resource__alloc(uint32_t, uint32_t, void *, string); + /* resource id, resource type, value, resource type name */ + probe resource__free(uint32_t, uint32_t, void *, string); + /* client id, event type, event* */ + probe send__event(int, uint8_t, void *); +}; + +#pragma D attributes Unstable/Unstable/Common provider Xserver provider +#pragma D attributes Private/Private/Unknown provider Xserver module +#pragma D attributes Private/Private/Unknown provider Xserver function +#pragma D attributes Unstable/Unstable/Common provider Xserver name +#pragma D attributes Unstable/Unstable/Common provider Xserver args + diff --git a/dix/dispatch.c b/dix/dispatch.c index 6347e3924..2e7fa79ab 100644 --- a/dix/dispatch.c +++ b/dix/dispatch.c @@ -74,6 +74,36 @@ Equipment Corporation. ******************************************************************/ +/* XSERVER_DTRACE additions: + * Copyright 2005-2006 Sun Microsystems, Inc. All rights reserved. + * + * 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, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * 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 + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL + * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, use + * or other dealings in this Software without prior written authorization + * of the copyright holder. + */ + + #ifdef HAVE_DIX_CONFIG_H #include <dix-config.h> @@ -119,6 +149,17 @@ int ProcInitialConnection(); #include <X11/extensions/XKBsrv.h> #endif +#ifdef XSERVER_DTRACE +#include <sys/types.h> +typedef const char *string; +#include "Xserver-dtrace.h" + +char *RequestNames[256]; +static void LoadRequestNames(void); +static void FreeRequestNames(void); +#define GetRequestName(i) (RequestNames[i]) +#endif + #define mskcnt ((MAXCLIENTS + 31) / 32) #define BITMASK(i) (1U << ((i) & 31)) #define MASKIDX(i) ((i) >> 5) @@ -373,6 +414,10 @@ Dispatch(void) if (!clientReady) return; +#ifdef XSERVER_DTRACE + LoadRequestNames(); +#endif + while (!dispatchException) { if (*icheck[0] != *icheck[1]) @@ -452,6 +497,11 @@ Dispatch(void) client->requestLog[client->requestLogIndex] = MAJOROP; client->requestLogIndex++; #endif +#ifdef XSERVER_DTRACE + XSERVER_REQUEST_START(GetRequestName(MAJOROP), MAJOROP, + ((xReq *)client->requestBuffer)->length, + client->index, client->requestBuffer); +#endif if (result > (maxBigRequestSize << 2)) result = BadLength; else @@ -464,7 +514,11 @@ Dispatch(void) #else result = (* client->requestVector[MAJOROP])(client); #endif /* XACE */ - +#ifdef XSERVER_DTRACE + XSERVER_REQUEST_DONE(GetRequestName(MAJOROP), MAJOROP, + client->sequence, client->index, result); +#endif + if (result != Success) { if (client->noClientException != Success) @@ -495,6 +549,9 @@ Dispatch(void) KillAllClients(); DEALLOCATE_LOCAL(clientReady); dispatchException &= ~DE_RESET; +#ifdef XSERVER_DTRACE + FreeRequestNames(); +#endif } #undef MAJOROP @@ -3569,6 +3626,9 @@ CloseDownClient(register ClientPtr client) CallCallbacks((&ClientStateCallback), (pointer)&clientinfo); } FreeClientResources(client); +#ifdef XSERVER_DTRACE + XSERVER_CLIENT_DISCONNECT(client->index); +#endif if (client->index < nextFreeClientID) nextFreeClientID = client->index; clients[client->index] = NullClient; @@ -3995,3 +4055,60 @@ MarkClientException(ClientPtr client) { client->noClientException = -1; } + +#ifdef XSERVER_DTRACE +#include <ctype.h> + +/* Load table of request names for dtrace probes */ +static void LoadRequestNames(void) +{ + int i; + FILE *xedb; + extern void LoadExtensionNames(char **RequestNames); + + bzero(RequestNames, 256 * sizeof(char *)); + + xedb = fopen(XERRORDB_PATH, "r"); + if (xedb != NULL) { + char buf[256]; + while (fgets(buf, sizeof(buf), xedb)) { + if ((strncmp("XRequest.", buf, 9) == 0) && (isdigit(buf[9]))) { + char *name; + i = strtol(buf + 9, &name, 10); + if (RequestNames[i] == 0) { + char *end = strchr(name, '\n'); + if (end) { *end = '\0'; } + RequestNames[i] = strdup(name + 1); + } + } + } + fclose(xedb); + } + + LoadExtensionNames(RequestNames); + + for (i = 0; i < 256; i++) { + if (RequestNames[i] == 0) { +#define RN_SIZE 12 /* "Request#' + up to 3 digits + \0 */ + RequestNames[i] = xalloc(RN_SIZE); + if (RequestNames[i]) { + snprintf(RequestNames[i], RN_SIZE, "Request#%d", i); + } + } + /* fprintf(stderr, "%d: %s\n", i, RequestNames[i]); */ + } +} + +static void FreeRequestNames(void) +{ + int i; + + for (i = 0; i < 256; i++) { + if (RequestNames[i] != 0) { + free(RequestNames[i]); + RequestNames[i] = 0; + } + } +} + +#endif diff --git a/dix/events.c b/dix/events.c index 3425cb433..3b1a0aaf4 100644 --- a/dix/events.c +++ b/dix/events.c @@ -141,6 +141,12 @@ extern Bool XkbFilterEvents(ClientPtr, int, xEvent *); #include "xace.h" #endif +#ifdef XSERVER_DTRACE +#include <sys/types.h> +typedef const char *string; +#include "Xserver-dtrace.h" +#endif + #ifdef XEVIE extern WindowPtr *WindowTable; extern int xevieFlag; @@ -4553,6 +4559,14 @@ WriteEventsToClient(ClientPtr pClient, int count, xEvent *events) eventinfo.count = count; CallCallbacks(&EventCallback, (pointer)&eventinfo); } +#ifdef XSERVER_DTRACE + if (XSERVER_SEND_EVENT_ENABLED()) { + for (i = 0; i < count; i++) + { + XSERVER_SEND_EVENT(pClient->index, events[i].u.u.type, &events[i]); + } + } +#endif if(pClient->swapped) { for(i = 0; i < count; i++) diff --git a/dix/extension.c b/dix/extension.c index f58c73138..fe779b2be 100644 --- a/dix/extension.c +++ b/dix/extension.c @@ -482,3 +482,17 @@ RegisterScreenProc(char *name, ScreenPtr pScreen, ExtensionLookupProc proc) } return TRUE; } + +#ifdef XSERVER_DTRACE +void LoadExtensionNames(char **RequestNames) { + int i; + + for (i=0; i<NumExtensions; i++) { + int r = extensions[i]->base; + + if (RequestNames[r] == NULL) { + RequestNames[r] = strdup(extensions[i]->name); + } + } +} +#endif diff --git a/dix/resource.c b/dix/resource.c index b2d01c8f3..efb759e75 100644 --- a/dix/resource.c +++ b/dix/resource.c @@ -72,6 +72,34 @@ dealings in this Software without prior written authorization from Digital Equipment Corporation. ******************************************************************/ +/* XSERVER_DTRACE additions: + * Copyright 2005-2006 Sun Microsystems, Inc. All rights reserved. + * + * 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, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * 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 + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL + * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING + * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, use + * or other dealings in this Software without prior written authorization + * of the copyright holder. + */ /* $TOG: resource.c /main/41 1998/02/09 14:20:31 kaleb $ */ @@ -125,6 +153,14 @@ Equipment Corporation. #endif #include <assert.h> +#ifdef XSERVER_DTRACE +#include <sys/types.h> +typedef const char *string; +#include "Xserver-dtrace.h" + +#define TypeNameString(t) NameForAtom(ResourceNames[t & TypeMask]) +#endif + static void RebuildTable( int /*client*/ ); @@ -429,6 +465,9 @@ AddResource(XID id, RESTYPE type, pointer value) register ClientResourceRec *rrec; register ResourcePtr res, *head; +#ifdef XSERVER_DTRACE + XSERVER_RESOURCE_ALLOC(id, type, value, TypeNameString(type)); +#endif client = CLIENT_ID(id); rrec = &clientTable[client]; if (!rrec->buckets) @@ -528,6 +567,11 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType) if (res->id == id) { RESTYPE rtype = res->type; + +#ifdef XSERVER_DTRACE + XSERVER_RESOURCE_FREE(res->id, res->type, + res->value, TypeNameString(res->type)); +#endif *prev = res->next; elements = --*eltptr; if (rtype & RC_CACHED) @@ -569,6 +613,10 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree) { if (res->id == id && res->type == type) { +#ifdef XSERVER_DTRACE + XSERVER_RESOURCE_FREE(res->id, res->type, + res->value, TypeNameString(res->type)); +#endif *prev = res->next; if (type & RC_CACHED) FlushClientCaches(res->id); @@ -731,6 +779,10 @@ FreeClientNeverRetainResources(ClientPtr client) RESTYPE rtype = this->type; if (rtype & RC_NEVERRETAIN) { +#ifdef XSERVER_DTRACE + XSERVER_RESOURCE_FREE(this->id, this->type, + this->value, TypeNameString(this->type)); +#endif *prev = this->next; if (rtype & RC_CACHED) FlushClientCaches(this->id); @@ -777,6 +829,10 @@ FreeClientResources(ClientPtr client) for (this = *head; this; this = *head) { RESTYPE rtype = this->type; +#ifdef XSERVER_DTRACE + XSERVER_RESOURCE_FREE(this->id, this->type, + this->value, TypeNameString(this->type)); +#endif *head = this->next; if (rtype & RC_CACHED) FlushClientCaches(this->id); |