]> git.saurik.com Git - apple/system_cmds.git/blame - fs_usage.tproj/fs_usage.c
system_cmds-175.2.tar.gz
[apple/system_cmds.git] / fs_usage.tproj / fs_usage.c
CommitLineData
1815bff5
A
1/*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License."
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24
25/*
26cc -I. -DKERNEL_PRIVATE -O -o fs_usage fs_usage.c
27*/
28
29#define Default_DELAY 1 /* default delay interval */
30
31#include <stdlib.h>
32#include <stdio.h>
33#include <signal.h>
34#include <strings.h>
35#include <nlist.h>
36#include <fcntl.h>
37#include <string.h>
38
39#include <sys/types.h>
40#include <sys/param.h>
41#include <sys/time.h>
42
43#include <libc.h>
44#include <termios.h>
45#include <bsd/curses.h>
46#include <sys/ioctl.h>
47
48#ifndef KERNEL_PRIVATE
49#define KERNEL_PRIVATE
50#include <sys/kdebug.h>
51#undef KERNEL_PRIVATE
52#else
53#include <sys/kdebug.h>
54#endif /*KERNEL_PRIVATE*/
55
56#include <sys/sysctl.h>
57#include <errno.h>
58#import <mach/clock_types.h>
59#include <err.h>
60
61extern int errno;
62
63
64struct th_info {
65 int in_filemgr;
66 int thread;
67 int type;
68 int arg1;
69 int arg2;
70 int arg3;
71 int arg4;
72 int vfslookup;
73 int child_thread;
74 int waited;
75 double stime;
76 char pathname[32];
77};
78
79#define MAX_THREADS 512
80struct th_info th_state[MAX_THREADS];
81
82
83int cur_max = 0;
84int need_new_map = 1;
85int bias_secs;
86int wideflag = 0;
87int select_pid_mode = 0; /* Flag set indicates that output is restricted
88 to selected pids or commands */
89
90int one_good_pid = 0; /* Used to fail gracefully when bad pids given */
91
92
93#define DBG_ZERO_FILL_FAULT 1
94#define DBG_PAGEIN_FAULT 2
95#define DBG_COW_FAULT 3
96#define DBG_CACHE_HIT_FAULT 4
97
98#define TRACE_DATA_NEWTHREAD 0x07000004
99#define TRACE_STRING_NEWTHREAD 0x07010004
100#define TRACE_STRING_EXEC 0x07010008
101
102#define MACH_vmfault 0x01300000
103#define MACH_sched 0x01400000
104#define MACH_stkhandoff 0x01400008
105#define VFS_LOOKUP 0x03010090
106#define BSC_exit 0x040C0004
107
108#define MSC_map_fd 0x010c00ac
109#define BSC_recvmsg 0x040C006C
110#define BSC_sendmsg 0x040C0070
111#define BSC_recvfrom 0x040C0074
112#define BSC_sendto 0x040C0214
113
114#define BSC_read 0x040C000C
115#define BSC_write 0x040C0010
116#define BSC_open 0x040C0014
117#define BSC_close 0x040C0018
118#define BSC_link 0x040C0024
119#define BSC_unlink 0x040C0028
120#define BSC_mknod 0x040C0038
121#define BSC_chmod 0x040C003C
122#define BSC_chown 0x040C0040
123#define BSC_access 0x040C0084
124#define BSC_chflags 0x040C0088
125#define BSC_fchflags 0x040C008C
126#define BSC_sync 0x040C0090
127#define BSC_symlink 0x040C00E4
128#define BSC_readlink 0x040C00E8
129#define BSC_fsync 0x040C017C
130#define BSC_readv 0x040C01E0
131#define BSC_writev 0x040C01E4
132#define BSC_fchown 0x040C01EC
133#define BSC_fchmod 0x040C01F0
134#define BSC_rename 0x040C0200
135#define BSC_mkdir 0x040C0220
136#define BSC_rmdir 0x040C0224
137#define BSC_statfs 0x040C0274
138#define BSC_fstatfs 0x040C0278
139#define BSC_stat 0x040C02F0
140#define BSC_fstat 0x040C02F4
141#define BSC_lstat 0x040C02F8
142#define BSC_pathconf 0x040C02FC
143#define BSC_fpathconf 0x040C0300
144#define BSC_getdirentries 0x040C0310
145#define BSC_mmap 0x040c0314
146#define BSC_lseek 0x040c031c
147#define BSC_truncate 0x040C0320
148#define BSC_ftruncate 0x040C0324
149#define BSC_statv 0x040C0364
150#define BSC_lstatv 0x040C0368
151#define BSC_fstatv 0x040C036C
152#define BSC_mkcomplex 0x040C0360
153#define BSC_getattrlist 0x040C0370
154#define BSC_setattrlist 0x040C0374
155#define BSC_getdirentriesattr 0x040C0378
156#define BSC_exchangedata 0x040C037C
157#define BSC_checkuseraccess 0x040C0380
158#define BSC_searchfs 0x040C0384
159
160// Carbon File Manager support
161#define FILEMGR_PBGETCATALOGINFO 0x1e000020
162#define FILEMGR_PBGETCATALOGINFOBULK 0x1e000024
163#define FILEMGR_PBCREATEFILEUNICODE 0x1e000028
164#define FILEMGR_PBCREATEDIRECTORYUNICODE 0x1e00002c
165#define FILEMGR_PBCREATEFORK 0x1e000030
166#define FILEMGR_PBDELETEFORK 0x1e000034
167#define FILEMGR_PBITERATEFORK 0x1e000038
168#define FILEMGR_PBOPENFORK 0x1e00003c
169#define FILEMGR_PBREADFORK 0x1e000040
170#define FILEMGR_PBWRITEFORK 0x1e000044
171#define FILEMGR_PBALLOCATEFORK 0x1e000048
172#define FILEMGR_PBDELETEOBJECT 0x1e00004c
173#define FILEMGR_PBEXCHANGEOBJECT 0x1e000050
174#define FILEMGR_PBGETFORKCBINFO 0x1e000054
175#define FILEMGR_PBGETVOLUMEINFO 0x1e000058
176#define FILEMGR_PBMAKEFSREF 0x1e00005c
177#define FILEMGR_PBMAKEFSREFUNICODE 0x1e000060
178#define FILEMGR_PBMOVEOBJECT 0x1e000064
179#define FILEMGR_PBOPENITERATOR 0x1e000068
180#define FILEMGR_PBRENAMEUNICODE 0x1e00006c
181#define FILEMGR_PBSETCATALOGINFO 0x1e000070
182#define FILEMGR_PBSETVOLUMEINFO 0x1e000074
183#define FILEMGR_FSREFMAKEPATH 0x1e000078
184#define FILEMGR_FSPATHMAKEREF 0x1e00007c
185
186#define FILEMGR_PBGETCATINFO 0x1e010000
187#define FILEMGR_PBGETCATINFOLITE 0x1e010004
188#define FILEMGR_PBHGETFINFO 0x1e010008
189#define FILEMGR_PBXGETVOLINFO 0x1e01000c
190#define FILEMGR_PBHCREATE 0x1e010010
191#define FILEMGR_PBHOPENDF 0x1e010014
192#define FILEMGR_PBHOPENRF 0x1e010018
193#define FILEMGR_PBHGETDIRACCESS 0x1e01001c
194#define FILEMGR_PBHSETDIRACCESS 0x1e010020
195#define FILEMGR_PBHMAPID 0x1e010024
196#define FILEMGR_PBHMAPNAME 0x1e010028
197#define FILEMGR_PBCLOSE 0x1e01002c
198#define FILEMGR_PBFLUSHFILE 0x1e010030
199#define FILEMGR_PBGETEOF 0x1e010034
200#define FILEMGR_PBSETEOF 0x1e010038
201#define FILEMGR_PBGETFPOS 0x1e01003c
202#define FILEMGR_PBREAD 0x1e010040
203#define FILEMGR_PBWRITE 0x1e010044
204#define FILEMGR_PBGETFCBINFO 0x1e010048
205#define FILEMGR_PBSETFINFO 0x1e01004c
206#define FILEMGR_PBALLOCATE 0x1e010050
207#define FILEMGR_PBALLOCCONTIG 0x1e010054
208#define FILEMGR_PBSETFPOS 0x1e010058
209#define FILEMGR_PBSETCATINFO 0x1e01005c
210#define FILEMGR_PBGETVOLPARMS 0x1e010060
211#define FILEMGR_PBSETVINFO 0x1e010064
212#define FILEMGR_PBMAKEFSSPEC 0x1e010068
213#define FILEMGR_PBHGETVINFO 0x1e01006c
214#define FILEMGR_PBCREATEFILEIDREF 0x1e010070
215#define FILEMGR_PBDELETEFILEIDREF 0x1e010074
216#define FILEMGR_PBRESOLVEFILEIDREF 0x1e010078
217#define FILEMGR_PBFLUSHVOL 0x1e01007c
218#define FILEMGR_PBHRENAME 0x1e010080
219#define FILEMGR_PBCATMOVE 0x1e010084
220#define FILEMGR_PBEXCHANGEFILES 0x1e010088
221#define FILEMGR_PBHDELETE 0x1e01008c
222#define FILEMGR_PBDIRCREATE 0x1e010090
223#define FILEMGR_PBCATSEARCH 0x1e010094
224#define FILEMGR_PBHSETFLOCK 0x1e010098
225#define FILEMGR_PBHRSTFLOCK 0x1e01009c
226#define FILEMGR_PBLOCKRANGE 0x1e0100a0
227#define FILEMGR_PBUNLOCKRANGE 0x1e0100a4
228
229
230#define FILEMGR_CLASS 0x1e
231
232#define MAX_PIDS 32
233int pids[MAX_PIDS];
234
235int num_of_pids = 0;
236int exclude_pids = 0;
237
238struct kinfo_proc *kp_buffer = 0;
239int kp_nentries = 0;
240
241#define SAMPLE_SIZE 60000
242
243#define DBG_ZERO_FILL_FAULT 1
244#define DBG_PAGEIN_FAULT 2
245#define DBG_COW_FAULT 3
246#define DBG_CACHE_HIT_FAULT 4
247
248#define DBG_FUNC_ALL (DBG_FUNC_START | DBG_FUNC_END)
249#define DBG_FUNC_MASK 0xfffffffc
250
251/* Default divisor */
252#define DIVISOR 16.6666 /* Trace divisor converts to microseconds */
253double divisor = DIVISOR;
254
255int mib[6];
256size_t needed;
257char *my_buffer;
258
259kbufinfo_t bufinfo = {0, 0, 0, 0};
260
261int total_threads = 0;
262kd_threadmap *mapptr = 0;
263
264int trace_enabled = 0;
265int set_remove_flag = 1;
266
267void set_numbufs();
268void set_init();
269void set_enable();
270void sample_sc();
271int quit();
272
273/*
274 * signal handlers
275 */
276
277void leave() /* exit under normal conditions -- INT handler */
278{
279 int i;
280 void set_enable();
281 void set_pidcheck();
282 void set_pidexclude();
283 void set_remove();
284
285 set_enable(0);
286
287 if (exclude_pids == 0) {
288 for (i = 0; i < num_of_pids; i++)
289 set_pidcheck(pids[i], 0);
290 }
291 else {
292 for (i = 0; i < num_of_pids; i++)
293 set_pidexclude(pids[i], 0);
294 }
295 set_remove();
296 exit(0);
297}
298
299
300void sigwinch()
301{
302 initscr();
303}
304
305int
306exit_usage(myname) {
307
308 fprintf(stderr, "Usage: %s [-e] [-w] [pid | cmd [pid | cmd]....]\n", myname);
309 fprintf(stderr, " -e exclude the pids specified from the sample\n");
310 fprintf(stderr, " -w force wider, detailed, output\n");
311 fprintf(stderr, " pid selects process(s) to sample\n");
312 fprintf(stderr, " cmd selects process(s) matching command string to sample\n");
313
314 exit(1);
315}
316
317
318main(argc, argv)
319 int argc;
320 char *argv[];
321{
322 char *myname = "fs_usage";
323 int i;
324 char ch;
325 void getdivisor();
326 void argtopid();
327 void set_remove();
328 void set_pidcheck();
329 void set_pidexclude();
330 int quit();
331
332 if ( geteuid() != 0 ) {
333 printf("'fs_usage' must be run as root...\n");
334 exit(1);
335 }
336
337 initscr();
338
339 /* get our name */
340 if (argc > 0) {
341 if ((myname = rindex(argv[0], '/')) == 0) {
342 myname = argv[0];
343 }
344 else {
345 myname++;
346 }
347 }
348
349 while ((ch = getopt(argc, argv, "ew")) != EOF) {
350 switch(ch) {
351 case 'e':
352 exclude_pids = 1;
353 break;
354 case 'w':
355 wideflag = 1;
356 break;
357 default:
358 exit_usage(myname);
359 }
360 }
361
362 argc -= optind;
363 argv += optind;
364
365 while (argc > 0 && num_of_pids < (MAX_PIDS - 1)) {
366 select_pid_mode++;
367 argtopid(argv[0]);
368 argc--;
369 argv++;
370 }
371
372 if (exclude_pids)
373 pids[num_of_pids++] = getpid();
374
375#if 0
376 for (i = 0; i < num_of_pids; i++)
377 {
378 if (exclude_pids)
379 printf("exclude pid %d\n", pids[i]);
380 else
381 printf("pid %d\n", pids[i]);
382 }
383#endif
384
385 /* set up signal handlers */
386 signal(SIGINT, leave);
387 signal(SIGQUIT, leave);
388 signal(SIGTERM, leave);
389 signal(SIGWINCH, sigwinch);
390
391 if ((my_buffer = malloc(SAMPLE_SIZE * sizeof(kd_buf))) == (char *)0)
392 quit("can't allocate memory for tracing info\n");
393
394 set_remove();
395 set_numbufs(SAMPLE_SIZE);
396 set_init();
397
398 if (exclude_pids == 0) {
399 for (i = 0; i < num_of_pids; i++)
400 set_pidcheck(pids[i], 1);
401 } else {
402 for (i = 0; i < num_of_pids; i++)
403 set_pidexclude(pids[i], 1);
404 }
405
406 if (select_pid_mode && !one_good_pid)
407 {
408 /*
409 An attempt to restrict output to a given
410 pid or command has failed. Exit gracefully
411 */
412 set_remove();
413 exit_usage(myname);
414 }
415
416 set_enable(1);
417 getdivisor();
418
419
420 /* main loop */
421
422 while (1) {
423 usleep(1000 * 50);
424
425 sample_sc();
426 }
427}
428
429void
430find_proc_names()
431{
432 size_t bufSize = 0;
433 struct kinfo_proc *kp;
434 int quit();
435
436 mib[0] = CTL_KERN;
437 mib[1] = KERN_PROC;
438 mib[2] = KERN_PROC_ALL;
439 mib[3] = 0;
440
441 if (sysctl(mib, 4, NULL, &bufSize, NULL, 0) < 0)
442 quit("trace facility failure, KERN_PROC_ALL\n");
443
444 if((kp = (struct kinfo_proc *)malloc(bufSize)) == (struct kinfo_proc *)0)
445 quit("can't allocate memory for proc buffer\n");
446
447 if (sysctl(mib, 4, kp, &bufSize, NULL, 0) < 0)
448 quit("trace facility failure, KERN_PROC_ALL\n");
449
450 kp_nentries = bufSize/ sizeof(struct kinfo_proc);
451 kp_buffer = kp;
452}
453
454
455struct th_info *find_thread(int thread, int type) {
456 struct th_info *ti;
457
458 for (ti = th_state; ti < &th_state[cur_max]; ti++) {
459 if (ti->thread == thread) {
460 if (type == ti->type)
461 return(ti);
462 if (ti->in_filemgr) {
463 if (type == -1)
464 return(ti);
465 continue;
466 }
467 if (type == 0)
468 return(ti);
469 }
470 }
471 return ((struct th_info *)0);
472}
473
474void
475set_enable(int val)
476{
477 mib[0] = CTL_KERN;
478 mib[1] = KERN_KDEBUG;
479 mib[2] = KERN_KDENABLE; /* protocol */
480 mib[3] = val;
481 mib[4] = 0;
482 mib[5] = 0; /* no flags */
483 if (sysctl(mib, 4, NULL, &needed, NULL, 0) < 0)
484 quit("trace facility failure, KERN_KDENABLE\n");
485
486 if (val)
487 trace_enabled = 1;
488 else
489 trace_enabled = 0;
490}
491
492void
493set_numbufs(int nbufs)
494{
495 mib[0] = CTL_KERN;
496 mib[1] = KERN_KDEBUG;
497 mib[2] = KERN_KDSETBUF;
498 mib[3] = nbufs;
499 mib[4] = 0;
500 mib[5] = 0; /* no flags */
501 if (sysctl(mib, 4, NULL, &needed, NULL, 0) < 0)
502 quit("trace facility failure, KERN_KDSETBUF\n");
503
504 mib[0] = CTL_KERN;
505 mib[1] = KERN_KDEBUG;
506 mib[2] = KERN_KDSETUP;
507 mib[3] = 0;
508 mib[4] = 0;
509 mib[5] = 0; /* no flags */
510 if (sysctl(mib, 3, NULL, &needed, NULL, 0) < 0)
511 quit("trace facility failure, KERN_KDSETUP\n");
512}
513
514void
515set_pidcheck(int pid, int on_off)
516{
517 kd_regtype kr;
518
519 kr.type = KDBG_TYPENONE;
520 kr.value1 = pid;
521 kr.value2 = on_off;
522 needed = sizeof(kd_regtype);
523 mib[0] = CTL_KERN;
524 mib[1] = KERN_KDEBUG;
525 mib[2] = KERN_KDPIDTR;
526 mib[3] = 0;
527 mib[4] = 0;
528 mib[5] = 0;
529
530 if (sysctl(mib, 3, &kr, &needed, NULL, 0) < 0) {
531 if (on_off == 1)
532 printf("pid %d does not exist\n", pid);
533 }
534 else {
535 one_good_pid++;
536 }
537}
538
539/*
540 on_off == 0 turns off pid exclusion
541 on_off == 1 turns on pid exclusion
542*/
543void
544set_pidexclude(int pid, int on_off)
545{
546 kd_regtype kr;
547
548 one_good_pid++;
549
550 kr.type = KDBG_TYPENONE;
551 kr.value1 = pid;
552 kr.value2 = on_off;
553 needed = sizeof(kd_regtype);
554 mib[0] = CTL_KERN;
555 mib[1] = KERN_KDEBUG;
556 mib[2] = KERN_KDPIDEX;
557 mib[3] = 0;
558 mib[4] = 0;
559 mib[5] = 0;
560
561 if (sysctl(mib, 3, &kr, &needed, NULL, 0) < 0) {
562 if (on_off == 1)
563 printf("pid %d does not exist\n", pid);
564 }
565}
566
567void
568get_bufinfo(kbufinfo_t *val)
569{
570 needed = sizeof (*val);
571 mib[0] = CTL_KERN;
572 mib[1] = KERN_KDEBUG;
573 mib[2] = KERN_KDGETBUF;
574 mib[3] = 0;
575 mib[4] = 0;
576 mib[5] = 0; /* no flags */
577
578 if (sysctl(mib, 3, val, &needed, 0, 0) < 0)
579 quit("trace facility failure, KERN_KDGETBUF\n");
580
581}
582
583void
584set_remove()
585{
586 extern int errno;
587
588 errno = 0;
589
590 mib[0] = CTL_KERN;
591 mib[1] = KERN_KDEBUG;
592 mib[2] = KERN_KDREMOVE; /* protocol */
593 mib[3] = 0;
594 mib[4] = 0;
595 mib[5] = 0; /* no flags */
596 if (sysctl(mib, 3, NULL, &needed, NULL, 0) < 0)
597 {
598 set_remove_flag = 0;
599
600 if (errno == EBUSY)
601 quit("the trace facility is currently in use...\n fs_usage, sc_usage, and latency use this feature.\n\n");
602 else
603 quit("trace facility failure, KERN_KDREMOVE\n");
604 }
605}
606
607void
608set_init()
609{ kd_regtype kr;
610
611 kr.type = KDBG_RANGETYPE;
612 kr.value1 = 0;
613 kr.value2 = -1;
614 needed = sizeof(kd_regtype);
615 mib[0] = CTL_KERN;
616 mib[1] = KERN_KDEBUG;
617 mib[2] = KERN_KDSETREG;
618 mib[3] = 0;
619 mib[4] = 0;
620 mib[5] = 0; /* no flags */
621
622 if (sysctl(mib, 3, &kr, &needed, NULL, 0) < 0)
623 quit("trace facility failure, KERN_KDSETREG\n");
624
625 mib[0] = CTL_KERN;
626 mib[1] = KERN_KDEBUG;
627 mib[2] = KERN_KDSETUP;
628 mib[3] = 0;
629 mib[4] = 0;
630 mib[5] = 0; /* no flags */
631
632 if (sysctl(mib, 3, NULL, &needed, NULL, 0) < 0)
633 quit("trace facility failure, KERN_KDSETUP\n");
634}
635
636void
637sample_sc()
638{
639 kd_buf *kd;
640 int i, count;
641 void read_command_map();
642 void create_map_entry();
643
644 /* Get kernel buffer information */
645 get_bufinfo(&bufinfo);
646
647 if (need_new_map) {
648 read_command_map();
649 need_new_map = 0;
650 }
651 needed = bufinfo.nkdbufs * sizeof(kd_buf);
652 mib[0] = CTL_KERN;
653 mib[1] = KERN_KDEBUG;
654 mib[2] = KERN_KDREADTR;
655 mib[3] = 0;
656 mib[4] = 0;
657 mib[5] = 0; /* no flags */
658
659 if (sysctl(mib, 3, my_buffer, &needed, NULL, 0) < 0)
660 quit("trace facility failure, KERN_KDREADTR\n");
661 count = needed;
662
663 if (bufinfo.flags & KDBG_WRAPPED) {
664 printf("buffer wrapped count = %d\n", count);
665
666 for (i = 0; i < cur_max; i++) {
667 th_state[i].thread = 0;
668 th_state[i].vfslookup = 0;
669 th_state[i].pathname[0] = 0;
670 }
671 cur_max = 0;
672 need_new_map = 1;
673
674 set_enable(0);
675 set_enable(1);
676 }
677 kd = (kd_buf *)my_buffer;
678#if 0
679 printf("READTR returned %d items\n", count);
680#endif
681 for (i = 0; i < count; i++) {
682 int debugid, thread;
683 int type, n;
684 long *sargptr;
685 unsigned long long now;
686 struct th_info *ti;
687 void enter_syscall();
688 void exit_syscall();
689 void kill_thread_map();
690
691 thread = kd[i].arg5 & KDBG_THREAD_MASK;
692 debugid = kd[i].debugid;
693 type = kd[i].debugid & DBG_FUNC_MASK;
694
695 switch (type) {
696
697 case TRACE_DATA_NEWTHREAD:
698
699 for (n = 0, ti = th_state; ti < &th_state[MAX_THREADS]; ti++, n++) {
700 if (ti->thread == 0)
701 break;
702 }
703 if (ti == &th_state[MAX_THREADS])
704 continue;
705 if (n >= cur_max)
706 cur_max = n + 1;
707
708 ti->thread = thread;
709 ti->child_thread = kd[i].arg1;
710 continue;
711
712 case TRACE_STRING_NEWTHREAD:
713 if ((ti = find_thread(thread, 0)) == (struct th_info *)0)
714 continue;
715 if (ti->child_thread == 0)
716 continue;
717 create_map_entry(ti->child_thread, (char *)&kd[i].arg1);
718
719 if (ti == &th_state[cur_max - 1])
720 cur_max--;
721 ti->child_thread = 0;
722 ti->thread = 0;
723 continue;
724
725 case TRACE_STRING_EXEC:
726 create_map_entry(thread, (char *)&kd[i].arg1);
727 continue;
728
729 case BSC_exit:
730 kill_thread_map(thread);
731 continue;
732
733 case MACH_sched:
734 case MACH_stkhandoff:
735 if (ti = find_thread(thread, 0))
736 ti->waited = 1;
737 continue;
738
739 case VFS_LOOKUP:
740 if ((ti = find_thread(thread, 0)) == (struct th_info *)0)
741 continue;
742
743 if (ti->vfslookup == 0) {
744 ti->vfslookup = 1;
745 memset(&ti->pathname[0], 0, 32);
746 sargptr = (long *)&ti->pathname[0];
747
748 *sargptr++ = kd[i].arg2;
749 *sargptr++ = kd[i].arg3;
750 *sargptr++ = kd[i].arg4;
751
752 } else if (ti->vfslookup == 1) {
753 ti->vfslookup = 2;
754
755 sargptr = (long *)&ti->pathname[12];
756 *sargptr++ = kd[i].arg1;
757 *sargptr++ = kd[i].arg2;
758 *sargptr++ = kd[i].arg3;
759 *sargptr++ = kd[i].arg4;
760 }
761 continue;
762 }
763 now = (((unsigned long long)kd[i].timestamp.tv_sec) << 32) |
764 (unsigned long long)((unsigned int)(kd[i].timestamp.tv_nsec));
765
766 if (debugid & DBG_FUNC_START) {
767 char *p;
768
769 switch (type) {
770 case FILEMGR_PBGETCATALOGINFO:
771 p = "GetCatalogInfo";
772 break;
773 case FILEMGR_PBGETCATALOGINFOBULK:
774 p = "GetCatalogInfoBulk";
775 break;
776 case FILEMGR_PBCREATEFILEUNICODE:
777 p = "CreateFileUnicode";
778 break;
779 case FILEMGR_PBCREATEDIRECTORYUNICODE:
780 p = "CreateDirectoryUnicode";
781 break;
782 case FILEMGR_PBCREATEFORK:
783 p = "PBCreateFork";
784 break;
785 case FILEMGR_PBDELETEFORK:
786 p = "PBDeleteFork";
787 break;
788 case FILEMGR_PBITERATEFORK:
789 p = "PBIterateFork";
790 break;
791 case FILEMGR_PBOPENFORK:
792 p = "PBOpenFork";
793 break;
794 case FILEMGR_PBREADFORK:
795 p = "PBReadFork";
796 break;
797 case FILEMGR_PBWRITEFORK:
798 p = "PBWriteFork";
799 break;
800 case FILEMGR_PBALLOCATEFORK:
801 p = "PBAllocateFork";
802 break;
803 case FILEMGR_PBDELETEOBJECT:
804 p = "PBDeleteObject";
805 break;
806 case FILEMGR_PBEXCHANGEOBJECT:
807 p = "PBExchangeObject";
808 break;
809 case FILEMGR_PBGETFORKCBINFO:
810 p = "PBGetForkCBInfo";
811 break;
812 case FILEMGR_PBGETVOLUMEINFO:
813 p = "PBGetVolumeInfo";
814 break;
815 case FILEMGR_PBMAKEFSREF:
816 p = "PBMakeFSRef";
817 break;
818 case FILEMGR_PBMAKEFSREFUNICODE:
819 p = "PBMakeFSRefUnicode";
820 break;
821 case FILEMGR_PBMOVEOBJECT:
822 p = "PBMoveObject";
823 break;
824 case FILEMGR_PBOPENITERATOR:
825 p = "PBOpenIterator";
826 break;
827 case FILEMGR_PBRENAMEUNICODE:
828 p = "PBRenameUnicode";
829 break;
830 case FILEMGR_PBSETCATALOGINFO:
831 p = "SetCatalogInfo";
832 break;
833 case FILEMGR_PBSETVOLUMEINFO:
834 p = "SetVolumeInfo";
835 break;
836 case FILEMGR_FSREFMAKEPATH:
837 p = "FSRefMakePath";
838 break;
839 case FILEMGR_FSPATHMAKEREF:
840 p = "FSPathMakeRef";
841 break;
842 // SPEC based calls
843 case FILEMGR_PBGETCATINFO:
844 p = "GetCatInfo";
845 break;
846 case FILEMGR_PBGETCATINFOLITE:
847 p = "GetCatInfoLite";
848 break;
849 case FILEMGR_PBHGETFINFO:
850 p = "PBHGetFInfo";
851 break;
852 case FILEMGR_PBXGETVOLINFO:
853 p = "PBXGetVolInfo";
854 break;
855 case FILEMGR_PBHCREATE:
856 p = "PBHCreate";
857 break;
858 case FILEMGR_PBHOPENDF:
859 p = "PBHOpenDF";
860 break;
861 case FILEMGR_PBHOPENRF:
862 p = "PBHOpenRF";
863 break;
864 case FILEMGR_PBHGETDIRACCESS:
865 p = "PBHGetDirAccess";
866 break;
867 case FILEMGR_PBHSETDIRACCESS:
868 p = "PBHSetDirAccess";
869 break;
870 case FILEMGR_PBHMAPID:
871 p = "PBHMapID";
872 break;
873 case FILEMGR_PBHMAPNAME:
874 p = "PBHMapName";
875 break;
876 case FILEMGR_PBCLOSE:
877 p = "PBClose";
878 break;
879 case FILEMGR_PBFLUSHFILE:
880 p = "PBFlushFile";
881 break;
882 case FILEMGR_PBGETEOF:
883 p = "PBGetEOF";
884 break;
885 case FILEMGR_PBSETEOF:
886 p = "PBSetEOF";
887 break;
888 case FILEMGR_PBGETFPOS:
889 p = "PBGetFPos";
890 break;
891 case FILEMGR_PBREAD:
892 p = "PBRead";
893 break;
894 case FILEMGR_PBWRITE:
895 p = "PBWrite";
896 break;
897 case FILEMGR_PBGETFCBINFO:
898 p = "PBGetFCBInfo";
899 break;
900 case FILEMGR_PBSETFINFO:
901 p = "PBSetFInfo";
902 break;
903 case FILEMGR_PBALLOCATE:
904 p = "PBAllocate";
905 break;
906 case FILEMGR_PBALLOCCONTIG:
907 p = "PBAllocContig";
908 break;
909 case FILEMGR_PBSETFPOS:
910 p = "PBSetFPos";
911 break;
912 case FILEMGR_PBSETCATINFO:
913 p = "PBSetCatInfo";
914 break;
915 case FILEMGR_PBGETVOLPARMS:
916 p = "PBGetVolParms";
917 break;
918 case FILEMGR_PBSETVINFO:
919 p = "PBSetVInfo";
920 break;
921 case FILEMGR_PBMAKEFSSPEC:
922 p = "PBMakeFSSpec";
923 break;
924 case FILEMGR_PBHGETVINFO:
925 p = "PBHGetVInfo";
926 break;
927 case FILEMGR_PBCREATEFILEIDREF:
928 p = "PBCreateFileIDRef";
929 break;
930 case FILEMGR_PBDELETEFILEIDREF:
931 p = "PBDeleteFileIDRef";
932 break;
933 case FILEMGR_PBRESOLVEFILEIDREF:
934 p = "PBResolveFileIDRef";
935 break;
936 case FILEMGR_PBFLUSHVOL:
937 p = "PBFlushVol";
938 break;
939 case FILEMGR_PBHRENAME:
940 p = "PBHRename";
941 break;
942 case FILEMGR_PBCATMOVE:
943 p = "PBCatMove";
944 break;
945 case FILEMGR_PBEXCHANGEFILES:
946 p = "PBExchangeFiles";
947 break;
948 case FILEMGR_PBHDELETE:
949 p = "PBHDelete";
950 break;
951 case FILEMGR_PBDIRCREATE:
952 p = "PBDirCreate";
953 break;
954 case FILEMGR_PBCATSEARCH:
955 p = "PBCatSearch";
956 break;
957 case FILEMGR_PBHSETFLOCK:
958 p = "PBHSetFlock";
959 break;
960 case FILEMGR_PBHRSTFLOCK:
961 p = "PBHRstFLock";
962 break;
963 case FILEMGR_PBLOCKRANGE:
964 p = "PBLockRange";
965 break;
966 case FILEMGR_PBUNLOCKRANGE:
967 p = "PBUnlockRange";
968 break;
969 default:
970 p = (char *)0;
971 break;
972 }
973 enter_syscall(thread, type, &kd[i], p, (double)now);
974 continue;
975 }
976 switch (type) {
977
978 case MACH_vmfault:
979 if (kd[i].arg2 == DBG_PAGEIN_FAULT)
980 exit_syscall("PAGE_IN", thread, type, 0, kd[i].arg1, 0, 2, (double)now);
981 else {
982 if (ti = find_thread(thread, type)) {
983 if (ti == &th_state[cur_max - 1])
984 cur_max--;
985 ti->thread = 0;
986 }
987 }
988 break;
989
990 case MSC_map_fd:
991 exit_syscall("map_fd", thread, type, kd[i].arg1, kd[i].arg2, 1, 0, (double)now);
992 break;
993
994 case BSC_mmap:
995 exit_syscall("mmap", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
996 break;
997
998 case BSC_recvmsg:
999 exit_syscall("recvmsg", thread, type, kd[i].arg1, kd[i].arg2, 1, 1, (double)now);
1000 break;
1001
1002 case BSC_sendmsg:
1003 exit_syscall("sendmsg", thread, type, kd[i].arg1, kd[i].arg2, 1, 1, (double)now);
1004 break;
1005
1006 case BSC_recvfrom:
1007 exit_syscall("recvfrom", thread, type, kd[i].arg1, kd[i].arg2, 1, 1, (double)now);
1008 break;
1009
1010 case BSC_sendto:
1011 exit_syscall("sendto", thread, type, kd[i].arg1, kd[i].arg2, 1, 1, (double)now);
1012 break;
1013
1014 case BSC_stat:
1015 exit_syscall("stat", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1016 break;
1017
1018 case BSC_open:
1019 exit_syscall("open", thread, type, kd[i].arg1, kd[i].arg2, 2, 0, (double)now);
1020 break;
1021
1022 case BSC_close:
1023 exit_syscall("close", thread, type, kd[i].arg1, kd[i].arg2, 1, 0, (double)now);
1024 break;
1025
1026 case BSC_read:
1027 exit_syscall("read", thread, type, kd[i].arg1, kd[i].arg2, 1, 1, (double)now);
1028 break;
1029
1030 case BSC_write:
1031 exit_syscall("write", thread, type, kd[i].arg1, kd[i].arg2, 1, 1, (double)now);
1032 break;
1033
1034 case BSC_fstat:
1035 exit_syscall("fstat", thread, type, kd[i].arg1, kd[i].arg2, 1, 0, (double)now);
1036 break;
1037
1038 case BSC_lstat:
1039 exit_syscall("lstat", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1040 break;
1041
1042 case BSC_link:
1043 exit_syscall("link", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1044 break;
1045
1046 case BSC_unlink:
1047 exit_syscall("unlink", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1048 break;
1049
1050 case BSC_mknod:
1051 exit_syscall("mknod", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1052 break;
1053
1054 case BSC_chmod:
1055 exit_syscall("chmod", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1056 break;
1057
1058 case BSC_chown:
1059 exit_syscall("chown", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1060 break;
1061
1062 case BSC_access:
1063 exit_syscall("access", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1064 break;
1065
1066 case BSC_chflags:
1067 exit_syscall("chflags", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1068 break;
1069
1070 case BSC_fchflags:
1071 exit_syscall("fchflags", thread, type, kd[i].arg1, kd[i].arg2, 1, 0, (double)now);
1072 break;
1073
1074 case BSC_sync:
1075 exit_syscall("sync", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1076 break;
1077
1078 case BSC_symlink:
1079 exit_syscall("symlink", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1080 break;
1081
1082 case BSC_readlink:
1083 exit_syscall("readlink", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1084 break;
1085
1086 case BSC_fsync:
1087 exit_syscall("fsync", thread, type, kd[i].arg1, kd[i].arg2, 1, 0, (double)now);
1088 break;
1089
1090 case BSC_readv:
1091 exit_syscall("readv", thread, type, kd[i].arg1, kd[i].arg2, 1, 1, (double)now);
1092 break;
1093
1094 case BSC_writev:
1095 exit_syscall("writev", thread, type, kd[i].arg1, kd[i].arg2, 1, 1, (double)now);
1096 break;
1097
1098 case BSC_fchown:
1099 exit_syscall("fchown", thread, type, kd[i].arg1, kd[i].arg2, 1, 0, (double)now);
1100 break;
1101
1102 case BSC_fchmod:
1103 exit_syscall("fchmod", thread, type, kd[i].arg1, kd[i].arg2, 1, 0, (double)now);
1104 break;
1105
1106 case BSC_rename:
1107 exit_syscall("rename", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1108 break;
1109
1110 case BSC_mkdir:
1111 exit_syscall("mkdir", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1112 break;
1113
1114 case BSC_rmdir:
1115 exit_syscall("rmdir", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1116 break;
1117
1118 case BSC_statfs:
1119 exit_syscall("statfs", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1120 break;
1121
1122 case BSC_fstatfs:
1123 exit_syscall("fstatfs", thread, type, kd[i].arg1, kd[i].arg2, 1, 0, (double)now);
1124 break;
1125
1126 case BSC_pathconf:
1127 exit_syscall("pathconf", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1128 break;
1129
1130 case BSC_fpathconf:
1131 exit_syscall("fpathconf", thread, type, kd[i].arg1, kd[i].arg2, 1, 0, (double)now);
1132 break;
1133
1134 case BSC_getdirentries:
1135 exit_syscall("getdirentries", thread, type, kd[i].arg1, kd[i].arg2, 1, 1, (double)now);
1136 break;
1137
1138 case BSC_lseek:
1139 exit_syscall("lseek", thread, type, kd[i].arg1, kd[i].arg3, 1, 5, (double)now);
1140 break;
1141
1142 case BSC_truncate:
1143 exit_syscall("truncate", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1144 break;
1145
1146 case BSC_ftruncate:
1147 exit_syscall("ftruncate", thread, type, kd[i].arg1, kd[i].arg2, 1, 3, (double)now);
1148 break;
1149
1150 case BSC_statv:
1151 exit_syscall("statv", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1152 break;
1153
1154 case BSC_lstatv:
1155 exit_syscall("lstatv", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1156 break;
1157
1158 case BSC_fstatv:
1159 exit_syscall("fstatv", thread, type, kd[i].arg1, kd[i].arg2, 1, 0, (double)now);
1160 break;
1161
1162 case BSC_mkcomplex:
1163 exit_syscall("mkcomplex", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1164 break;
1165
1166 case BSC_getattrlist:
1167 exit_syscall("getattrlist", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1168 break;
1169
1170 case BSC_setattrlist:
1171 exit_syscall("setattrlist", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1172 break;
1173
1174 case BSC_getdirentriesattr:
1175 exit_syscall("getdirentriesattr", thread, type, kd[i].arg1, kd[i].arg2, 0, 1, (double)now);
1176 break;
1177
1178 case BSC_exchangedata:
1179 exit_syscall("exchangedata", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1180 break;
1181
1182 case BSC_checkuseraccess:
1183 exit_syscall("checkuseraccess", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1184 break;
1185
1186 case BSC_searchfs:
1187 exit_syscall("searchfs", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1188 break;
1189
1190 case FILEMGR_PBGETCATALOGINFO:
1191 exit_syscall("GetCatalogInfo", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1192 break;
1193 case FILEMGR_PBGETCATALOGINFOBULK:
1194 exit_syscall("GetCatalogInfoBulk", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1195 break;
1196 case FILEMGR_PBCREATEFILEUNICODE:
1197 exit_syscall("CreateFileUnicode", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1198 break;
1199 case FILEMGR_PBCREATEDIRECTORYUNICODE:
1200 exit_syscall("CreateDirectoryUnicode", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1201 break;
1202 case FILEMGR_PBCREATEFORK:
1203 exit_syscall("PBCreateFork", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1204 break;
1205 case FILEMGR_PBDELETEFORK:
1206 exit_syscall("PBDeleteFork", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1207 break;
1208 case FILEMGR_PBITERATEFORK:
1209 exit_syscall("PBIterateFork", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1210 break;
1211 case FILEMGR_PBOPENFORK:
1212 exit_syscall("PBOpenFork", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1213 break;
1214 case FILEMGR_PBREADFORK:
1215 exit_syscall("PBReadFork", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1216 break;
1217 case FILEMGR_PBWRITEFORK:
1218 exit_syscall("PBWriteFork", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1219 break;
1220 case FILEMGR_PBALLOCATEFORK:
1221 exit_syscall("PBAllocateFork", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1222 break;
1223 case FILEMGR_PBDELETEOBJECT:
1224 exit_syscall("PBDeleteObject", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1225 break;
1226 case FILEMGR_PBEXCHANGEOBJECT:
1227 exit_syscall("PBExchangeObject", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1228 break;
1229 case FILEMGR_PBGETFORKCBINFO:
1230 exit_syscall("PBGetForkCBInfo", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1231 break;
1232 case FILEMGR_PBGETVOLUMEINFO:
1233 exit_syscall("PBGetVolumeInfo", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1234 break;
1235 case FILEMGR_PBMAKEFSREF:
1236 exit_syscall("PBMakeFSRef", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1237 break;
1238 case FILEMGR_PBMAKEFSREFUNICODE:
1239 exit_syscall("PBMakeFSRefUnicode", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1240 break;
1241 case FILEMGR_PBMOVEOBJECT:
1242 exit_syscall("PBMoveObject", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1243 break;
1244 case FILEMGR_PBOPENITERATOR:
1245 exit_syscall("PBOpenIterator", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1246 break;
1247 case FILEMGR_PBRENAMEUNICODE:
1248 exit_syscall("PBRenameUnicode", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1249 break;
1250 case FILEMGR_PBSETCATALOGINFO:
1251 exit_syscall("PBSetCatalogInfo", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1252 break;
1253 case FILEMGR_PBSETVOLUMEINFO:
1254 exit_syscall("PBSetVolumeInfo", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1255 break;
1256 case FILEMGR_FSREFMAKEPATH:
1257 exit_syscall("FSRefMakePath", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1258 break;
1259 case FILEMGR_FSPATHMAKEREF:
1260 exit_syscall("FSPathMakeRef", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1261 break;
1262 case FILEMGR_PBGETCATINFO:
1263 exit_syscall("GetCatInfo", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1264 break;
1265 case FILEMGR_PBGETCATINFOLITE:
1266 exit_syscall("GetCatInfoLite", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1267 break;
1268 case FILEMGR_PBHGETFINFO:
1269 exit_syscall("PBHGetFInfo", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1270 break;
1271 case FILEMGR_PBXGETVOLINFO:
1272 exit_syscall("PBXGetVolInfo", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1273 break;
1274 case FILEMGR_PBHCREATE:
1275 exit_syscall("PBHCreate", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1276 break;
1277 case FILEMGR_PBHOPENDF:
1278 exit_syscall("PBHOpenDF", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1279 break;
1280 case FILEMGR_PBHOPENRF:
1281 exit_syscall("PBHOpenRF", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1282 break;
1283 case FILEMGR_PBHGETDIRACCESS:
1284 exit_syscall("PBHGetDirAccess", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1285 break;
1286 case FILEMGR_PBHSETDIRACCESS:
1287 exit_syscall("PBHSetDirAccess", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1288 break;
1289 case FILEMGR_PBHMAPID:
1290 exit_syscall("PBHMapID", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1291 break;
1292 case FILEMGR_PBHMAPNAME:
1293 exit_syscall("PBHMapName", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1294 break;
1295 case FILEMGR_PBCLOSE:
1296 exit_syscall("PBClose", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1297 break;
1298 case FILEMGR_PBFLUSHFILE:
1299 exit_syscall("PBFlushFile", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1300 break;
1301 case FILEMGR_PBGETEOF:
1302 exit_syscall("PBGetEOF", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1303 break;
1304 case FILEMGR_PBSETEOF:
1305 exit_syscall("PBSetEOF", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1306 break;
1307 case FILEMGR_PBGETFPOS:
1308 exit_syscall("PBGetFPos", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1309 break;
1310 case FILEMGR_PBREAD:
1311 exit_syscall("PBRead", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1312 break;
1313 case FILEMGR_PBWRITE:
1314 exit_syscall("PBWrite", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1315 break;
1316 case FILEMGR_PBGETFCBINFO:
1317 exit_syscall("PBGetFCBInfo", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1318 break;
1319 case FILEMGR_PBSETFINFO:
1320 exit_syscall("PBSetFInfo", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1321 break;
1322 case FILEMGR_PBALLOCATE:
1323 exit_syscall("PBAllocate", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1324 break;
1325 case FILEMGR_PBALLOCCONTIG:
1326 exit_syscall("PBAllocContig", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1327 break;
1328 case FILEMGR_PBSETFPOS:
1329 exit_syscall("PBSetFPos", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1330 break;
1331 case FILEMGR_PBSETCATINFO:
1332 exit_syscall("PBSetCatInfo", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1333 break;
1334 case FILEMGR_PBGETVOLPARMS:
1335 exit_syscall("PBGetVolParms", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1336 break;
1337 case FILEMGR_PBSETVINFO:
1338 exit_syscall("PBSetVInfo", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1339 break;
1340 case FILEMGR_PBMAKEFSSPEC:
1341 exit_syscall("PBMakeFSSpec", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1342 break;
1343 case FILEMGR_PBHGETVINFO:
1344 exit_syscall("PBHGetVInfo", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1345 break;
1346 case FILEMGR_PBCREATEFILEIDREF:
1347 exit_syscall("PBCreateFileIDRef", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1348 break;
1349 case FILEMGR_PBDELETEFILEIDREF:
1350 exit_syscall("PBDeleteFileIDRef", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1351 break;
1352 case FILEMGR_PBRESOLVEFILEIDREF:
1353 exit_syscall("PBResolveFileIDRef", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1354 break;
1355 case FILEMGR_PBFLUSHVOL:
1356 exit_syscall("PBFlushVol", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1357 break;
1358 case FILEMGR_PBHRENAME:
1359 exit_syscall("PBHRename", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1360 break;
1361 case FILEMGR_PBCATMOVE:
1362 exit_syscall("PBCatMove", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1363 break;
1364 case FILEMGR_PBEXCHANGEFILES:
1365 exit_syscall("PBExchangeFiles", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1366 break;
1367 case FILEMGR_PBHDELETE:
1368 exit_syscall("PBHDelete", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1369 break;
1370 case FILEMGR_PBDIRCREATE:
1371 exit_syscall("PBDirCreate", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1372 break;
1373 case FILEMGR_PBCATSEARCH:
1374 exit_syscall("PBCatSearch", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1375 break;
1376 case FILEMGR_PBHSETFLOCK:
1377 exit_syscall("PBHSetFLock", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1378 break;
1379 case FILEMGR_PBHRSTFLOCK:
1380 exit_syscall("PBHRstFLock", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1381 break;
1382 case FILEMGR_PBLOCKRANGE:
1383 exit_syscall("PBLockRange", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1384 break;
1385 case FILEMGR_PBUNLOCKRANGE:
1386 exit_syscall("PBUnlockRange", thread, type, kd[i].arg1, kd[i].arg2, 0, 0, (double)now);
1387 break;
1388 default:
1389 break;
1390 }
1391 }
1392 fflush(0);
1393}
1394
1395void
1396enter_syscall(int thread, int type, kd_buf *kd, char *name, double now)
1397{
1398 struct th_info *ti;
1399 int i;
1400 int secs;
1401 int usecs;
1402 long long l_usecs;
1403 long curr_time;
1404 kd_threadmap *map;
1405 kd_threadmap *find_thread_map();
1406
1407 switch (type) {
1408
1409 case MACH_vmfault:
1410 case MSC_map_fd:
1411 case BSC_mmap:
1412 case BSC_recvmsg:
1413 case BSC_sendmsg:
1414 case BSC_recvfrom:
1415 case BSC_sendto:
1416 case BSC_stat:
1417 case BSC_open:
1418 case BSC_close:
1419 case BSC_read:
1420 case BSC_write:
1421 case BSC_fstat:
1422 case BSC_lstat:
1423 case BSC_link:
1424 case BSC_unlink:
1425 case BSC_mknod:
1426 case BSC_chmod:
1427 case BSC_chown:
1428 case BSC_access:
1429 case BSC_chflags:
1430 case BSC_fchflags:
1431 case BSC_sync:
1432 case BSC_symlink:
1433 case BSC_readlink:
1434 case BSC_fsync:
1435 case BSC_readv:
1436 case BSC_writev:
1437 case BSC_fchown:
1438 case BSC_fchmod:
1439 case BSC_rename:
1440 case BSC_mkdir:
1441 case BSC_rmdir:
1442 case BSC_statfs:
1443 case BSC_fstatfs:
1444 case BSC_pathconf:
1445 case BSC_fpathconf:
1446 case BSC_getdirentries:
1447 case BSC_lseek:
1448 case BSC_truncate:
1449 case BSC_ftruncate:
1450 case BSC_statv:
1451 case BSC_lstatv:
1452 case BSC_fstatv:
1453 case BSC_mkcomplex:
1454 case BSC_getattrlist:
1455 case BSC_setattrlist:
1456 case BSC_getdirentriesattr:
1457 case BSC_exchangedata:
1458 case BSC_checkuseraccess:
1459 case BSC_searchfs:
1460 case FILEMGR_PBGETCATALOGINFO:
1461 case FILEMGR_PBGETCATALOGINFOBULK:
1462 case FILEMGR_PBCREATEFILEUNICODE:
1463 case FILEMGR_PBCREATEDIRECTORYUNICODE:
1464 case FILEMGR_PBCREATEFORK:
1465 case FILEMGR_PBDELETEFORK:
1466 case FILEMGR_PBITERATEFORK:
1467 case FILEMGR_PBOPENFORK:
1468 case FILEMGR_PBREADFORK:
1469 case FILEMGR_PBWRITEFORK:
1470 case FILEMGR_PBALLOCATEFORK:
1471 case FILEMGR_PBDELETEOBJECT:
1472 case FILEMGR_PBEXCHANGEOBJECT:
1473 case FILEMGR_PBGETFORKCBINFO:
1474 case FILEMGR_PBGETVOLUMEINFO:
1475 case FILEMGR_PBMAKEFSREF:
1476 case FILEMGR_PBMAKEFSREFUNICODE:
1477 case FILEMGR_PBMOVEOBJECT:
1478 case FILEMGR_PBOPENITERATOR:
1479 case FILEMGR_PBRENAMEUNICODE:
1480 case FILEMGR_PBSETCATALOGINFO:
1481 case FILEMGR_PBSETVOLUMEINFO:
1482 case FILEMGR_FSREFMAKEPATH:
1483 case FILEMGR_FSPATHMAKEREF:
1484
1485 case FILEMGR_PBGETCATINFO:
1486 case FILEMGR_PBGETCATINFOLITE:
1487 case FILEMGR_PBHGETFINFO:
1488 case FILEMGR_PBXGETVOLINFO:
1489 case FILEMGR_PBHCREATE:
1490 case FILEMGR_PBHOPENDF:
1491 case FILEMGR_PBHOPENRF:
1492 case FILEMGR_PBHGETDIRACCESS:
1493 case FILEMGR_PBHSETDIRACCESS:
1494 case FILEMGR_PBHMAPID:
1495 case FILEMGR_PBHMAPNAME:
1496 case FILEMGR_PBCLOSE:
1497 case FILEMGR_PBFLUSHFILE:
1498 case FILEMGR_PBGETEOF:
1499 case FILEMGR_PBSETEOF:
1500 case FILEMGR_PBGETFPOS:
1501 case FILEMGR_PBREAD:
1502 case FILEMGR_PBWRITE:
1503 case FILEMGR_PBGETFCBINFO:
1504 case FILEMGR_PBSETFINFO:
1505 case FILEMGR_PBALLOCATE:
1506 case FILEMGR_PBALLOCCONTIG:
1507 case FILEMGR_PBSETFPOS:
1508 case FILEMGR_PBSETCATINFO:
1509 case FILEMGR_PBGETVOLPARMS:
1510 case FILEMGR_PBSETVINFO:
1511 case FILEMGR_PBMAKEFSSPEC:
1512 case FILEMGR_PBHGETVINFO:
1513 case FILEMGR_PBCREATEFILEIDREF:
1514 case FILEMGR_PBDELETEFILEIDREF:
1515 case FILEMGR_PBRESOLVEFILEIDREF:
1516 case FILEMGR_PBFLUSHVOL:
1517 case FILEMGR_PBHRENAME:
1518 case FILEMGR_PBCATMOVE:
1519 case FILEMGR_PBEXCHANGEFILES:
1520 case FILEMGR_PBHDELETE:
1521 case FILEMGR_PBDIRCREATE:
1522 case FILEMGR_PBCATSEARCH:
1523 case FILEMGR_PBHSETFLOCK:
1524 case FILEMGR_PBHRSTFLOCK:
1525 case FILEMGR_PBLOCKRANGE:
1526 case FILEMGR_PBUNLOCKRANGE:
1527
1528
1529 for (i = 0, ti = th_state; ti < &th_state[MAX_THREADS]; ti++, i++) {
1530 if (ti->thread == 0)
1531 break;
1532 }
1533 if (ti == &th_state[MAX_THREADS])
1534 return;
1535 if (i >= cur_max)
1536 cur_max = i + 1;
1537
1538 if ((type >> 24) == FILEMGR_CLASS) {
1539 ti->in_filemgr = 1;
1540
1541 l_usecs = (long long)(now / divisor);
1542 secs = l_usecs / 1000000;
1543
1544 if (bias_secs == 0) {
1545 curr_time = time((long *)0);
1546 bias_secs = curr_time - secs;
1547 }
1548 curr_time = bias_secs + secs;
1549 printf("%-8.8s", &(ctime(&curr_time)[11]));
1550
1551 if (COLS > 110 || wideflag) {
1552 usecs = l_usecs - (long long)((long long)secs * 1000000);
1553 printf(".%03ld", (long)usecs / 1000);
1554 }
1555 map = find_thread_map(thread);
1556 if (map) {
1557 char buf[128];
1558 int clen;
1559
1560 sprintf(buf, " %s", name);
1561 clen = strlen(buf);
1562
1563 if (clen > 25)
1564 clen = 25;
1565 memset(&buf[clen], ' ', 26 - clen);
1566
1567 sprintf(&buf[25], "(%d, 0x%x, 0x%x, 0x%x)", (short)kd->arg1, kd->arg2, kd->arg3, kd->arg4);
1568 clen = strlen(&buf[25]) + 25;
1569 memset(&buf[clen], ' ', 128 - clen);
1570
1571 if (COLS > 110 || wideflag)
1572 sprintf(&buf[81], "%s\n", map->command);
1573 else
1574 sprintf(&buf[60], "%.12s\n", map->command);
1575
1576 printf(buf);
1577
1578 } else
1579 printf(" %-24.24s (%5d, %#x, 0x%x, 0x%x)\n", name, (short)kd->arg1, kd->arg2, kd->arg3, kd->arg4);
1580
1581 } else {
1582 ti->in_filemgr = 0;
1583 }
1584 ti->thread = thread;
1585 ti->vfslookup = 0;
1586 ti->waited = 0;
1587 ti->type = type;
1588 ti->stime = now;
1589 ti->arg1 = kd->arg1;
1590 ti->arg2 = kd->arg2;
1591 ti->arg3 = kd->arg3;
1592 ti->arg4 = kd->arg4;
1593 ti->pathname[0] = 0;
1594
1595 break;
1596
1597 default:
1598 break;
1599 }
1600}
1601
1602
1603void
1604exit_syscall(char *sc_name, int thread, int type, int error, int retval,
1605 int has_fd, int has_ret, double now)
1606{
1607 struct th_info *ti;
1608 int secs;
1609 int usecs;
1610 int nopadding;
1611 long long l_usecs;
1612 long curr_time;
1613 kd_threadmap *map;
1614 kd_threadmap *find_thread_map();
1615
1616 if ((ti = find_thread(thread, type)) == (struct th_info *)0)
1617 return;
1618 map = find_thread_map(thread);
1619 l_usecs = (long long)(now / divisor);
1620 secs = l_usecs / 1000000;
1621
1622 if (bias_secs == 0) {
1623 curr_time = time((long *)0);
1624 bias_secs = curr_time - secs;
1625 }
1626 curr_time = bias_secs + secs;
1627 printf("%-8.8s", &(ctime(&curr_time)[11]));
1628
1629
1630 if (COLS > 110 || wideflag) {
1631 nopadding = 0;
1632 usecs = l_usecs - (long long)((long long)secs * 1000000);
1633 printf(".%03ld", (long)usecs / 1000);
1634
1635 if ((type >> 24) != FILEMGR_CLASS) {
1636 if (find_thread(thread, -1)) {
1637 printf(" ");
1638 nopadding = 1;
1639 }
1640 }
1641 } else
1642 nopadding = 1;
1643
1644 if (((type >> 24) == FILEMGR_CLASS) && (COLS > 110 || wideflag))
1645 printf(" %-18.18s", sc_name);
1646 else
1647 printf(" %-15.15s", sc_name);
1648
1649 if (COLS > 110 || wideflag) {
1650 if (has_fd == 2 && error == 0)
1651 printf(" F=%-3d", retval);
1652 else if (has_fd == 1)
1653 printf(" F=%-3d", ti->arg1);
1654 else if (has_ret != 2)
1655 printf(" ");
1656
1657 if (error)
1658 printf("[%3d] ", error);
1659 else if (has_ret == 3)
1660 printf("O=0x%8.8x", ti->arg3);
1661 else if (has_ret == 5)
1662 printf("O=0x%8.8x", retval);
1663 else if (has_ret == 2)
1664 printf(" A=0x%8.8x ", retval);
1665 else if (has_ret == 1)
1666 printf(" B=0x%-6x", retval);
1667 else if (has_ret == 4)
1668 printf("R=0x%-8x", retval);
1669 else
1670 printf(" ");
1671 }
1672 printf(" %-28.28s ", ti->pathname);
1673
1674 usecs = (unsigned long)(((double)now - ti->stime) / divisor);
1675 secs = usecs / 1000000;
1676 usecs -= secs * 1000000;
1677
1678 if ((type >> 24) != FILEMGR_CLASS && !nopadding)
1679 printf(" ");
1680
1681 printf(" %2ld.%06ld", (long)secs, (long)usecs);
1682 if (ti->waited)
1683 printf(" W");
1684 else
1685 printf(" ");
1686
1687 if (map) {
1688 if (COLS > 110 || wideflag)
1689 printf(" %s", map->command);
1690 else
1691 printf(" %.12s", map->command);
1692 }
1693 printf("\n");
1694
1695 if (ti == &th_state[cur_max - 1])
1696 cur_max--;
1697 ti->thread = 0;
1698}
1699
1700int
1701quit(s)
1702char *s;
1703{
1704 if (trace_enabled)
1705 set_enable(0);
1706
1707 /*
1708 This flag is turned off when calling
1709 quit() due to a set_remove() failure.
1710 */
1711 if (set_remove_flag)
1712 set_remove();
1713
1714 printf("fs_usage: ");
1715 if (s)
1716 printf("%s", s);
1717
1718 exit(1);
1719}
1720
1721
1722void getdivisor()
1723{
1724
1725 unsigned int delta;
1726 unsigned int abs_to_ns_num;
1727 unsigned int abs_to_ns_denom;
1728 unsigned int proc_to_abs_num;
1729 unsigned int proc_to_abs_denom;
1730
1731 extern void MKGetTimeBaseInfo(unsigned int *, unsigned int *, unsigned int *, unsigned int *, unsigned int *);
1732
1733 MKGetTimeBaseInfo (&delta, &abs_to_ns_num, &abs_to_ns_denom,
1734 &proc_to_abs_num, &proc_to_abs_denom);
1735
1736 divisor = ((double)abs_to_ns_denom / (double)abs_to_ns_num) * 1000;
1737}
1738
1739
1740void read_command_map()
1741{
1742 size_t size;
1743 int mib[6];
1744
1745 if (mapptr) {
1746 free(mapptr);
1747 mapptr = 0;
1748 }
1749 total_threads = bufinfo.nkdthreads;
1750 size = bufinfo.nkdthreads * sizeof(kd_threadmap);
1751
1752 if (size)
1753 {
1754 if (mapptr = (kd_threadmap *) malloc(size))
1755 bzero (mapptr, size);
1756 else
1757 {
1758 printf("Thread map is not initialized -- this is not fatal\n");
1759 return;
1760 }
1761 }
1762
1763 /* Now read the threadmap */
1764 mib[0] = CTL_KERN;
1765 mib[1] = KERN_KDEBUG;
1766 mib[2] = KERN_KDTHRMAP;
1767 mib[3] = 0;
1768 mib[4] = 0;
1769 mib[5] = 0; /* no flags */
1770 if (sysctl(mib, 3, mapptr, &size, NULL, 0) < 0)
1771 {
1772 /* This is not fatal -- just means I cant map command strings */
1773
1774 printf("Can't read the thread map -- this is not fatal\n");
1775 free(mapptr);
1776 mapptr = 0;
1777 return;
1778 }
1779 return;
1780}
1781
1782
1783void create_map_entry(int thread, char *command)
1784{
1785 int i, n;
1786 kd_threadmap *map;
1787
1788 if (!mapptr)
1789 return;
1790
1791 for (i = 0, map = 0; !map && i < total_threads; i++)
1792 {
1793 if (mapptr[i].thread == thread )
1794 map = &mapptr[i]; /* Reuse this entry, the thread has been reassigned */
1795 }
1796
1797 if (!map) /* look for invalid entries that I can reuse*/
1798 {
1799 for (i = 0, map = 0; !map && i < total_threads; i++)
1800 {
1801 if (mapptr[i].valid == 0 )
1802 map = &mapptr[i]; /* Reuse this invalid entry */
1803 }
1804 }
1805
1806 if (!map)
1807 {
1808 /* If reach here, then this is a new thread and
1809 * there are no invalid entries to reuse
1810 * Double the size of the thread map table.
1811 */
1812
1813 n = total_threads * 2;
1814 mapptr = (kd_threadmap *) realloc(mapptr, n * sizeof(kd_threadmap));
1815 bzero(&mapptr[total_threads], total_threads*sizeof(kd_threadmap));
1816 map = &mapptr[total_threads];
1817 total_threads = n;
1818 }
1819
1820 map->valid = 1;
1821 map->thread = thread;
1822 (void)strncpy (map->command, command, sizeof(map->command));
1823 map->command[sizeof(map->command)-1] = '\0';
1824}
1825
1826
1827kd_threadmap *find_thread_map(int thread)
1828{
1829 int i;
1830 kd_threadmap *map;
1831
1832 if (!mapptr)
1833 return((kd_threadmap *)0);
1834
1835 for (i = 0; i < total_threads; i++)
1836 {
1837 map = &mapptr[i];
1838 if (map->valid && (map->thread == thread))
1839 {
1840 return(map);
1841 }
1842 }
1843 return ((kd_threadmap *)0);
1844}
1845
1846
1847void
1848kill_thread_map(int thread)
1849{
1850 kd_threadmap *map;
1851
1852 if (map = find_thread_map(thread)) {
1853 map->valid = 0;
1854 map->thread = 0;
1855 map->command[0] = '\0';
1856 }
1857}
1858
1859void
1860argtopid(str)
1861 char *str;
1862{
1863 char *cp;
1864 int ret;
1865 int i;
1866
1867 ret = (int)strtol(str, &cp, 10);
1868 if (cp == str || *cp) {
1869 /* Assume this is a command string and find matching pids */
1870 if (!kp_buffer)
1871 find_proc_names();
1872
1873 for (i=0; i < kp_nentries && num_of_pids < (MAX_PIDS - 1); i++) {
1874 if(kp_buffer[i].kp_proc.p_stat == 0)
1875 continue;
1876 else {
1877 if(!strcmp(str, kp_buffer[i].kp_proc.p_comm))
1878 pids[num_of_pids++] = kp_buffer[i].kp_proc.p_pid;
1879 }
1880 }
1881 }
1882 else if (num_of_pids < (MAX_PIDS - 1))
1883 pids[num_of_pids++] = ret;
1884
1885 return;
1886}
1887
1888