2 * Created: Mon Jan 15 05:05:07 2001 by faith@acm.org
4 * Copyright 2000 VA Linux Systems, Inc., Fremont, California.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * Authors: Rickard E. (Rik) Faith <faith@valinux.com>
34 #include "xf86drmRandom.c"
35 #include "xf86drmHash.c"
38 #define DRM_VERSION 0x00000001
39 #define DRM_MEMORY 0x00000002
40 #define DRM_CLIENTS 0x00000004
41 #define DRM_STATS 0x00000008
42 #define DRM_BUSID 0x00000010
44 static void getversion(int fd
)
46 drmVersionPtr version
;
48 version
= drmGetVersion(fd
);
50 printf(" Version information:\n");
51 printf(" Name: %s\n", version
->name
? version
->name
: "?");
52 printf(" Version: %d.%d.%d\n",
53 version
->version_major
,
54 version
->version_minor
,
55 version
->version_patchlevel
);
56 printf(" Date: %s\n", version
->date
? version
->date
: "?");
57 printf(" Desc: %s\n", version
->desc
? version
->desc
: "?");
58 drmFreeVersion(version
);
60 printf(" No version information available\n");
64 static void getbusid(int fd
)
66 const char *busid
= drmGetBusid(fd
);
68 printf(" Busid: %s\n", *busid
? busid
: "(not set)");
73 static void getvm(int fd
)
85 printf(" VM map information:\n");
86 printf(" flags: (R)estricted (r)ead/(w)rite (l)ocked (k)ernel (W)rite-combine (L)ock:\n");
87 printf(" slot offset size type flags address mtrr\n");
90 !drmGetMap(fd
, i
, &offset
, &size
, &type
, &flags
, &handle
, &mtrr
);
94 case DRM_FRAME_BUFFER
: typename
= "FB"; break;
95 case DRM_REGISTERS
: typename
= "REG"; break;
96 case DRM_SHM
: typename
= "SHM"; break;
97 case DRM_AGP
: typename
= "AGP"; break;
98 case DRM_SCATTER_GATHER
: typename
= "SG"; break;
99 default: typename
= "???"; break;
102 flagname
[0] = (flags
& DRM_RESTRICTED
) ? 'R' : ' ';
103 flagname
[1] = (flags
& DRM_READ_ONLY
) ? 'r' : 'w';
104 flagname
[2] = (flags
& DRM_LOCKED
) ? 'l' : ' ';
105 flagname
[3] = (flags
& DRM_KERNEL
) ? 'k' : ' ';
106 flagname
[4] = (flags
& DRM_WRITE_COMBINING
) ? 'W' : ' ';
107 flagname
[5] = (flags
& DRM_CONTAINS_LOCK
) ? 'L' : ' ';
110 printf(" %4d 0x%08lx 0x%08lx %3.3s %6.6s 0x%08lx ",
111 i
, offset
, (unsigned long)size
, typename
, flagname
, handle
);
112 if (mtrr
< 0) printf("none\n");
113 else printf("%4d\n", mtrr
);
117 static void getclients(int fd
)
129 printf(" DRI client information:\n");
130 printf(" a pid uid magic ioctls prog\n");
132 for (i
= 0; !drmGetClient(fd
, i
, &auth
, &pid
, &uid
, &magic
, &iocs
); i
++) {
133 sprintf(buf
, "/proc/%d/cmdline", pid
);
134 memset(cmd
, 0, sizeof(cmd
));
135 if ((procfd
= open(buf
, O_RDONLY
, 0)) >= 0) {
136 read(procfd
, cmd
, sizeof(cmd
)-1);
142 for (pt
= cmd
; *pt
; pt
++) if (!isprint(*pt
)) *pt
= ' ';
143 printf(" %c %5d %5d %10lu %10lu %s\n",
144 auth
? 'y' : 'n', pid
, uid
, magic
, iocs
, cmd
);
146 printf(" %c %5d %5d %10lu %10lu\n",
147 auth
? 'y' : 'n', pid
, uid
, magic
, iocs
);
152 static void printhuman(unsigned long value
, const char *name
, int mult
)
156 /* Print width 5 number in width 6 space */
157 if (value
< 100000) {
158 printf(" %5lu", value
);
163 f
= (double)value
/ (double)mult
;
165 printf(" %4.2f%c", f
, *p
);
170 f
= (double)value
/ (double)mult
;
172 printf(" %4.2f%c", f
, *p
);
177 f
= (double)value
/ (double)mult
;
179 printf(" %4.2f%c", f
, *p
);
184 static void getstats(int fd
, int i
)
186 drmStatsT prev
, curr
;
190 printf(" System statistics:\n");
192 if (drmGetStats(fd
, &prev
)) return;
194 for (j
= 0; j
< prev
.count
; j
++) {
196 printf(prev
.data
[j
].long_format
, prev
.data
[j
].long_name
);
197 if (prev
.data
[j
].isvalue
) printf(" 0x%08lx\n", prev
.data
[j
].value
);
198 else printf(" %10lu\n", prev
.data
[j
].value
);
204 for (j
= 0; j
< prev
.count
; j
++)
205 if (!prev
.data
[j
].verbose
) {
207 printf(prev
.data
[j
].rate_format
, prev
.data
[j
].rate_name
);
213 if (drmGetStats(fd
, &curr
)) return;
215 for (j
= 0; j
< curr
.count
; j
++) {
216 if (curr
.data
[j
].verbose
) continue;
217 if (curr
.data
[j
].isvalue
) {
218 printf(" %08lx", curr
.data
[j
].value
);
220 rate
= (curr
.data
[j
].value
- prev
.data
[j
].value
) / (double)i
;
221 printhuman(rate
, curr
.data
[j
].mult_names
, curr
.data
[j
].mult
);
225 memcpy(&prev
, &curr
, sizeof(prev
));
230 int main(int argc
, char **argv
)
240 while ((c
= getopt(argc
, argv
, "avmcsbM:i:")) != EOF
)
242 case 'a': mask
= ~0; break;
243 case 'v': mask
|= DRM_VERSION
; break;
244 case 'm': mask
|= DRM_MEMORY
; break;
245 case 'c': mask
|= DRM_CLIENTS
; break;
246 case 's': mask
|= DRM_STATS
; break;
247 case 'b': mask
|= DRM_BUSID
; break;
248 case 'i': interval
= strtol(optarg
, NULL
, 0); break;
249 case 'M': minor
= strtol(optarg
, NULL
, 0); break;
251 fprintf( stderr
, "Usage: dristat [options]\n\n" );
252 fprintf( stderr
, "Displays DRM information. Use with no arguments to display available cards.\n\n" );
253 fprintf( stderr
, " -a Show all available information\n" );
254 fprintf( stderr
, " -b Show DRM bus ID's\n" );
255 fprintf( stderr
, " -c Display information about DRM clients\n" );
256 fprintf( stderr
, " -i [interval] Continuously display statistics every [interval] seconds\n" );
257 fprintf( stderr
, " -v Display DRM module and card version information\n" );
258 fprintf( stderr
, " -m Display memory use information\n" );
259 fprintf( stderr
, " -s Display DRM statistics\n" );
260 fprintf( stderr
, " -M [minor] Select card by minor number\n" );
264 for (i
= 0; i
< 16; i
++) if (!minor
|| i
== minor
) {
265 sprintf(buf
, DRM_DEV_NAME
, DRM_DIR_NAME
, i
);
266 fd
= drmOpenMinor(i
, 1, DRM_NODE_RENDER
);
269 if (mask
& DRM_BUSID
) getbusid(fd
);
270 if (mask
& DRM_VERSION
) getversion(fd
);
271 if (mask
& DRM_MEMORY
) getvm(fd
);
272 if (mask
& DRM_CLIENTS
) getclients(fd
);
273 if (mask
& DRM_STATS
) getstats(fd
, interval
);