2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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
22 * @APPLE_LICENSE_HEADER_END@
26 cc -I/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders -DPRIVATE -D__APPLE_PRIVATE -arch x86_64 -arch i386 -O -o fs_usage fs_usage.c
44 #include <sys/types.h>
45 #include <sys/param.h>
47 #include <sys/ioctl.h>
48 #include <sys/socket.h>
50 #include <sys/sysctl.h>
53 #ifndef KERNEL_PRIVATE
54 #define KERNEL_PRIVATE
55 #include <sys/kdebug.h>
58 #include <sys/kdebug.h>
59 #endif /*KERNEL_PRIVATE*/
61 #import <mach/clock_types.h>
62 #import <mach/mach_time.h>
66 #define F_OPENFROM 56 /* SPI: open a file relative to fd (must be a dir) */
67 #define F_UNLINKFROM 57 /* SPI: open a file relative to fd (must be a dir) */
68 #define F_CHECK_OPENEVT 58 /* SPI: if a process is marked OPENEVT, or in O_EVTONLY on opens of this vnode */
79 #define RAW_VERSION0 0x55aa0000
80 #define RAW_VERSION1 0x55aa0101
86 typedef struct LibraryRange
{
91 LibraryRange framework32
;
92 LibraryRange framework64
;
104 char *frameworkType
[] = {
115 typedef struct LibraryInfo
{
122 LibraryInfo frameworkInfo
[MAXINDEX
];
123 int numFrameworks
= 0;
127 * MAXCOLS controls when extra data kicks in.
128 * MAX_WIDE_MODE_COLS controls -w mode to get even wider data in path.
129 * If NUMPARMS changes to match the kernel, it will automatically
130 * get reflected in the -w mode output.
133 #define PATHLENGTH (NUMPARMS*sizeof(uintptr_t))
136 #define MAX_WIDE_MODE_COLS (PATHLENGTH + 80)
137 #define MAXWIDTH MAX_WIDE_MODE_COLS + 64
140 typedef struct th_info
*th_info_t
;
145 uintptr_t child_thread
;
161 uintptr_t pathname
[NUMPARMS
+ 1]; /* add room for null terminator */
162 uintptr_t pathname2
[NUMPARMS
+ 1]; /* add room for null terminator */
166 typedef struct threadmap
* threadmap_t
;
172 unsigned int tm_setsize
; /* this is a bit count */
173 unsigned long *tm_setptr
; /* file descripter bitmap */
174 char tm_command
[MAXCOMLEN
+ 1];
178 #define HASH_SIZE 1024
179 #define HASH_MASK 1023
181 th_info_t th_info_hash
[HASH_SIZE
];
182 th_info_t th_info_freelist
;
184 threadmap_t threadmap_hash
[HASH_SIZE
];
185 threadmap_t threadmap_freelist
;
188 int filemgr_in_progress
= 0;
189 int need_new_map
= 1;
195 int one_good_pid
= 0; /* Used to fail gracefully when bad pids given */
196 int select_pid_mode
= 0; /* Flag set indicates that output is restricted
197 to selected pids or commands */
204 #define USLEEP_BEHIND 2
205 #define USLEEP_MAX 32
206 int usleep_ms
= USLEEP_MIN
;
209 * Network only or filesystem only output filter
210 * Default of zero means report all activity - no filtering
212 #define FILESYS_FILTER 0x01
213 #define NETWORK_FILTER 0x02
214 #define CACHEHIT_FILTER 0x04
215 #define EXEC_FILTER 0x08
216 #define PATHNAME_FILTER 0x10
217 #define DEFAULT_DO_NOT_FILTER 0x00
219 int filter_mode
= CACHEHIT_FILTER
;
225 struct diskrec
*next
;
239 uintptr_t issuing_thread
;
240 uintptr_t completion_thread
;
241 char issuing_command
[MAXCOMLEN
];
243 double completed_time
;
246 struct diskrec
*disk_list
= NULL
;
247 struct diskio
*free_diskios
= NULL
;
248 struct diskio
*busy_diskios
= NULL
;
251 struct diskio
*insert_diskio();
252 struct diskio
*complete_diskio();
256 int check_filter_mode(struct th_info
*, int, int, int, char *);
257 void format_print(struct th_info
*, char *, uintptr_t, int, int, int, int, int, int, double, double, int, char *, struct diskio
*);
258 void enter_event_now(uintptr_t, int, kd_buf
*, char *, double);
259 void enter_event(uintptr_t, int, kd_buf
*, char *, double);
260 void exit_event(char *, uintptr_t, int, int, int, int, int, int, double);
261 void extend_syscall(uintptr_t, int, kd_buf
*);
263 char *generate_cs_disk_name(int, char *s
);
264 char *find_disk_name(int);
265 void cache_disk_names();
266 void recache_disk_names();
268 void lookup_name(uint64_t user_addr
, char **type
, char **name
);
269 int ReadSharedCacheMap(const char *, LibraryRange
*, char *);
270 void SortFrameworkAddresses();
272 void fs_usage_fd_set(uintptr_t, unsigned int);
273 int fs_usage_fd_isset(uintptr_t, unsigned int);
274 void fs_usage_fd_clear(uintptr_t, unsigned int);
276 void init_arguments_buffer();
277 int get_real_command_name(int, char *, int);
279 void delete_all_events();
280 void delete_event(th_info_t
);
281 th_info_t
add_event(uintptr_t, int);
282 th_info_t
find_event(uintptr_t, int);
283 void mark_thread_waited(uintptr_t);
285 void read_command_map();
286 void delete_all_map_entries();
287 void create_map_entry(uintptr_t, int, char *);
288 void delete_map_entry(uintptr_t);
289 threadmap_t
find_map_entry(uintptr_t);
295 void set_pidexclude();
299 #define CLASS_MASK 0xff000000
300 #define CSC_MASK 0xffff0000
301 #define BSC_INDEX(type) ((type >> 2) & 0x3fff)
304 #define TRACE_DATA_NEWTHREAD 0x07000004
305 #define TRACE_DATA_EXEC 0x07000008
306 #define TRACE_STRING_NEWTHREAD 0x07010004
307 #define TRACE_STRING_EXEC 0x07010008
309 #define MACH_vmfault 0x01300008
310 #define MACH_pageout 0x01300004
311 #define MACH_sched 0x01400000
312 #define MACH_stkhandoff 0x01400008
313 #define MACH_idle 0x01400024
314 #define VFS_LOOKUP 0x03010090
316 #define BSC_thread_terminate 0x040c05a4
318 #define Throttled 0x3010184
319 #define SPEC_ioctl 0x3060000
320 #define proc_exit 0x4010004
322 #define P_DISKIO 0x03020000
323 #define P_DISKIO_DONE 0x03020004
324 #define P_DISKIO_TYPE 0x03020068
325 #define P_DISKIO_MASK (CSC_MASK | 0x4)
327 #define P_DISKIO_READ 0x00000008
328 #define P_DISKIO_ASYNC 0x00000010
329 #define P_DISKIO_META 0x00000020
330 #define P_DISKIO_PAGING 0x00000040
331 #define P_DISKIO_THROTTLE 0x00000080
332 #define P_DISKIO_PASSIVE 0x00000100
334 #define P_WrData 0x03020000
335 #define P_RdData 0x03020008
336 #define P_WrMeta 0x03020020
337 #define P_RdMeta 0x03020028
338 #define P_PgOut 0x03020040
339 #define P_PgIn 0x03020048
341 #define P_CS_ReadChunk 0x0a000200
342 #define P_CS_ReadChunkDone 0x0a000280
343 #define P_CS_WriteChunk 0x0a000210
344 #define P_CS_WriteChunkDone 0x0a000290
346 #define P_CS_Originated_Read 0x0a000500
347 #define P_CS_Originated_ReadDone 0x0a000580
348 #define P_CS_Originated_Write 0x0a000510
349 #define P_CS_Originated_WriteDone 0x0a000590
350 #define P_CS_MetaRead 0x0a000900
351 #define P_CS_MetaReadDone 0x0a000980
352 #define P_CS_MetaWrite 0x0a000910
353 #define P_CS_MetaWriteDone 0x0a000990
354 #define P_CS_SYNC_DISK 0x0a008000
357 #define MSC_map_fd 0x010c00ac
359 #define BSC_BASE 0x040C0000
360 #define MSC_BASE 0x010C0000
362 // Network related codes
363 #define BSC_recvmsg 0x040C006C
364 #define BSC_sendmsg 0x040C0070
365 #define BSC_recvfrom 0x040C0074
366 #define BSC_accept 0x040C0078
367 #define BSC_select 0x040C0174
368 #define BSC_socket 0x040C0184
369 #define BSC_connect 0x040C0188
370 #define BSC_bind 0x040C01A0
371 #define BSC_listen 0x040C01A8
372 #define BSC_sendto 0x040C0214
373 #define BSC_socketpair 0x040C021C
375 #define BSC_exit 0x040C0004
376 #define BSC_read 0x040C000C
377 #define BSC_write 0x040C0010
378 #define BSC_open 0x040C0014
379 #define BSC_close 0x040C0018
380 #define BSC_link 0x040C0024
381 #define BSC_unlink 0x040C0028
382 #define BSC_chdir 0x040c0030
383 #define BSC_fchdir 0x040c0034
384 #define BSC_mknod 0x040C0038
385 #define BSC_chmod 0x040C003C
386 #define BSC_chown 0x040C0040
387 #define BSC_getfsstat 0x040C0048
388 #define BSC_access 0x040C0084
389 #define BSC_chflags 0x040C0088
390 #define BSC_fchflags 0x040C008C
391 #define BSC_sync 0x040C0090
392 #define BSC_dup 0x040C00A4
393 #define BSC_ioctl 0x040C00D8
394 #define BSC_revoke 0x040C00E0
395 #define BSC_symlink 0x040C00E4
396 #define BSC_readlink 0x040C00E8
397 #define BSC_execve 0x040C00EC
398 #define BSC_umask 0x040C00F0
399 #define BSC_chroot 0x040C00F4
400 #define BSC_msync 0x040C0104
401 #define BSC_dup2 0x040C0168
402 #define BSC_fcntl 0x040C0170
403 #define BSC_fsync 0x040C017C
404 #define BSC_readv 0x040C01E0
405 #define BSC_writev 0x040C01E4
406 #define BSC_fchown 0x040C01EC
407 #define BSC_fchmod 0x040C01F0
408 #define BSC_rename 0x040C0200
409 #define BSC_mkfifo 0x040c0210
410 #define BSC_mkdir 0x040C0220
411 #define BSC_rmdir 0x040C0224
412 #define BSC_utimes 0x040C0228
413 #define BSC_futimes 0x040C022C
414 #define BSC_pread 0x040C0264
415 #define BSC_pwrite 0x040C0268
416 #define BSC_statfs 0x040C0274
417 #define BSC_fstatfs 0x040C0278
418 #define BSC_unmount 0x040C027C
419 #define BSC_mount 0x040C029C
420 #define BSC_stat 0x040C02F0
421 #define BSC_fstat 0x040C02F4
422 #define BSC_lstat 0x040C02F8
423 #define BSC_pathconf 0x040C02FC
424 #define BSC_fpathconf 0x040C0300
425 #define BSC_getdirentries 0x040C0310
426 #define BSC_mmap 0x040c0314
427 #define BSC_lseek 0x040c031c
428 #define BSC_truncate 0x040C0320
429 #define BSC_ftruncate 0x040C0324
430 #define BSC_undelete 0x040C0334
431 #define BSC_statv 0x040C0364
432 #define BSC_lstatv 0x040C0368
433 #define BSC_fstatv 0x040C036C
434 #define BSC_mkcomplex 0x040C0360
435 #define BSC_getattrlist 0x040C0370
436 #define BSC_setattrlist 0x040C0374
437 #define BSC_getdirentriesattr 0x040C0378
438 #define BSC_exchangedata 0x040C037C
439 #define BSC_checkuseraccess 0x040C0380
440 #define BSC_searchfs 0x040C0384
441 #define BSC_delete 0x040C0388
442 #define BSC_copyfile 0x040C038C
443 #define BSC_getxattr 0x040C03A8
444 #define BSC_fgetxattr 0x040C03AC
445 #define BSC_setxattr 0x040C03B0
446 #define BSC_fsetxattr 0x040C03B4
447 #define BSC_removexattr 0x040C03B8
448 #define BSC_fremovexattr 0x040C03BC
449 #define BSC_listxattr 0x040C03C0
450 #define BSC_flistxattr 0x040C03C4
451 #define BSC_fsctl 0x040C03C8
452 #define BSC_posix_spawn 0x040C03D0
453 #define BSC_open_extended 0x040C0454
454 #define BSC_stat_extended 0x040C045C
455 #define BSC_lstat_extended 0x040C0460
456 #define BSC_fstat_extended 0x040C0464
457 #define BSC_chmod_extended 0x040C0468
458 #define BSC_fchmod_extended 0x040C046C
459 #define BSC_access_extended 0x040C0470
460 #define BSC_mkfifo_extended 0x040C048C
461 #define BSC_mkdir_extended 0x040C0490
462 #define BSC_load_shared_file 0x040C04A0
463 #define BSC_aio_fsync 0x040C04E4
464 #define BSC_aio_return 0x040C04E8
465 #define BSC_aio_suspend 0x040C04EC
466 #define BSC_aio_cancel 0x040C04F0
467 #define BSC_aio_error 0x040C04F4
468 #define BSC_aio_read 0x040C04F8
469 #define BSC_aio_write 0x040C04FC
470 #define BSC_lio_listio 0x040C0500
471 #define BSC_sendfile 0x040C0544
472 #define BSC_stat64 0x040C0548
473 #define BSC_fstat64 0x040C054C
474 #define BSC_lstat64 0x040C0550
475 #define BSC_stat64_extended 0x040C0554
476 #define BSC_lstat64_extended 0x040C0558
477 #define BSC_fstat64_extended 0x040C055C
478 #define BSC_getdirentries64 0x040C0560
479 #define BSC_statfs64 0x040C0564
480 #define BSC_fstatfs64 0x040C0568
481 #define BSC_getfsstat64 0x040C056C
482 #define BSC_pthread_chdir 0x040C0570
483 #define BSC_pthread_fchdir 0x040C0574
484 #define BSC_lchown 0x040C05B0
486 #define BSC_read_nocancel 0x040c0630
487 #define BSC_write_nocancel 0x040c0634
488 #define BSC_open_nocancel 0x040c0638
489 #define BSC_close_nocancel 0x040c063c
490 #define BSC_recvmsg_nocancel 0x040c0644
491 #define BSC_sendmsg_nocancel 0x040c0648
492 #define BSC_recvfrom_nocancel 0x040c064c
493 #define BSC_accept_nocancel 0x040c0650
494 #define BSC_msync_nocancel 0x040c0654
495 #define BSC_fcntl_nocancel 0x040c0658
496 #define BSC_select_nocancel 0x040c065c
497 #define BSC_fsync_nocancel 0x040c0660
498 #define BSC_connect_nocancel 0x040c0664
499 #define BSC_readv_nocancel 0x040c066c
500 #define BSC_writev_nocancel 0x040c0670
501 #define BSC_sendto_nocancel 0x040c0674
502 #define BSC_pread_nocancel 0x040c0678
503 #define BSC_pwrite_nocancel 0x040c067c
504 #define BSC_aio_suspend_nocancel 0x40c0694
506 #define BSC_msync_extended 0x040e0104
507 #define BSC_pread_extended 0x040e0264
508 #define BSC_pwrite_extended 0x040e0268
509 #define BSC_mmap_extended 0x040e0314
510 #define BSC_mmap_extended2 0x040f0314
512 // Carbon File Manager support
513 #define FILEMGR_PBGETCATALOGINFO 0x1e000020
514 #define FILEMGR_PBGETCATALOGINFOBULK 0x1e000024
515 #define FILEMGR_PBCREATEFILEUNICODE 0x1e000028
516 #define FILEMGR_PBCREATEDIRECTORYUNICODE 0x1e00002c
517 #define FILEMGR_PBCREATEFORK 0x1e000030
518 #define FILEMGR_PBDELETEFORK 0x1e000034
519 #define FILEMGR_PBITERATEFORK 0x1e000038
520 #define FILEMGR_PBOPENFORK 0x1e00003c
521 #define FILEMGR_PBREADFORK 0x1e000040
522 #define FILEMGR_PBWRITEFORK 0x1e000044
523 #define FILEMGR_PBALLOCATEFORK 0x1e000048
524 #define FILEMGR_PBDELETEOBJECT 0x1e00004c
525 #define FILEMGR_PBEXCHANGEOBJECT 0x1e000050
526 #define FILEMGR_PBGETFORKCBINFO 0x1e000054
527 #define FILEMGR_PBGETVOLUMEINFO 0x1e000058
528 #define FILEMGR_PBMAKEFSREF 0x1e00005c
529 #define FILEMGR_PBMAKEFSREFUNICODE 0x1e000060
530 #define FILEMGR_PBMOVEOBJECT 0x1e000064
531 #define FILEMGR_PBOPENITERATOR 0x1e000068
532 #define FILEMGR_PBRENAMEUNICODE 0x1e00006c
533 #define FILEMGR_PBSETCATALOGINFO 0x1e000070
534 #define FILEMGR_PBSETVOLUMEINFO 0x1e000074
535 #define FILEMGR_FSREFMAKEPATH 0x1e000078
536 #define FILEMGR_FSPATHMAKEREF 0x1e00007c
538 #define FILEMGR_PBGETCATINFO 0x1e010000
539 #define FILEMGR_PBGETCATINFOLITE 0x1e010004
540 #define FILEMGR_PBHGETFINFO 0x1e010008
541 #define FILEMGR_PBXGETVOLINFO 0x1e01000c
542 #define FILEMGR_PBHCREATE 0x1e010010
543 #define FILEMGR_PBHOPENDF 0x1e010014
544 #define FILEMGR_PBHOPENRF 0x1e010018
545 #define FILEMGR_PBHGETDIRACCESS 0x1e01001c
546 #define FILEMGR_PBHSETDIRACCESS 0x1e010020
547 #define FILEMGR_PBHMAPID 0x1e010024
548 #define FILEMGR_PBHMAPNAME 0x1e010028
549 #define FILEMGR_PBCLOSE 0x1e01002c
550 #define FILEMGR_PBFLUSHFILE 0x1e010030
551 #define FILEMGR_PBGETEOF 0x1e010034
552 #define FILEMGR_PBSETEOF 0x1e010038
553 #define FILEMGR_PBGETFPOS 0x1e01003c
554 #define FILEMGR_PBREAD 0x1e010040
555 #define FILEMGR_PBWRITE 0x1e010044
556 #define FILEMGR_PBGETFCBINFO 0x1e010048
557 #define FILEMGR_PBSETFINFO 0x1e01004c
558 #define FILEMGR_PBALLOCATE 0x1e010050
559 #define FILEMGR_PBALLOCCONTIG 0x1e010054
560 #define FILEMGR_PBSETFPOS 0x1e010058
561 #define FILEMGR_PBSETCATINFO 0x1e01005c
562 #define FILEMGR_PBGETVOLPARMS 0x1e010060
563 #define FILEMGR_PBSETVINFO 0x1e010064
564 #define FILEMGR_PBMAKEFSSPEC 0x1e010068
565 #define FILEMGR_PBHGETVINFO 0x1e01006c
566 #define FILEMGR_PBCREATEFILEIDREF 0x1e010070
567 #define FILEMGR_PBDELETEFILEIDREF 0x1e010074
568 #define FILEMGR_PBRESOLVEFILEIDREF 0x1e010078
569 #define FILEMGR_PBFLUSHVOL 0x1e01007c
570 #define FILEMGR_PBHRENAME 0x1e010080
571 #define FILEMGR_PBCATMOVE 0x1e010084
572 #define FILEMGR_PBEXCHANGEFILES 0x1e010088
573 #define FILEMGR_PBHDELETE 0x1e01008c
574 #define FILEMGR_PBDIRCREATE 0x1e010090
575 #define FILEMGR_PBCATSEARCH 0x1e010094
576 #define FILEMGR_PBHSETFLOCK 0x1e010098
577 #define FILEMGR_PBHRSTFLOCK 0x1e01009c
578 #define FILEMGR_PBLOCKRANGE 0x1e0100a0
579 #define FILEMGR_PBUNLOCKRANGE 0x1e0100a4
582 #define FILEMGR_CLASS 0x1e
583 #define FILEMGR_BASE 0x1e000000
585 #define FMT_DEFAULT 0
592 #define FMT_CACHEHIT 7
596 #define FMT_FTRUNC 11
598 #define FMT_SELECT 13
600 #define FMT_AIO_FSYNC 15
601 #define FMT_AIO_RETURN 16
602 #define FMT_AIO_SUSPEND 17
603 #define FMT_AIO_CANCEL 18
605 #define FMT_LIO_LISTIO 20
608 #define FMT_ACCESS 23
610 #define FMT_FCHMOD 25
611 #define FMT_CHMOD_EXT 26
612 #define FMT_FCHMOD_EXT 27
613 #define FMT_CHFLAGS 28
614 #define FMT_FCHFLAGS 29
618 #define FMT_SENDFILE 33
619 #define FMT_SPEC_IOCTL 34
621 #define FMT_UNMOUNT 36
622 #define FMT_DISKIO_CS 37
623 #define FMT_SYNC_DISK_CS 38
625 #define MAX_BSD_SYSCALL 512
630 } bsd_syscalls
[MAX_BSD_SYSCALL
];
633 int bsd_syscall_types
[] = {
635 BSC_recvmsg_nocancel
,
637 BSC_sendmsg_nocancel
,
639 BSC_recvfrom_nocancel
,
646 BSC_connect_nocancel
,
720 BSC_getdirentriesattr
,
744 BSC_load_shared_file
,
748 BSC_aio_suspend_nocancel
,
765 BSC_lstat64_extended
,
766 BSC_fstat64_extended
,
778 #define MAX_FILEMGR 512
780 struct filemgr_call
{
782 } filemgr_calls
[MAX_FILEMGR
];
785 int filemgr_call_types
[] = {
786 FILEMGR_PBGETCATALOGINFO
,
787 FILEMGR_PBGETCATALOGINFOBULK
,
788 FILEMGR_PBCREATEFILEUNICODE
,
789 FILEMGR_PBCREATEDIRECTORYUNICODE
,
790 FILEMGR_PBCREATEFORK
,
791 FILEMGR_PBDELETEFORK
,
792 FILEMGR_PBITERATEFORK
,
796 FILEMGR_PBALLOCATEFORK
,
797 FILEMGR_PBDELETEOBJECT
,
798 FILEMGR_PBEXCHANGEOBJECT
,
799 FILEMGR_PBGETFORKCBINFO
,
800 FILEMGR_PBGETVOLUMEINFO
,
802 FILEMGR_PBMAKEFSREFUNICODE
,
803 FILEMGR_PBMOVEOBJECT
,
804 FILEMGR_PBOPENITERATOR
,
805 FILEMGR_PBRENAMEUNICODE
,
806 FILEMGR_PBSETCATALOGINFO
,
807 FILEMGR_PBSETVOLUMEINFO
,
808 FILEMGR_FSREFMAKEPATH
,
809 FILEMGR_FSPATHMAKEREF
,
811 FILEMGR_PBGETCATINFO
,
812 FILEMGR_PBGETCATINFOLITE
,
814 FILEMGR_PBXGETVOLINFO
,
818 FILEMGR_PBHGETDIRACCESS
,
819 FILEMGR_PBHSETDIRACCESS
,
829 FILEMGR_PBGETFCBINFO
,
832 FILEMGR_PBALLOCCONTIG
,
834 FILEMGR_PBSETCATINFO
,
835 FILEMGR_PBGETVOLPARMS
,
837 FILEMGR_PBMAKEFSSPEC
,
839 FILEMGR_PBCREATEFILEIDREF
,
840 FILEMGR_PBDELETEFILEIDREF
,
841 FILEMGR_PBRESOLVEFILEIDREF
,
845 FILEMGR_PBEXCHANGEFILES
,
852 FILEMGR_PBUNLOCKRANGE
,
862 int exclude_pids
= 0;
863 int exclude_default_pids
= 1;
866 struct kinfo_proc
*kp_buffer
= 0;
869 #define EVENT_BASE 60000
871 int num_events
= EVENT_BASE
;
874 #define DBG_FUNC_ALL (DBG_FUNC_START | DBG_FUNC_END)
875 #define DBG_FUNC_MASK 0xfffffffc
877 double divisor
= 0.0; /* Trace divisor converts to microseconds */
883 kbufinfo_t bufinfo
= {0, 0, 0, 0, 0};
886 /* defines for tracking file descriptor state */
887 #define FS_USAGE_FD_SETSIZE 256 /* Initial number of file descriptors per
888 thread that we will track */
890 #define FS_USAGE_NFDBITS (sizeof (unsigned long) * 8)
891 #define FS_USAGE_NFDBYTES(n) (((n) / FS_USAGE_NFDBITS) * sizeof (unsigned long))
893 int trace_enabled
= 0;
894 int set_remove_flag
= 1;
896 char *RAW_file
= (char *)0;
900 uint64_t sample_TOD_secs
;
901 uint32_t sample_TOD_usecs
;
903 double bias_now
= 0.0;
904 double start_time
= 0.0;
905 double end_time
= 999999999999.9;
918 void leave() /* exit under normal conditions -- INT handler */
923 void set_pidexclude();
930 if (exclude_pids
== 0) {
931 for (i
= 0; i
< num_of_pids
; i
++)
932 set_pidcheck(pids
[i
], 0);
935 for (i
= 0; i
< num_of_pids
; i
++)
936 set_pidexclude(pids
[i
], 0);
951 * This flag is turned off when calling
952 * quit() due to a set_remove() failure.
957 fprintf(stderr
, "fs_usage: ");
959 fprintf(stderr
, "%s", s
);
965 void get_screenwidth()
972 if (ioctl(1, TIOCGWINSZ
, &size
) != -1) {
973 columns
= size
.ws_col
;
975 if (columns
> MAXWIDTH
)
991 struct mach_timebase_info mti
;
993 mach_timebase_info(&mti
);
995 divisor
= ((double)mti
.denom
/ (double)mti
.numer
) * 1000;
1000 exit_usage(char *myname
) {
1002 fprintf(stderr
, "Usage: %s [-e] [-w] [-f mode] [-R rawfile [-S start_time] [-E end_time]] [pid | cmd [pid | cmd]....]\n", myname
);
1003 fprintf(stderr
, " -e exclude the specified list of pids from the sample\n");
1004 fprintf(stderr
, " and exclude fs_usage by default\n");
1005 fprintf(stderr
, " -w force wider, detailed, output\n");
1006 fprintf(stderr
, " -f Output is based on the mode provided\n");
1007 fprintf(stderr
, " mode = \"network\" Show only network related output\n");
1008 fprintf(stderr
, " mode = \"filesys\" Show only file system related output\n");
1009 fprintf(stderr
, " mode = \"pathname\" Show only pathname related output\n");
1010 fprintf(stderr
, " mode = \"exec\" Show only execs\n");
1011 fprintf(stderr
, " mode = \"cachehit\" In addition, show cachehits\n");
1012 fprintf(stderr
, " -R specifies a raw trace file to process\n");
1013 fprintf(stderr
, " -S if -R is specified, selects a start point in microseconds\n");
1014 fprintf(stderr
, " -E if -R is specified, selects an end point in microseconds\n");
1015 fprintf(stderr
, " pid selects process(s) to sample\n");
1016 fprintf(stderr
, " cmd selects process(s) matching command string to sample\n");
1017 fprintf(stderr
, "\n%s will handle a maximum list of %d pids.\n\n", myname
, MAX_PIDS
);
1018 fprintf(stderr
, "By default (no options) the following processes are excluded from the output:\n");
1019 fprintf(stderr
, "fs_usage, Terminal, telnetd, sshd, rlogind, tcsh, csh, sh\n\n");
1025 int filemgr_index(type
) {
1028 return (((type
>> 2) & 0x3fff) + 256);
1030 return (((type
>> 2) & 0x3fff));
1034 void init_tables(void)
1040 for (i
= 0; i
< MAX_BSD_SYSCALL
; i
++) {
1041 bsd_syscalls
[i
].sc_name
= NULL
;
1042 bsd_syscalls
[i
].sc_format
= FMT_DEFAULT
;
1045 for (i
= 0; i
< MAX_FILEMGR
; i
++) {
1046 filemgr_calls
[i
].fm_name
= NULL
;
1049 for (i
= 0; (type
= bsd_syscall_types
[i
]); i
++) {
1051 code
= BSC_INDEX(type
);
1053 if (code
>= MAX_BSD_SYSCALL
) {
1054 printf("BSD syscall init (%x): type exceeds table size\n", type
);
1060 bsd_syscalls
[code
].sc_name
= "sendfile";
1061 bsd_syscalls
[code
].sc_format
= FMT_FD
; /* this should be changed to FMT_SENDFILE */
1062 break; /* once we add an extended info trace event */
1065 case BSC_recvmsg_nocancel
:
1066 bsd_syscalls
[code
].sc_name
= "recvmsg";
1067 bsd_syscalls
[code
].sc_format
= FMT_FD_IO
;
1071 case BSC_sendmsg_nocancel
:
1072 bsd_syscalls
[code
].sc_name
= "sendmsg";
1073 bsd_syscalls
[code
].sc_format
= FMT_FD_IO
;
1077 case BSC_recvfrom_nocancel
:
1078 bsd_syscalls
[code
].sc_name
= "recvfrom";
1079 bsd_syscalls
[code
].sc_format
= FMT_FD_IO
;
1083 case BSC_sendto_nocancel
:
1084 bsd_syscalls
[code
].sc_name
= "sendto";
1085 bsd_syscalls
[code
].sc_format
= FMT_FD_IO
;
1089 case BSC_select_nocancel
:
1090 bsd_syscalls
[code
].sc_name
= "select";
1091 bsd_syscalls
[code
].sc_format
= FMT_SELECT
;
1095 case BSC_accept_nocancel
:
1096 bsd_syscalls
[code
].sc_name
= "accept";
1097 bsd_syscalls
[code
].sc_format
= FMT_FD_2
;
1101 bsd_syscalls
[code
].sc_name
= "socket";
1102 bsd_syscalls
[code
].sc_format
= FMT_SOCKET
;
1106 case BSC_connect_nocancel
:
1107 bsd_syscalls
[code
].sc_name
= "connect";
1108 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1112 bsd_syscalls
[code
].sc_name
= "bind";
1113 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1117 bsd_syscalls
[code
].sc_name
= "listen";
1118 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1122 bsd_syscalls
[code
].sc_name
= "mmap";
1123 bsd_syscalls
[code
].sc_format
= FMT_MMAP
;
1126 case BSC_socketpair
:
1127 bsd_syscalls
[code
].sc_name
= "socketpair";
1131 bsd_syscalls
[code
].sc_name
= "getxattr";
1135 bsd_syscalls
[code
].sc_name
= "setxattr";
1138 case BSC_removexattr
:
1139 bsd_syscalls
[code
].sc_name
= "removexattr";
1143 bsd_syscalls
[code
].sc_name
= "listxattr";
1147 bsd_syscalls
[code
].sc_name
= "stat";
1151 bsd_syscalls
[code
].sc_name
= "stat64";
1154 case BSC_stat_extended
:
1155 bsd_syscalls
[code
].sc_name
= "stat_extended";
1158 case BSC_stat64_extended
:
1159 bsd_syscalls
[code
].sc_name
= "stat_extended64";
1163 bsd_syscalls
[code
].sc_name
= "mount";
1164 bsd_syscalls
[code
].sc_format
= FMT_MOUNT
;
1168 bsd_syscalls
[code
].sc_name
= "unmount";
1169 bsd_syscalls
[code
].sc_format
= FMT_UNMOUNT
;
1173 bsd_syscalls
[code
].sc_name
= "exit";
1177 bsd_syscalls
[code
].sc_name
= "execve";
1180 case BSC_posix_spawn
:
1181 bsd_syscalls
[code
].sc_name
= "posix_spawn";
1184 case BSC_load_shared_file
:
1185 bsd_syscalls
[code
].sc_name
= "load_sf";
1189 case BSC_open_nocancel
:
1190 bsd_syscalls
[code
].sc_name
= "open";
1191 bsd_syscalls
[code
].sc_format
= FMT_OPEN
;
1194 case BSC_open_extended
:
1195 bsd_syscalls
[code
].sc_name
= "open_extended";
1196 bsd_syscalls
[code
].sc_format
= FMT_OPEN
;
1200 bsd_syscalls
[code
].sc_name
= "dup";
1201 bsd_syscalls
[code
].sc_format
= FMT_FD_2
;
1205 bsd_syscalls
[code
].sc_name
= "dup2";
1206 bsd_syscalls
[code
].sc_format
= FMT_FD_2
;
1210 case BSC_close_nocancel
:
1211 bsd_syscalls
[code
].sc_name
= "close";
1212 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1216 case BSC_read_nocancel
:
1217 bsd_syscalls
[code
].sc_name
= "read";
1218 bsd_syscalls
[code
].sc_format
= FMT_FD_IO
;
1222 case BSC_write_nocancel
:
1223 bsd_syscalls
[code
].sc_name
= "write";
1224 bsd_syscalls
[code
].sc_format
= FMT_FD_IO
;
1228 bsd_syscalls
[code
].sc_name
= "fgetxattr";
1229 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1233 bsd_syscalls
[code
].sc_name
= "fsetxattr";
1234 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1237 case BSC_fremovexattr
:
1238 bsd_syscalls
[code
].sc_name
= "fremovexattr";
1239 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1242 case BSC_flistxattr
:
1243 bsd_syscalls
[code
].sc_name
= "flistxattr";
1244 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1248 bsd_syscalls
[code
].sc_name
= "fstat";
1249 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1253 bsd_syscalls
[code
].sc_name
= "fstat64";
1254 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1257 case BSC_fstat_extended
:
1258 bsd_syscalls
[code
].sc_name
= "fstat_extended";
1259 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1262 case BSC_fstat64_extended
:
1263 bsd_syscalls
[code
].sc_name
= "fstat64_extended";
1264 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1268 bsd_syscalls
[code
].sc_name
= "lstat";
1272 bsd_syscalls
[code
].sc_name
= "lstat64";
1275 case BSC_lstat_extended
:
1276 bsd_syscalls
[code
].sc_name
= "lstat_extended";
1279 case BSC_lstat64_extended
:
1280 bsd_syscalls
[code
].sc_name
= "lstat_extended64";
1284 bsd_syscalls
[code
].sc_name
= "lstatv";
1288 bsd_syscalls
[code
].sc_name
= "link";
1292 bsd_syscalls
[code
].sc_name
= "unlink";
1296 bsd_syscalls
[code
].sc_name
= "mknod";
1300 bsd_syscalls
[code
].sc_name
= "umask";
1301 bsd_syscalls
[code
].sc_format
= FMT_UMASK
;
1305 bsd_syscalls
[code
].sc_name
= "chmod";
1306 bsd_syscalls
[code
].sc_format
= FMT_CHMOD
;
1309 case BSC_chmod_extended
:
1310 bsd_syscalls
[code
].sc_name
= "chmod_extended";
1311 bsd_syscalls
[code
].sc_format
= FMT_CHMOD_EXT
;
1315 bsd_syscalls
[code
].sc_name
= "fchmod";
1316 bsd_syscalls
[code
].sc_format
= FMT_FCHMOD
;
1319 case BSC_fchmod_extended
:
1320 bsd_syscalls
[code
].sc_name
= "fchmod_extended";
1321 bsd_syscalls
[code
].sc_format
= FMT_FCHMOD_EXT
;
1325 bsd_syscalls
[code
].sc_name
= "chown";
1329 bsd_syscalls
[code
].sc_name
= "lchown";
1333 bsd_syscalls
[code
].sc_name
= "fchown";
1334 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1338 bsd_syscalls
[code
].sc_name
= "access";
1339 bsd_syscalls
[code
].sc_format
= FMT_ACCESS
;
1342 case BSC_access_extended
:
1343 bsd_syscalls
[code
].sc_name
= "access_extended";
1347 bsd_syscalls
[code
].sc_name
= "chdir";
1350 case BSC_pthread_chdir
:
1351 bsd_syscalls
[code
].sc_name
= "pthread_chdir";
1355 bsd_syscalls
[code
].sc_name
= "chroot";
1359 bsd_syscalls
[code
].sc_name
= "utimes";
1363 bsd_syscalls
[code
].sc_name
= "delete-Carbon";
1367 bsd_syscalls
[code
].sc_name
= "undelete";
1371 bsd_syscalls
[code
].sc_name
= "revoke";
1375 bsd_syscalls
[code
].sc_name
= "fsctl";
1379 bsd_syscalls
[code
].sc_name
= "chflags";
1380 bsd_syscalls
[code
].sc_format
= FMT_CHFLAGS
;
1384 bsd_syscalls
[code
].sc_name
= "fchflags";
1385 bsd_syscalls
[code
].sc_format
= FMT_FCHFLAGS
;
1389 bsd_syscalls
[code
].sc_name
= "fchdir";
1390 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1393 case BSC_pthread_fchdir
:
1394 bsd_syscalls
[code
].sc_name
= "pthread_fchdir";
1395 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1399 bsd_syscalls
[code
].sc_name
= "futimes";
1400 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1404 bsd_syscalls
[code
].sc_name
= "sync";
1408 bsd_syscalls
[code
].sc_name
= "symlink";
1412 bsd_syscalls
[code
].sc_name
= "readlink";
1416 case BSC_fsync_nocancel
:
1417 bsd_syscalls
[code
].sc_name
= "fsync";
1418 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1422 case BSC_readv_nocancel
:
1423 bsd_syscalls
[code
].sc_name
= "readv";
1424 bsd_syscalls
[code
].sc_format
= FMT_FD_IO
;
1428 case BSC_writev_nocancel
:
1429 bsd_syscalls
[code
].sc_name
= "writev";
1430 bsd_syscalls
[code
].sc_format
= FMT_FD_IO
;
1434 case BSC_pread_nocancel
:
1435 bsd_syscalls
[code
].sc_name
= "pread";
1436 bsd_syscalls
[code
].sc_format
= FMT_PREAD
;
1440 case BSC_pwrite_nocancel
:
1441 bsd_syscalls
[code
].sc_name
= "pwrite";
1442 bsd_syscalls
[code
].sc_format
= FMT_PREAD
;
1446 bsd_syscalls
[code
].sc_name
= "mkdir";
1449 case BSC_mkdir_extended
:
1450 bsd_syscalls
[code
].sc_name
= "mkdir_extended";
1454 bsd_syscalls
[code
].sc_name
= "mkfifo";
1457 case BSC_mkfifo_extended
:
1458 bsd_syscalls
[code
].sc_name
= "mkfifo_extended";
1462 bsd_syscalls
[code
].sc_name
= "rmdir";
1466 bsd_syscalls
[code
].sc_name
= "statfs";
1470 bsd_syscalls
[code
].sc_name
= "statfs64";
1474 bsd_syscalls
[code
].sc_name
= "getfsstat";
1477 case BSC_getfsstat64
:
1478 bsd_syscalls
[code
].sc_name
= "getfsstat64";
1482 bsd_syscalls
[code
].sc_name
= "fstatfs";
1483 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1487 bsd_syscalls
[code
].sc_name
= "fstatfs64";
1488 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1492 bsd_syscalls
[code
].sc_name
= "pathconf";
1496 bsd_syscalls
[code
].sc_name
= "fpathconf";
1497 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1500 case BSC_getdirentries
:
1501 bsd_syscalls
[code
].sc_name
= "getdirentries";
1502 bsd_syscalls
[code
].sc_format
= FMT_FD_IO
;
1505 case BSC_getdirentries64
:
1506 bsd_syscalls
[code
].sc_name
= "getdirentries64";
1507 bsd_syscalls
[code
].sc_format
= FMT_FD_IO
;
1511 bsd_syscalls
[code
].sc_name
= "lseek";
1512 bsd_syscalls
[code
].sc_format
= FMT_LSEEK
;
1516 bsd_syscalls
[code
].sc_name
= "truncate";
1517 bsd_syscalls
[code
].sc_format
= FMT_TRUNC
;
1521 bsd_syscalls
[code
].sc_name
= "ftruncate";
1522 bsd_syscalls
[code
].sc_format
= FMT_FTRUNC
;
1526 bsd_syscalls
[code
].sc_name
= "statv";
1530 bsd_syscalls
[code
].sc_name
= "fstatv";
1531 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1535 bsd_syscalls
[code
].sc_name
= "mkcomplex";
1538 case BSC_getattrlist
:
1539 bsd_syscalls
[code
].sc_name
= "getattrlist";
1542 case BSC_setattrlist
:
1543 bsd_syscalls
[code
].sc_name
= "setattrlist";
1546 case BSC_getdirentriesattr
:
1547 bsd_syscalls
[code
].sc_name
= "getdirentriesattr";
1548 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1551 case BSC_exchangedata
:
1552 bsd_syscalls
[code
].sc_name
= "exchangedata";
1556 bsd_syscalls
[code
].sc_name
= "rename";
1560 bsd_syscalls
[code
].sc_name
= "copyfile";
1563 case BSC_checkuseraccess
:
1564 bsd_syscalls
[code
].sc_name
= "checkuseraccess";
1568 bsd_syscalls
[code
].sc_name
= "searchfs";
1572 bsd_syscalls
[code
].sc_name
= "aio_fsync";
1573 bsd_syscalls
[code
].sc_format
= FMT_AIO_FSYNC
;
1576 case BSC_aio_return
:
1577 bsd_syscalls
[code
].sc_name
= "aio_return";
1578 bsd_syscalls
[code
].sc_format
= FMT_AIO_RETURN
;
1581 case BSC_aio_suspend
:
1582 case BSC_aio_suspend_nocancel
:
1583 bsd_syscalls
[code
].sc_name
= "aio_suspend";
1584 bsd_syscalls
[code
].sc_format
= FMT_AIO_SUSPEND
;
1587 case BSC_aio_cancel
:
1588 bsd_syscalls
[code
].sc_name
= "aio_cancel";
1589 bsd_syscalls
[code
].sc_format
= FMT_AIO_CANCEL
;
1593 bsd_syscalls
[code
].sc_name
= "aio_error";
1594 bsd_syscalls
[code
].sc_format
= FMT_AIO
;
1598 bsd_syscalls
[code
].sc_name
= "aio_read";
1599 bsd_syscalls
[code
].sc_format
= FMT_AIO
;
1603 bsd_syscalls
[code
].sc_name
= "aio_write";
1604 bsd_syscalls
[code
].sc_format
= FMT_AIO
;
1607 case BSC_lio_listio
:
1608 bsd_syscalls
[code
].sc_name
= "lio_listio";
1609 bsd_syscalls
[code
].sc_format
= FMT_LIO_LISTIO
;
1613 case BSC_msync_nocancel
:
1614 bsd_syscalls
[code
].sc_name
= "msync";
1615 bsd_syscalls
[code
].sc_format
= FMT_MSYNC
;
1619 case BSC_fcntl_nocancel
:
1620 bsd_syscalls
[code
].sc_name
= "fcntl";
1621 bsd_syscalls
[code
].sc_format
= FMT_FCNTL
;
1625 bsd_syscalls
[code
].sc_name
= "ioctl";
1626 bsd_syscalls
[code
].sc_format
= FMT_IOCTL
;
1631 for (i
= 0; (type
= filemgr_call_types
[i
]); i
++) {
1634 code
= filemgr_index(type
);
1636 if (code
>= MAX_FILEMGR
) {
1637 printf("FILEMGR call init (%x): type exceeds table size\n", type
);
1642 case FILEMGR_PBGETCATALOGINFO
:
1643 p
= "GetCatalogInfo";
1646 case FILEMGR_PBGETCATALOGINFOBULK
:
1647 p
= "GetCatalogInfoBulk";
1650 case FILEMGR_PBCREATEFILEUNICODE
:
1651 p
= "CreateFileUnicode";
1654 case FILEMGR_PBCREATEDIRECTORYUNICODE
:
1655 p
= "CreateDirectoryUnicode";
1658 case FILEMGR_PBCREATEFORK
:
1662 case FILEMGR_PBDELETEFORK
:
1666 case FILEMGR_PBITERATEFORK
:
1667 p
= "PBIterateFork";
1670 case FILEMGR_PBOPENFORK
:
1674 case FILEMGR_PBREADFORK
:
1678 case FILEMGR_PBWRITEFORK
:
1682 case FILEMGR_PBALLOCATEFORK
:
1683 p
= "PBAllocateFork";
1686 case FILEMGR_PBDELETEOBJECT
:
1687 p
= "PBDeleteObject";
1690 case FILEMGR_PBEXCHANGEOBJECT
:
1691 p
= "PBExchangeObject";
1694 case FILEMGR_PBGETFORKCBINFO
:
1695 p
= "PBGetForkCBInfo";
1698 case FILEMGR_PBGETVOLUMEINFO
:
1699 p
= "PBGetVolumeInfo";
1702 case FILEMGR_PBMAKEFSREF
:
1706 case FILEMGR_PBMAKEFSREFUNICODE
:
1707 p
= "PBMakeFSRefUnicode";
1710 case FILEMGR_PBMOVEOBJECT
:
1714 case FILEMGR_PBOPENITERATOR
:
1715 p
= "PBOpenIterator";
1718 case FILEMGR_PBRENAMEUNICODE
:
1719 p
= "PBRenameUnicode";
1722 case FILEMGR_PBSETCATALOGINFO
:
1723 p
= "SetCatalogInfo";
1726 case FILEMGR_PBSETVOLUMEINFO
:
1727 p
= "SetVolumeInfo";
1730 case FILEMGR_FSREFMAKEPATH
:
1731 p
= "FSRefMakePath";
1734 case FILEMGR_FSPATHMAKEREF
:
1735 p
= "FSPathMakeRef";
1738 case FILEMGR_PBGETCATINFO
:
1742 case FILEMGR_PBGETCATINFOLITE
:
1743 p
= "GetCatInfoLite";
1746 case FILEMGR_PBHGETFINFO
:
1750 case FILEMGR_PBXGETVOLINFO
:
1751 p
= "PBXGetVolInfo";
1754 case FILEMGR_PBHCREATE
:
1758 case FILEMGR_PBHOPENDF
:
1762 case FILEMGR_PBHOPENRF
:
1766 case FILEMGR_PBHGETDIRACCESS
:
1767 p
= "PBHGetDirAccess";
1770 case FILEMGR_PBHSETDIRACCESS
:
1771 p
= "PBHSetDirAccess";
1774 case FILEMGR_PBHMAPID
:
1778 case FILEMGR_PBHMAPNAME
:
1782 case FILEMGR_PBCLOSE
:
1786 case FILEMGR_PBFLUSHFILE
:
1790 case FILEMGR_PBGETEOF
:
1794 case FILEMGR_PBSETEOF
:
1798 case FILEMGR_PBGETFPOS
:
1802 case FILEMGR_PBREAD
:
1806 case FILEMGR_PBWRITE
:
1810 case FILEMGR_PBGETFCBINFO
:
1814 case FILEMGR_PBSETFINFO
:
1818 case FILEMGR_PBALLOCATE
:
1822 case FILEMGR_PBALLOCCONTIG
:
1823 p
= "PBAllocContig";
1826 case FILEMGR_PBSETFPOS
:
1830 case FILEMGR_PBSETCATINFO
:
1834 case FILEMGR_PBGETVOLPARMS
:
1835 p
= "PBGetVolParms";
1838 case FILEMGR_PBSETVINFO
:
1842 case FILEMGR_PBMAKEFSSPEC
:
1846 case FILEMGR_PBHGETVINFO
:
1850 case FILEMGR_PBCREATEFILEIDREF
:
1851 p
= "PBCreateFileIDRef";
1854 case FILEMGR_PBDELETEFILEIDREF
:
1855 p
= "PBDeleteFileIDRef";
1858 case FILEMGR_PBRESOLVEFILEIDREF
:
1859 p
= "PBResolveFileIDRef";
1862 case FILEMGR_PBFLUSHVOL
:
1866 case FILEMGR_PBHRENAME
:
1870 case FILEMGR_PBCATMOVE
:
1874 case FILEMGR_PBEXCHANGEFILES
:
1875 p
= "PBExchangeFiles";
1878 case FILEMGR_PBHDELETE
:
1882 case FILEMGR_PBDIRCREATE
:
1886 case FILEMGR_PBCATSEARCH
:
1890 case FILEMGR_PBHSETFLOCK
:
1894 case FILEMGR_PBHRSTFLOCK
:
1898 case FILEMGR_PBLOCKRANGE
:
1902 case FILEMGR_PBUNLOCKRANGE
:
1903 p
= "PBUnlockRange";
1910 filemgr_calls
[code
].fm_name
= p
;
1921 char *myname
= "fs_usage";
1925 if (0 != reexec_to_match_kernel()) {
1926 fprintf(stderr
, "Could not re-execute: %d\n", errno
);
1935 if ((myname
= rindex(argv
[0], '/')) == 0)
1941 while ((ch
= getopt(argc
, argv
, "ewf:R:S:E:")) != EOF
) {
1947 exclude_default_pids
= 0;
1952 if ((uint
)columns
< MAX_WIDE_MODE_COLS
)
1953 columns
= MAX_WIDE_MODE_COLS
;
1957 if (!strcmp(optarg
, "network"))
1958 filter_mode
|= NETWORK_FILTER
;
1959 else if (!strcmp(optarg
, "filesys"))
1960 filter_mode
|= FILESYS_FILTER
;
1961 else if (!strcmp(optarg
, "cachehit"))
1962 filter_mode
&= ~CACHEHIT_FILTER
; /* turns on CACHE_HIT */
1963 else if (!strcmp(optarg
, "exec"))
1964 filter_mode
|= EXEC_FILTER
;
1965 else if (!strcmp(optarg
, "pathname"))
1966 filter_mode
|= PATHNAME_FILTER
;
1975 start_time
= atof(optarg
);
1979 end_time
= atof(optarg
);
1987 if ( geteuid() != 0 ) {
1988 fprintf(stderr
, "'fs_usage' must be run as root...\n");
1996 * when excluding, fs_usage should be the first in line for pids[]
1998 * the !exclude_pids && argc == 0 catches the exclude_default_pids
1999 * case below where exclude_pids is later set and the fs_usage PID
2000 * needs to make it into pids[]
2002 if (exclude_pids
|| (!exclude_pids
&& argc
== 0)) {
2003 if (num_of_pids
< (MAX_PIDS
- 1))
2004 pids
[num_of_pids
++] = getpid();
2008 * If we process any list of pids/cmds, then turn off the defaults
2011 exclude_default_pids
= 0;
2013 while (argc
> 0 && num_of_pids
< (MAX_PIDS
- 1)) {
2020 * Exclude a set of default pids
2022 if (exclude_default_pids
) {
2023 argtopid("Terminal");
2024 argtopid("telnetd");
2027 argtopid("rlogind");
2034 for (i
= 0; i
< num_of_pids
; i
++) {
2036 fprintf(stderr
, "exclude pid %d\n", pids
[i
]);
2038 fprintf(stderr
, "pid %d\n", pids
[i
]);
2042 struct sigaction osa
;
2046 /* set up signal handlers */
2047 signal(SIGINT
, leave
);
2048 signal(SIGQUIT
, leave
);
2050 sigaction(SIGHUP
, (struct sigaction
*)NULL
, &osa
);
2052 if (osa
.sa_handler
== SIG_DFL
)
2053 signal(SIGHUP
, leave
);
2054 signal(SIGTERM
, leave
);
2056 * grab the number of cpus
2061 len
= sizeof(num_cpus
);
2063 sysctl(mib
, 2, &num_cpus
, &len
, NULL
, 0);
2064 num_events
= EVENT_BASE
* num_cpus
;
2066 signal(SIGWINCH
, sigwinch
);
2068 if ((my_buffer
= malloc(num_events
* sizeof(kd_buf
))) == (char *)0)
2069 quit("can't allocate memory for tracing info\n");
2071 if (ReadSharedCacheMap("/var/db/dyld/dyld_shared_cache_i386.map", &framework32
, "/var/db/dyld/dyld_shared_cache_i386")) {
2072 ReadSharedCacheMap("/var/db/dyld/dyld_shared_cache_x86_64.map", &framework64
, "/var/db/dyld/dyld_shared_cache_x86_64");
2074 ReadSharedCacheMap("/var/db/dyld/dyld_shared_cache_ppc.map", &framework32
, "/var/db/dyld/dyld_shared_cache_ppc");
2075 ReadSharedCacheMap("/var/db/dyld/dyld_shared_cache_ppc64.map", &framework64
, "/var/db/dyld/dyld_shared_cache_ppc64");
2077 SortFrameworkAddresses();
2084 set_numbufs(num_events
);
2087 if (exclude_pids
== 0) {
2088 for (i
= 0; i
< num_of_pids
; i
++)
2089 set_pidcheck(pids
[i
], 1);
2091 for (i
= 0; i
< num_of_pids
; i
++)
2092 set_pidexclude(pids
[i
], 1);
2094 if (select_pid_mode
&& !one_good_pid
) {
2096 * An attempt to restrict output to a given
2097 * pid or command has failed. Exit gracefully
2104 init_arguments_buffer();
2115 usleep(1000 * usleep_ms
);
2119 last_time
= time((long *)0);
2128 struct kinfo_proc
*kp
;
2132 mib
[2] = KERN_PROC_ALL
;
2135 if (sysctl(mib
, 4, NULL
, &bufSize
, NULL
, 0) < 0)
2136 quit("trace facility failure, KERN_PROC_ALL\n");
2138 if ((kp
= (struct kinfo_proc
*)malloc(bufSize
)) == (struct kinfo_proc
*)0)
2139 quit("can't allocate memory for proc buffer\n");
2141 if (sysctl(mib
, 4, kp
, &bufSize
, NULL
, 0) < 0)
2142 quit("trace facility failure, KERN_PROC_ALL\n");
2144 kp_nentries
= bufSize
/ sizeof(struct kinfo_proc
);
2153 mib
[1] = KERN_KDEBUG
;
2154 mib
[2] = KERN_KDENABLE
; /* protocol */
2157 mib
[5] = 0; /* no flags */
2159 if (sysctl(mib
, 4, NULL
, &needed
, NULL
, 0) < 0)
2160 quit("trace facility failure, KERN_KDENABLE\n");
2169 set_numbufs(int nbufs
)
2172 mib
[1] = KERN_KDEBUG
;
2173 mib
[2] = KERN_KDSETBUF
;
2176 mib
[5] = 0; /* no flags */
2178 if (sysctl(mib
, 4, NULL
, &needed
, NULL
, 0) < 0)
2179 quit("trace facility failure, KERN_KDSETBUF\n");
2182 mib
[1] = KERN_KDEBUG
;
2183 mib
[2] = KERN_KDSETUP
;
2186 mib
[5] = 0; /* no flags */
2188 if (sysctl(mib
, 3, NULL
, &needed
, NULL
, 0) < 0)
2189 quit("trace facility failure, KERN_KDSETUP\n");
2193 set_pidcheck(int pid
, int on_off
)
2197 kr
.type
= KDBG_TYPENONE
;
2200 needed
= sizeof(kd_regtype
);
2202 mib
[1] = KERN_KDEBUG
;
2203 mib
[2] = KERN_KDPIDTR
;
2208 if (sysctl(mib
, 3, &kr
, &needed
, NULL
, 0) < 0) {
2210 fprintf(stderr
, "pid %d does not exist\n", pid
);
2216 * on_off == 0 turns off pid exclusion
2217 * on_off == 1 turns on pid exclusion
2220 set_pidexclude(int pid
, int on_off
)
2226 kr
.type
= KDBG_TYPENONE
;
2229 needed
= sizeof(kd_regtype
);
2231 mib
[1] = KERN_KDEBUG
;
2232 mib
[2] = KERN_KDPIDEX
;
2237 if (sysctl(mib
, 3, &kr
, &needed
, NULL
, 0) < 0) {
2239 fprintf(stderr
, "pid %d does not exist\n", pid
);
2244 get_bufinfo(kbufinfo_t
*val
)
2246 needed
= sizeof (*val
);
2248 mib
[1] = KERN_KDEBUG
;
2249 mib
[2] = KERN_KDGETBUF
;
2252 mib
[5] = 0; /* no flags */
2254 if (sysctl(mib
, 3, val
, &needed
, 0, 0) < 0)
2255 quit("trace facility failure, KERN_KDGETBUF\n");
2265 mib
[1] = KERN_KDEBUG
;
2266 mib
[2] = KERN_KDREMOVE
; /* protocol */
2269 mib
[5] = 0; /* no flags */
2271 if (sysctl(mib
, 3, NULL
, &needed
, NULL
, 0) < 0) {
2272 set_remove_flag
= 0;
2275 quit("the trace facility is currently in use...\n fs_usage, sc_usage, and latency use this feature.\n\n");
2277 quit("trace facility failure, KERN_KDREMOVE\n");
2285 kr
.type
= KDBG_RANGETYPE
;
2288 needed
= sizeof(kd_regtype
);
2291 mib
[1] = KERN_KDEBUG
;
2292 mib
[2] = KERN_KDSETREG
;
2295 mib
[5] = 0; /* no flags */
2297 if (sysctl(mib
, 3, &kr
, &needed
, NULL
, 0) < 0)
2298 quit("trace facility failure, KERN_KDSETREG\n");
2301 mib
[1] = KERN_KDEBUG
;
2302 mib
[2] = KERN_KDSETUP
;
2305 mib
[5] = 0; /* no flags */
2307 if (sysctl(mib
, 3, NULL
, &needed
, NULL
, 0) < 0)
2308 quit("trace facility failure, KERN_KDSETUP\n");
2317 uint32_t my_buffer_size
= 0;
2320 get_bufinfo(&bufinfo
);
2322 my_buffer_size
= num_events
* sizeof(kd_buf
);
2329 needed
= bufinfo
.nkdbufs
* sizeof(kd_buf
);
2332 mib
[1] = KERN_KDEBUG
;
2333 mib
[2] = KERN_KDREADTR
;
2336 mib
[5] = 0; /* no flags */
2338 if (sysctl(mib
, 3, my_buffer
, &needed
, NULL
, 0) < 0)
2339 quit("trace facility failure, KERN_KDREADTR\n");
2342 if (count
> (num_events
/ 8)) {
2343 if (usleep_ms
> USLEEP_BEHIND
)
2344 usleep_ms
= USLEEP_BEHIND
;
2345 else if (usleep_ms
> USLEEP_MIN
)
2348 } else if (count
< (num_events
/ 16)) {
2349 if (usleep_ms
< USLEEP_MAX
)
2353 if (bufinfo
.flags
& KDBG_WRAPPED
) {
2354 fprintf(stderr
, "fs_usage: buffer overrun, events generated too quickly: %d\n", count
);
2356 delete_all_events();
2366 if ((bytes_read
= read(RAW_fd
, my_buffer
, my_buffer_size
)) < sizeof(kd_buf
))
2368 count
= bytes_read
/ sizeof(kd_buf
);
2370 kd
= (kd_buf
*)my_buffer
;
2372 fprintf(stderr
, "READTR returned %d items\n", count
);
2374 for (i
= 0; i
< count
; i
++) {
2388 thread
= kd
[i
].arg5
;
2389 debugid
= kd
[i
].debugid
;
2390 type
= kd
[i
].debugid
& DBG_FUNC_MASK
;
2392 now
= kdbg_get_timestamp(&kd
[i
]);
2394 if (i
== 0 && !RAW_flag
) {
2396 curr_time
= time((long *)0);
2398 * Compute bias seconds after each trace buffer read.
2399 * This helps resync timestamps with the system clock
2400 * in the event of a system sleep.
2402 if (bias_secs
== 0 || curr_time
< last_time
|| curr_time
> (last_time
+ 2)) {
2403 l_usecs
= (long long)(now
/ divisor
);
2404 secs
= l_usecs
/ 1000000;
2405 bias_secs
= curr_time
- secs
;
2408 if (RAW_flag
&& bias_now
== 0.0)
2411 if ((type
& P_DISKIO_MASK
) == P_DISKIO
) {
2412 insert_diskio(type
, kd
[i
].arg1
, kd
[i
].arg2
, kd
[i
].arg3
, kd
[i
].arg4
, thread
, (double)now
);
2415 if ((type
& P_DISKIO_MASK
) == P_DISKIO_DONE
) {
2416 if ((dio
= complete_diskio(kd
[i
].arg1
, kd
[i
].arg4
, kd
[i
].arg3
, thread
, (double)now
))) {
2424 case P_CS_ReadChunk
:
2425 case P_CS_WriteChunk
:
2427 case P_CS_MetaWrite
:
2428 insert_diskio(type
, kd
[i
].arg2
, kd
[i
].arg1
, kd
[i
].arg3
, kd
[i
].arg4
, thread
, (double)now
);
2431 case P_CS_Originated_Read
:
2432 case P_CS_Originated_Write
:
2433 insert_diskio(type
, kd
[i
].arg2
, CS_DEV
, kd
[i
].arg3
, kd
[i
].arg4
, thread
, (double)now
);
2436 case P_CS_ReadChunkDone
:
2437 case P_CS_WriteChunkDone
:
2438 case P_CS_Originated_ReadDone
:
2439 case P_CS_Originated_WriteDone
:
2440 case P_CS_MetaReadDone
:
2441 case P_CS_MetaWriteDone
:
2442 if ((dio
= complete_diskio(kd
[i
].arg2
, kd
[i
].arg4
, kd
[i
].arg3
, thread
, (double)now
))) {
2448 case TRACE_DATA_NEWTHREAD
:
2450 if ((ti
= add_event(thread
, TRACE_DATA_NEWTHREAD
)) == NULL
)
2452 ti
->child_thread
= kd
[i
].arg1
;
2453 ti
->pid
= kd
[i
].arg2
;
2457 case TRACE_STRING_NEWTHREAD
:
2458 if ((ti
= find_event(thread
, TRACE_DATA_NEWTHREAD
)) == (struct th_info
*)0)
2461 create_map_entry(ti
->child_thread
, ti
->pid
, (char *)&kd
[i
].arg1
);
2466 case TRACE_DATA_EXEC
:
2467 if ((ti
= add_event(thread
, TRACE_DATA_EXEC
)) == NULL
)
2470 ti
->pid
= kd
[i
].arg1
;
2473 case TRACE_STRING_EXEC
:
2474 if ((ti
= find_event(thread
, BSC_execve
))) {
2475 if (ti
->pathname
[0])
2476 exit_event("execve", thread
, BSC_execve
, 0, 0, 0, 0, FMT_DEFAULT
, (double)now
);
2478 } else if ((ti
= find_event(thread
, BSC_posix_spawn
))) {
2479 if (ti
->pathname
[0])
2480 exit_event("posix_spawn", thread
, BSC_posix_spawn
, 0, 0, 0, 0, FMT_DEFAULT
, (double)now
);
2482 if ((ti
= find_event(thread
, TRACE_DATA_EXEC
)) == (struct th_info
*)0)
2485 create_map_entry(thread
, ti
->pid
, (char *)&kd
[i
].arg1
);
2490 case BSC_thread_terminate
:
2491 delete_map_entry(thread
);
2498 kd
[i
].arg1
= kd
[i
].arg2
>> 8;
2503 if (kd
[i
].arg4
& MAP_ANON
)
2509 case MACH_stkhandoff
:
2510 mark_thread_waited(thread
);
2514 if ((ti
= find_event(thread
, 0)) == (struct th_info
*)0)
2517 if (debugid
& DBG_FUNC_START
) {
2518 if (ti
->pathname2
[0])
2520 if (ti
->pathname
[0] == 0)
2521 sargptr
= ti
->pathname
;
2523 sargptr
= ti
->pathname2
;
2524 *sargptr
++ = kd
[i
].arg2
;
2525 *sargptr
++ = kd
[i
].arg3
;
2526 *sargptr
++ = kd
[i
].arg4
;
2528 * NULL terminate the 'string'
2532 ti
->pathptr
= sargptr
;
2534 sargptr
= ti
->pathptr
;
2537 * We don't want to overrun our pathname buffer if the
2538 * kernel sends us more VFS_LOOKUP entries than we can
2539 * handle and we only handle 2 pathname lookups for
2540 * a given system call
2544 if (ti
->pathname2
[0]) {
2545 if ((uintptr_t)sargptr
>= (uintptr_t)&ti
->pathname2
[NUMPARMS
])
2548 if ((uintptr_t)sargptr
>= (uintptr_t)&ti
->pathname
[NUMPARMS
])
2551 *sargptr
++ = kd
[i
].arg1
;
2552 *sargptr
++ = kd
[i
].arg2
;
2553 *sargptr
++ = kd
[i
].arg3
;
2554 *sargptr
++ = kd
[i
].arg4
;
2556 * NULL terminate the 'string'
2560 if (debugid
& DBG_FUNC_END
) {
2561 if (ti
->pathname2
[0])
2564 ti
->pathptr
= ti
->pathname2
;
2566 ti
->pathptr
= sargptr
;
2571 if (debugid
& DBG_FUNC_START
) {
2574 if ((type
& CLASS_MASK
) == FILEMGR_BASE
) {
2576 index
= filemgr_index(type
);
2578 if (index
>= MAX_FILEMGR
)
2581 if ((p
= filemgr_calls
[index
].fm_name
) == NULL
)
2586 enter_event(thread
, type
, &kd
[i
], p
, (double)now
);
2593 exit_event(" THROTTLED", thread
, type
, 0, 0, 0, 0, FMT_DEFAULT
, (double)now
);
2596 case P_CS_SYNC_DISK
:
2597 exit_event(" SyncCacheCS", thread
, type
, kd
[i
].arg1
, 0, 0, 0, FMT_SYNC_DISK_CS
, (double)now
);
2601 if (kd
[i
].arg2
== DKIOCSYNCHRONIZECACHE
)
2602 exit_event("IOCTL", thread
, type
, kd
[i
].arg1
, kd
[i
].arg2
, 0, 0, FMT_SPEC_IOCTL
, (double)now
);
2604 if ((ti
= find_event(thread
, type
)))
2611 exit_event("PAGE_OUT_ANON", thread
, type
, 0, kd
[i
].arg1
, 0, 0, FMT_PGOUT
, (double)now
);
2613 exit_event("PAGE_OUT_FILE", thread
, type
, 0, kd
[i
].arg1
, 0, 0, FMT_PGOUT
, (double)now
);
2617 if (kd
[i
].arg4
== DBG_PAGEIN_FAULT
)
2618 exit_event("PAGE_IN", thread
, type
, 0, kd
[i
].arg1
, kd
[i
].arg2
, 0, FMT_PGIN
, (double)now
);
2619 else if (kd
[i
].arg4
== DBG_PAGEINV_FAULT
)
2620 exit_event("PAGE_IN_FILE", thread
, type
, 0, kd
[i
].arg1
, kd
[i
].arg2
, 0, FMT_PGIN
, (double)now
);
2621 else if (kd
[i
].arg4
== DBG_PAGEIND_FAULT
)
2622 exit_event("PAGE_IN_ANON", thread
, type
, 0, kd
[i
].arg1
, kd
[i
].arg2
, 0, FMT_PGIN
, (double)now
);
2623 else if (kd
[i
].arg4
== DBG_CACHE_HIT_FAULT
)
2624 exit_event("CACHE_HIT", thread
, type
, 0, kd
[i
].arg1
, kd
[i
].arg2
, 0, FMT_CACHEHIT
, (double)now
);
2626 if ((ti
= find_event(thread
, type
)))
2632 exit_event("map_fd", thread
, type
, kd
[i
].arg1
, kd
[i
].arg2
, 0, 0, FMT_FD
, (double)now
);
2635 case BSC_mmap_extended
:
2636 case BSC_mmap_extended2
:
2637 case BSC_msync_extended
:
2638 case BSC_pread_extended
:
2639 case BSC_pwrite_extended
:
2640 extend_syscall(thread
, type
, &kd
[i
]);
2644 if ((type
& CSC_MASK
) == BSC_BASE
) {
2646 if ((index
= BSC_INDEX(type
)) >= MAX_BSD_SYSCALL
)
2649 if (bsd_syscalls
[index
].sc_name
) {
2650 exit_event(bsd_syscalls
[index
].sc_name
, thread
, type
, kd
[i
].arg1
, kd
[i
].arg2
, kd
[i
].arg3
, kd
[i
].arg4
,
2651 bsd_syscalls
[index
].sc_format
, (double)now
);
2653 if (type
== BSC_exit
)
2654 delete_map_entry(thread
);
2656 } else if ((type
& CLASS_MASK
) == FILEMGR_BASE
) {
2658 if ((index
= filemgr_index(type
)) >= MAX_FILEMGR
)
2661 if (filemgr_calls
[index
].fm_name
) {
2662 exit_event(filemgr_calls
[index
].fm_name
, thread
, type
, kd
[i
].arg1
, kd
[i
].arg2
, kd
[i
].arg3
, kd
[i
].arg4
,
2663 FMT_DEFAULT
, (double)now
);
2672 enter_event_now(uintptr_t thread
, int type
, kd_buf
*kd
, char *name
, double now
)
2686 if ((ti
= add_event(thread
, type
)) == NULL
)
2690 ti
->arg1
= kd
->arg1
;
2691 ti
->arg2
= kd
->arg2
;
2692 ti
->arg3
= kd
->arg3
;
2693 ti
->arg4
= kd
->arg4
;
2695 if ((type
& CLASS_MASK
) == FILEMGR_BASE
&&
2696 (!RAW_flag
|| (now
>= start_time
&& now
<= end_time
))) {
2698 filemgr_in_progress
++;
2702 l_usecs
= (long long)((now
- bias_now
) / divisor
);
2703 l_usecs
+= (sample_TOD_secs
* 1000000) + sample_TOD_usecs
;
2705 l_usecs
= (long long)(now
/ divisor
);
2706 secs
= l_usecs
/ 1000000;
2707 curr_time
= bias_secs
+ secs
;
2709 sprintf(buf
, "%-8.8s", &(ctime(&curr_time
)[11]));
2710 tsclen
= strlen(buf
);
2712 if (columns
> MAXCOLS
|| wideflag
) {
2713 usecs
= l_usecs
- (long long)((long long)secs
* 1000000);
2714 sprintf(&buf
[tsclen
], ".%06ld", (long)usecs
);
2715 tsclen
= strlen(buf
);
2719 * Print timestamp column
2723 tme
= find_map_entry(thread
);
2725 sprintf(buf
, " %-25.25s ", name
);
2726 nmclen
= strlen(buf
);
2729 sprintf(buf
, "(%d, 0x%lx, 0x%lx, 0x%lx)", (short)kd
->arg1
, kd
->arg2
, kd
->arg3
, kd
->arg4
);
2730 argsclen
= strlen(buf
);
2733 * Calculate white space out to command
2735 if (columns
> MAXCOLS
|| wideflag
) {
2736 clen
= columns
- (tsclen
+ nmclen
+ argsclen
+ 20 + 11);
2738 clen
= columns
- (tsclen
+ nmclen
+ argsclen
+ 12);
2741 printf("%s", buf
); /* print the kdargs */
2742 memset(buf
, ' ', clen
);
2746 else if ((argsclen
+ clen
) > 0) {
2748 * no room so wipe out the kdargs
2750 memset(buf
, ' ', (argsclen
+ clen
));
2751 buf
[argsclen
+ clen
] = '\0';
2754 if (columns
> MAXCOLS
|| wideflag
)
2755 printf("%s.%d\n", tme
->tm_command
, (int)thread
);
2757 printf("%-12.12s\n", tme
->tm_command
);
2759 printf(" %-24.24s (%5d, %#lx, 0x%lx, 0x%lx)\n", name
, (short)kd
->arg1
, kd
->arg2
, kd
->arg3
, kd
->arg4
);
2765 enter_event(uintptr_t thread
, int type
, kd_buf
*kd
, char *name
, double now
)
2769 if (type
== MACH_pageout
|| type
== MACH_vmfault
|| type
== MSC_map_fd
|| type
== SPEC_ioctl
|| type
== Throttled
|| type
== P_CS_SYNC_DISK
) {
2770 enter_event_now(thread
, type
, kd
, name
, now
);
2773 if ((type
& CSC_MASK
) == BSC_BASE
) {
2775 if ((index
= BSC_INDEX(type
)) >= MAX_BSD_SYSCALL
)
2778 if (bsd_syscalls
[index
].sc_name
)
2779 enter_event_now(thread
, type
, kd
, name
, now
);
2782 if ((type
& CLASS_MASK
) == FILEMGR_BASE
) {
2784 if ((index
= filemgr_index(type
)) >= MAX_FILEMGR
)
2787 if (filemgr_calls
[index
].fm_name
)
2788 enter_event_now(thread
, type
, kd
, name
, now
);
2793 * Handle system call extended trace data.
2795 * Wipe out the kd args that were collected upon syscall_entry
2796 * because it is the extended info that we really want, and it
2797 * is all we really need.
2801 extend_syscall(uintptr_t thread
, int type
, kd_buf
*kd
)
2806 case BSC_mmap_extended
:
2807 if ((ti
= find_event(thread
, BSC_mmap
)) == (struct th_info
*)0)
2809 ti
->arg8
= ti
->arg3
; /* save protection */
2810 ti
->arg1
= kd
->arg1
; /* the fd */
2811 ti
->arg3
= kd
->arg2
; /* bottom half address */
2812 ti
->arg5
= kd
->arg3
; /* bottom half size */
2814 case BSC_mmap_extended2
:
2815 if ((ti
= find_event(thread
, BSC_mmap
)) == (struct th_info
*)0)
2817 ti
->arg2
= kd
->arg1
; /* top half address */
2818 ti
->arg4
= kd
->arg2
; /* top half size */
2819 ti
->arg6
= kd
->arg3
; /* top half file offset */
2820 ti
->arg7
= kd
->arg4
; /* bottom half file offset */
2822 case BSC_msync_extended
:
2823 if ((ti
= find_event(thread
, BSC_msync
)) == (struct th_info
*)0) {
2824 if ((ti
= find_event(thread
, BSC_msync_nocancel
)) == (struct th_info
*)0)
2827 ti
->arg4
= kd
->arg1
; /* top half address */
2828 ti
->arg5
= kd
->arg2
; /* top half size */
2830 case BSC_pread_extended
:
2831 if ((ti
= find_event(thread
, BSC_pread
)) == (struct th_info
*)0) {
2832 if ((ti
= find_event(thread
, BSC_pread_nocancel
)) == (struct th_info
*)0)
2835 ti
->arg1
= kd
->arg1
; /* the fd */
2836 ti
->arg2
= kd
->arg2
; /* nbytes */
2837 ti
->arg3
= kd
->arg3
; /* top half offset */
2838 ti
->arg4
= kd
->arg4
; /* bottom half offset */
2840 case BSC_pwrite_extended
:
2841 if ((ti
= find_event(thread
, BSC_pwrite
)) == (struct th_info
*)0) {
2842 if ((ti
= find_event(thread
, BSC_pwrite_nocancel
)) == (struct th_info
*)0)
2845 ti
->arg1
= kd
->arg1
; /* the fd */
2846 ti
->arg2
= kd
->arg2
; /* nbytes */
2847 ti
->arg3
= kd
->arg3
; /* top half offset */
2848 ti
->arg4
= kd
->arg4
; /* bottom half offset */
2857 exit_event(char *sc_name
, uintptr_t thread
, int type
, int arg1
, int arg2
, int arg3
, int arg4
,
2858 int format
, double now
)
2862 if ((ti
= find_event(thread
, type
)) == (struct th_info
*)0)
2865 if (check_filter_mode(ti
, type
, arg1
, arg2
, sc_name
))
2866 format_print(ti
, sc_name
, thread
, type
, arg1
, arg2
, arg3
, arg4
, format
, now
, ti
->stime
, ti
->waited
, (char *)ti
->pathname
, NULL
);
2868 if ((type
& CLASS_MASK
) == FILEMGR_BASE
) {
2871 if (filemgr_in_progress
> 0)
2872 filemgr_in_progress
--;
2879 get_mode_nibble(char * buf
, int smode
, int special
, char x_on
, char x_off
)
2898 get_mode_string(int mode
, char *buf
)
2900 memset(buf
, '-', 9);
2903 get_mode_nibble(&buf
[6], mode
, (mode
& 01000), 't', 'T');
2904 get_mode_nibble(&buf
[3], (mode
>>3), (mode
& 02000), 's', 'S');
2905 get_mode_nibble(&buf
[0], (mode
>>6), (mode
& 04000), 's', 'S');
2909 int clip_64bit(char *s
, uint64_t value
)
2913 if ( (value
& 0xff00000000000000LL
) )
2914 clen
= printf("%s0x%16.16qx", s
, value
);
2915 else if ( (value
& 0x00ff000000000000LL
) )
2916 clen
= printf("%s0x%14.14qx ", s
, value
);
2917 else if ( (value
& 0x0000ff0000000000LL
) )
2918 clen
= printf("%s0x%12.12qx ", s
, value
);
2919 else if ( (value
& 0x000000ff00000000LL
) )
2920 clen
= printf("%s0x%10.10qx ", s
, value
);
2922 clen
= printf("%s0x%8.8qx ", s
, value
);
2929 format_print(struct th_info
*ti
, char *sc_name
, uintptr_t thread
, int type
, int arg1
, int arg2
, int arg3
, int arg4
,
2930 int format
, double now
, double stime
, int waited
, char *pathname
, struct diskio
*dio
)
2945 char *framework_name
;
2946 char *framework_type
;
2950 char cs_diskname
[32];
2952 static char timestamp
[32];
2953 static int last_timestamp
= -1;
2954 static int timestamp_len
= 0;
2957 l_usecs
= (long long)((now
- bias_now
) / divisor
);
2959 if ((double)l_usecs
< start_time
|| (double)l_usecs
> end_time
)
2962 l_usecs
+= (sample_TOD_secs
* 1000000) + sample_TOD_usecs
;
2965 l_usecs
= (long long)(now
/ divisor
);
2966 secs
= l_usecs
/ 1000000;
2967 curr_time
= bias_secs
+ secs
;
2972 command_name
= dio
->issuing_command
;
2976 if ((tme
= find_map_entry(thread
)))
2977 command_name
= tme
->tm_command
;
2979 if (last_timestamp
!= curr_time
) {
2980 timestamp_len
= sprintf(timestamp
, "%-8.8s", &(ctime(&curr_time
)[11]));
2981 last_timestamp
= curr_time
;
2983 if (columns
> MAXCOLS
|| wideflag
) {
2986 tlen
= timestamp_len
;
2988 usec
= (l_usecs
- (long long)((long long)secs
* 1000000));
2990 sprintf(×tamp
[tlen
], ".%06ld", (long)usec
);
2993 timestamp
[tlen
] = '\0';
2995 if (filemgr_in_progress
) {
2996 if (class != FILEMGR_CLASS
) {
2997 if (find_event(thread
, -1))
3004 if ((class == FILEMGR_CLASS
) && (columns
> MAXCOLS
|| wideflag
))
3005 clen
= printf("%s %-20.20s", timestamp
, sc_name
);
3006 else if (in_filemgr
)
3007 clen
= printf("%s %-15.15s", timestamp
, sc_name
);
3009 clen
= printf("%s %-17.17s", timestamp
, sc_name
);
3012 framework_name
= NULL
;
3014 if (columns
> MAXCOLS
|| wideflag
) {
3016 off_t offset_reassembled
= 0LL;
3022 * pathname based system calls or
3023 * calls with no fd or pathname (i.e. sync)
3026 clen
+= printf(" [%3d] ", arg1
);
3028 clen
+= printf(" ");
3033 * fd based system call... no I/O
3036 clen
+= printf(" F=%-3d[%3d]", ti
->arg1
, arg1
);
3038 clen
+= printf(" F=%-3d", ti
->arg1
);
3046 clen
+= printf(" F=%-3d[%3d]", ti
->arg1
, arg1
);
3048 clen
+= printf(" F=%-3d F=%-3d", ti
->arg1
, arg2
);
3053 * system calls with fd's that return an I/O completion count
3056 clen
+= printf(" F=%-3d[%3d]", ti
->arg1
, arg1
);
3058 clen
+= printf(" F=%-3d B=0x%-6x", ti
->arg1
, arg2
);
3065 user_addr
= ((uint64_t)arg2
<< 32) | (uint32_t)arg3
;
3067 lookup_name(user_addr
, &framework_type
, &framework_name
);
3068 clen
+= clip_64bit(" A=", user_addr
);
3075 user_addr
= ((uint64_t)arg2
<< 32) | (uint32_t)arg3
;
3077 lookup_name(user_addr
, &framework_type
, &framework_name
);
3078 clen
+= clip_64bit(" A=", user_addr
);
3085 clen
+= printf(" B=0x%-8x", arg2
);
3093 clen
+= printf(" D=0x%8.8x [%3d]", dio
->blkno
, dio
->io_errno
);
3095 clen
+= printf(" D=0x%8.8x B=0x%-6x /dev/%s", dio
->blkno
, dio
->iosize
, find_disk_name(dio
->dev
));
3103 clen
+= printf(" D=0x%8.8x [%3d]", dio
->blkno
, dio
->io_errno
);
3105 clen
+= printf(" D=0x%8.8x B=0x%-6x /dev/%s", dio
->blkno
, dio
->iosize
, generate_cs_disk_name(dio
->dev
, &cs_diskname
[0]));
3108 case FMT_SYNC_DISK_CS
:
3110 * physical disk sync cache
3112 clen
+= printf(" /dev/%s", generate_cs_disk_name(arg1
, &cs_diskname
[0]));
3125 if (ti
->arg3
& MS_ASYNC
)
3126 mlen
+= sprintf(&buf
[mlen
], "MS_ASYNC | ");
3128 mlen
+= sprintf(&buf
[mlen
], "MS_SYNC | ");
3130 if (ti
->arg3
& MS_INVALIDATE
)
3131 mlen
+= sprintf(&buf
[mlen
], "MS_INVALIDATE | ");
3132 if (ti
->arg3
& MS_KILLPAGES
)
3133 mlen
+= sprintf(&buf
[mlen
], "MS_KILLPAGES | ");
3134 if (ti
->arg3
& MS_DEACTIVATE
)
3135 mlen
+= sprintf(&buf
[mlen
], "MS_DEACTIVATE | ");
3137 if (ti
->arg3
& ~(MS_ASYNC
| MS_SYNC
| MS_INVALIDATE
| MS_KILLPAGES
| MS_DEACTIVATE
))
3138 mlen
+= sprintf(&buf
[mlen
], "UNKNOWN | ");
3141 buf
[mlen
- 3] = '\0';
3144 clen
+= printf(" [%3d]", arg1
);
3146 user_addr
= (((off_t
)(unsigned int)(ti
->arg4
)) << 32) | (unsigned int)(ti
->arg1
);
3147 clen
+= clip_64bit(" A=", user_addr
);
3149 user_size
= (((off_t
)(unsigned int)(ti
->arg5
)) << 32) | (unsigned int)(ti
->arg2
);
3151 clen
+= printf(" B=0x%-16qx <%s>", user_size
, buf
);
3165 clen
+= printf(" F=%-3d[%3d]", ti
->arg1
, arg1
);
3167 clen
+= printf(" F=%-3d", ti
->arg1
);
3231 case F_PATHPKG_CHECK
:
3232 p
= "PATHPKG_CHECK";
3246 case F_CHECK_OPENEVT
:
3247 p
= "CHECK_OPENEVT";
3257 case F_GLOBAL_NOCACHE
:
3259 p
= "CACHING OFF (GLOBAL)";
3261 p
= "CACHING ON (GLOBAL)";
3267 clen
+= printf(" <%s>", p
);
3269 clen
+= printf(" <%s> F=%d", p
, fd
);
3271 clen
+= printf(" <CMD=%d>", ti
->arg2
);
3282 clen
+= printf(" F=%-3d[%3d]", ti
->arg1
, arg1
);
3284 clen
+= printf(" F=%-3d", ti
->arg1
);
3286 clen
+= printf(" <CMD=0x%x>", ti
->arg2
);
3291 case FMT_SPEC_IOCTL
:
3296 clen
+= printf(" <DKIOCSYNCHRONIZECACHE> /dev/%s", find_disk_name(arg1
));
3306 clen
+= printf(" [%3d]", arg1
);
3308 clen
+= printf(" S=%-3d", arg2
);
3315 * pread, pwrite, lseek
3317 clen
+= printf(" F=%-3d", ti
->arg1
);
3320 clen
+= printf("[%3d] ", arg1
);
3322 if (format
== FMT_PREAD
)
3323 clen
+= printf(" B=0x%-8x ", arg2
);
3325 clen
+= printf(" ");
3327 if (format
== FMT_PREAD
)
3328 offset_reassembled
= (((off_t
)(unsigned int)(ti
->arg3
)) << 32) | (unsigned int)(ti
->arg4
);
3331 offset_reassembled
= (((off_t
)(unsigned int)(arg2
)) << 32) | (unsigned int)(arg3
);
3333 offset_reassembled
= (((off_t
)(unsigned int)(arg3
)) << 32) | (unsigned int)(arg2
);
3335 clen
+= clip_64bit("O=", offset_reassembled
);
3337 if (format
== FMT_LSEEK
) {
3340 if (ti
->arg4
== SEEK_SET
)
3342 else if (ti
->arg4
== SEEK_CUR
)
3344 else if (ti
->arg4
== SEEK_END
)
3349 clen
+= printf(" <%s>", mode
);
3357 clen
+= printf(" F=%-3d ", ti
->arg1
);
3360 clen
+= printf("[%3d] ", arg1
);
3363 user_addr
= (((off_t
)(unsigned int)(ti
->arg2
)) << 32) | (unsigned int)(ti
->arg3
);
3365 clen
+= clip_64bit("A=", user_addr
);
3367 offset_reassembled
= (((off_t
)(unsigned int)(ti
->arg6
)) << 32) | (unsigned int)(ti
->arg7
);
3369 clen
+= clip_64bit("O=", offset_reassembled
);
3371 user_size
= (((off_t
)(unsigned int)(ti
->arg4
)) << 32) | (unsigned int)(ti
->arg5
);
3373 clen
+= printf("B=0x%-16qx", user_size
);
3375 clen
+= printf(" <");
3377 if (ti
->arg8
& PROT_READ
)
3378 clen
+= printf("READ");
3380 if (ti
->arg8
& PROT_WRITE
)
3381 clen
+= printf("|WRITE");
3383 if (ti
->arg8
& PROT_EXEC
)
3384 clen
+= printf("|EXEC");
3386 clen
+= printf(">");
3393 * ftruncate, truncate
3395 if (format
== FMT_FTRUNC
)
3396 clen
+= printf(" F=%-3d", ti
->arg1
);
3398 clen
+= printf(" ");
3401 clen
+= printf("[%3d]", arg1
);
3404 offset_reassembled
= (((off_t
)(unsigned int)(ti
->arg2
)) << 32) | (unsigned int)(ti
->arg3
);
3406 offset_reassembled
= (((off_t
)(unsigned int)(ti
->arg3
)) << 32) | (unsigned int)(ti
->arg2
);
3408 clen
+= clip_64bit(" O=", offset_reassembled
);
3421 if (format
== FMT_FCHFLAGS
) {
3423 clen
+= printf(" F=%-3d[%3d]", ti
->arg1
, arg1
);
3425 clen
+= printf(" F=%-3d", ti
->arg1
);
3428 clen
+= printf(" [%3d] ", arg1
);
3433 if (ti
->arg2
& UF_NODUMP
)
3434 mlen
+= sprintf(&buf
[mlen
], "UF_NODUMP | ");
3435 if (ti
->arg2
& UF_IMMUTABLE
)
3436 mlen
+= sprintf(&buf
[mlen
], "UF_IMMUTABLE | ");
3437 if (ti
->arg2
& UF_APPEND
)
3438 mlen
+= sprintf(&buf
[mlen
], "UF_APPEND | ");
3439 if (ti
->arg2
& UF_OPAQUE
)
3440 mlen
+= sprintf(&buf
[mlen
], "UF_OPAQUE | ");
3441 if (ti
->arg2
& SF_ARCHIVED
)
3442 mlen
+= sprintf(&buf
[mlen
], "SF_ARCHIVED | ");
3443 if (ti
->arg2
& SF_IMMUTABLE
)
3444 mlen
+= sprintf(&buf
[mlen
], "SF_IMMUTABLE | ");
3445 if (ti
->arg2
& SF_APPEND
)
3446 mlen
+= sprintf(&buf
[mlen
], "SF_APPEND | ");
3449 mlen
+= sprintf(&buf
[mlen
], "CLEAR_ALL_FLAGS | ");
3450 else if (ti
->arg2
& ~(UF_NODUMP
| UF_IMMUTABLE
| UF_APPEND
| SF_ARCHIVED
| SF_IMMUTABLE
| SF_APPEND
))
3451 mlen
+= sprintf(&buf
[mlen
], "UNKNOWN | ");
3460 memset(&buf
[mlen
], ' ', 19 - mlen
);
3463 clen
+= printf("%s", buf
);
3471 case FMT_FCHMOD_EXT
:
3476 * fchmod, fchmod_extended, chmod, chmod_extended
3480 if (format
== FMT_FCHMOD
|| format
== FMT_FCHMOD_EXT
) {
3482 clen
+= printf(" F=%-3d[%3d] ", ti
->arg1
, arg1
);
3484 clen
+= printf(" F=%-3d ", ti
->arg1
);
3487 clen
+= printf(" [%3d] ", arg1
);
3489 clen
+= printf(" ");
3491 if (format
== FMT_UMASK
)
3493 else if (format
== FMT_FCHMOD
|| format
== FMT_CHMOD
)
3498 get_mode_string(mode
, &buf
[0]);
3501 clen
+= printf("<%s> ", buf
);
3503 clen
+= printf("<%s>", buf
);
3514 memset(mode
, '_', 4);
3517 if (ti
->arg2
& R_OK
)
3519 if (ti
->arg2
& W_OK
)
3521 if (ti
->arg2
& X_OK
)
3523 if (ti
->arg2
== F_OK
)
3527 clen
+= printf(" [%3d] (%s) ", arg1
, mode
);
3529 clen
+= printf(" (%s) ", mode
);
3538 clen
+= printf(" [%3d] <FLGS=0x%x> ", arg1
, ti
->arg3
);
3540 clen
+= printf(" <FLGS=0x%x> ", ti
->arg3
);
3550 if (ti
->arg2
& MNT_FORCE
)
3551 mountflag
= "<FORCE>";
3556 clen
+= printf(" [%3d] %s ", arg1
, mountflag
);
3558 clen
+= printf(" %s ", mountflag
);
3571 memset(mode
, '_', 6);
3574 if (ti
->arg2
& O_RDWR
) {
3577 } else if (ti
->arg2
& O_WRONLY
)
3582 if (ti
->arg2
& O_CREAT
)
3585 if (ti
->arg2
& O_APPEND
)
3588 if (ti
->arg2
& O_TRUNC
)
3591 if (ti
->arg2
& O_EXCL
)
3595 clen
+= printf(" [%3d] (%s) ", arg1
, mode
);
3597 clen
+= printf(" F=%-3d (%s) ", arg2
, mode
);
3631 domain
= "AF_IMPLINK";
3642 type
= "SOCK_STREAM";
3646 type
= "SOCK_DGRAM";
3653 case SOCK_SEQPACKET
:
3654 type
= "SOCK_SEQPACKET";
3667 clen
+= printf(" [%3d] <%s, %s, 0x%x>", arg1
, domain
, type
, ti
->arg3
);
3669 clen
+= printf(" F=%-3d <%s, %s, 0x%x>", arg2
, domain
, type
, ti
->arg3
);
3676 * aio_fsync [errno] AIOCBP OP
3680 if (ti
->arg1
== O_SYNC
|| ti
->arg1
== 0)
3683 else if (ti
->arg1
== O_DSYNC
)
3690 clen
+= printf(" [%3d] P=0x%8.8x <%s>", arg1
, ti
->arg2
, op
);
3692 clen
+= printf(" P=0x%8.8x <%s>", ti
->arg2
, op
);
3696 case FMT_AIO_RETURN
:
3698 * aio_return [errno] AIOCBP IOSIZE
3701 clen
+= printf(" [%3d] P=0x%8.8x", arg1
, ti
->arg1
);
3703 clen
+= printf(" P=0x%8.8x B=0x%-8x", ti
->arg1
, arg2
);
3706 case FMT_AIO_SUSPEND
:
3708 * aio_suspend [errno] NENTS
3711 clen
+= printf(" [%3d] N=%d", arg1
, ti
->arg2
);
3713 clen
+= printf(" N=%d", ti
->arg2
);
3716 case FMT_AIO_CANCEL
:
3718 * aio_cancel [errno] FD or AIOCBP (if non-null)
3722 clen
+= printf(" [%3d] P=0x%8.8x", arg1
, ti
->arg2
);
3724 clen
+= printf(" P=0x%8.8x", ti
->arg2
);
3727 clen
+= printf(" F=%-3d[%3d]", ti
->arg1
, arg1
);
3729 clen
+= printf(" F=%-3d", ti
->arg1
);
3735 * aio_error, aio_read, aio_write [errno] AIOCBP
3738 clen
+= printf(" [%3d] P=0x%8.8x", arg1
, ti
->arg1
);
3740 clen
+= printf(" P=0x%8.8x", ti
->arg1
);
3743 case FMT_LIO_LISTIO
:
3746 * lio_listio [errno] NENTS MODE
3750 if (ti
->arg1
== LIO_NOWAIT
)
3752 else if (ti
->arg1
== LIO_WAIT
)
3758 clen
+= printf(" [%3d] N=%d <%s>", arg1
, ti
->arg3
, op
);
3760 clen
+= printf(" N=%d <%s>", ti
->arg3
, op
);
3768 * Calculate space available to print pathname
3770 if (columns
> MAXCOLS
|| wideflag
)
3771 clen
= columns
- (clen
+ 14 + 20 + 11);
3773 clen
= columns
- (clen
+ 14 + 12);
3775 if (class != FILEMGR_CLASS
&& !nopadding
)
3779 len
= sprintf(&buf
[0], " %s %s ", framework_type
, framework_name
);
3780 else if (*pathname
!= '\0') {
3781 len
= sprintf(&buf
[0], " %s ", pathname
);
3783 if (format
== FMT_MOUNT
&& ti
->pathname2
[0]) {
3786 memset(&buf
[len
], ' ', 2);
3788 len2
= sprintf(&buf
[len
+2], " %s ", (char *)ti
->pathname2
);
3789 len
= len
+ 2 + len2
;
3796 * Add null padding if column length
3797 * is wider than the pathname length.
3799 memset(&buf
[len
], ' ', clen
- len
);
3804 } else if (clen
== len
) {
3807 } else if ((clen
> 0) && (clen
< len
)) {
3809 * This prints the tail end of the pathname
3811 buf
[len
-clen
] = ' ';
3813 pathname
= &buf
[len
- clen
];
3820 * fudge some additional system call overhead
3821 * that currently isn't tracked... this also
3822 * insures that we see a minimum of 1 us for
3825 usecs
= (unsigned long)(((now
- stime
) + (divisor
-1)) / divisor
);
3826 secs
= usecs
/ 1000000;
3827 usecs
-= secs
* 1000000;
3829 if (class != FILEMGR_CLASS
&& !nopadding
)
3839 if (columns
> MAXCOLS
|| wideflag
)
3840 printf("%s%s %3ld.%06ld%s %s.%d\n", p1
, pathname
, (unsigned long)secs
, (unsigned long)usecs
, p2
, command_name
, (int)thread
);
3842 printf("%s%s %3ld.%06ld%s %-12.12s\n", p1
, pathname
, (unsigned long)secs
, (unsigned long)usecs
, p2
, command_name
);
3847 delete_event(th_info_t ti_to_delete
) {
3852 hashid
= ti_to_delete
->thread
& HASH_MASK
;
3854 if ((ti
= th_info_hash
[hashid
])) {
3855 if (ti
== ti_to_delete
)
3856 th_info_hash
[hashid
] = ti
->next
;
3860 for (ti
= ti
->next
; ti
; ti
= ti
->next
) {
3861 if (ti
== ti_to_delete
) {
3862 ti_prev
->next
= ti
->next
;
3869 ti
->next
= th_info_freelist
;
3870 th_info_freelist
= ti
;
3876 add_event(uintptr_t thread
, int type
) {
3880 if ((ti
= th_info_freelist
))
3881 th_info_freelist
= ti
->next
;
3883 ti
= (th_info_t
)malloc(sizeof(struct th_info
));
3885 hashid
= thread
& HASH_MASK
;
3887 ti
->next
= th_info_hash
[hashid
];
3888 th_info_hash
[hashid
] = ti
;
3890 ti
->thread
= thread
;
3895 ti
->pathptr
= ti
->pathname
;
3896 ti
->pathname
[0] = 0;
3897 ti
->pathname2
[0] = 0;
3903 find_event(uintptr_t thread
, int type
) {
3907 hashid
= thread
& HASH_MASK
;
3909 for (ti
= th_info_hash
[hashid
]; ti
; ti
= ti
->next
) {
3910 if (ti
->thread
== thread
) {
3911 if (type
== ti
->type
)
3913 if (ti
->in_filemgr
) {
3922 return ((th_info_t
) 0);
3926 delete_all_events() {
3928 th_info_t ti_next
= 0;
3931 for (i
= 0; i
< HASH_SIZE
; i
++) {
3933 for (ti
= th_info_hash
[i
]; ti
; ti
= ti_next
) {
3935 ti
->next
= th_info_freelist
;
3936 th_info_freelist
= ti
;
3938 th_info_hash
[i
] = 0;
3944 mark_thread_waited(uintptr_t thread
) {
3948 hashid
= thread
& HASH_MASK
;
3950 for (ti
= th_info_hash
[hashid
]; ti
; ti
= ti
->next
) {
3951 if (ti
->thread
== thread
)
3957 void read_command_map()
3961 int total_threads
= 0;
3962 kd_threadmap
*mapptr
= 0;
3964 delete_all_map_entries();
3968 total_threads
= bufinfo
.nkdthreads
;
3969 size
= bufinfo
.nkdthreads
* sizeof(kd_threadmap
);
3972 if ((mapptr
= (kd_threadmap
*) malloc(size
))) {
3975 bzero (mapptr
, size
);
3977 * Now read the threadmap
3980 mib
[1] = KERN_KDEBUG
;
3981 mib
[2] = KERN_KDTHRMAP
;
3984 mib
[5] = 0; /* no flags */
3986 if (sysctl(mib
, 3, mapptr
, &size
, NULL
, 0) < 0) {
3988 * This is not fatal -- just means I cant map command strings
3999 RAW_fd
= open(RAW_file
, O_RDONLY
);
4002 perror("Can't open RAW file");
4005 if (read(RAW_fd
, &header
, sizeof(RAW_header
)) != sizeof(RAW_header
)) {
4006 perror("read failed");
4009 if (header
.version_no
!= RAW_VERSION1
) {
4010 header
.version_no
= RAW_VERSION0
;
4011 header
.TOD_secs
= time((long *)0);
4012 header
.TOD_usecs
= 0;
4014 lseek(RAW_fd
, (off_t
)0, SEEK_SET
);
4016 if (read(RAW_fd
, &header
.thread_count
, sizeof(int)) != sizeof(int)) {
4017 perror("read failed");
4021 sample_TOD_secs
= header
.TOD_secs
;
4022 sample_TOD_usecs
= header
.TOD_usecs
;
4024 total_threads
= header
.thread_count
;
4025 size
= total_threads
* sizeof(kd_threadmap
);
4028 if ((mapptr
= (kd_threadmap
*) malloc(size
))) {
4029 bzero (mapptr
, size
);
4031 if (read(RAW_fd
, mapptr
, size
) != size
) {
4037 if (header
.version_no
!= RAW_VERSION0
) {
4038 offset
= lseek(RAW_fd
, (off_t
)0, SEEK_CUR
);
4039 offset
= (offset
+ (4095)) & ~4095;
4041 lseek(RAW_fd
, offset
, SEEK_SET
);
4044 for (i
= 0; i
< total_threads
; i
++)
4045 create_map_entry(mapptr
[i
].thread
, mapptr
[i
].valid
, &mapptr
[i
].command
[0]);
4051 void delete_all_map_entries()
4053 threadmap_t tme
= 0;
4054 threadmap_t tme_next
= 0;
4057 for (i
= 0; i
< HASH_SIZE
; i
++) {
4059 for (tme
= threadmap_hash
[i
]; tme
; tme
= tme_next
) {
4061 free(tme
->tm_setptr
);
4062 tme_next
= tme
->tm_next
;
4063 tme
->tm_next
= threadmap_freelist
;
4064 threadmap_freelist
= tme
;
4066 threadmap_hash
[i
] = 0;
4071 void create_map_entry(uintptr_t thread
, int pid
, char *command
)
4076 if ((tme
= threadmap_freelist
))
4077 threadmap_freelist
= tme
->tm_next
;
4079 tme
= (threadmap_t
)malloc(sizeof(struct threadmap
));
4081 tme
->tm_thread
= thread
;
4082 tme
->tm_setsize
= 0;
4085 (void)strncpy (tme
->tm_command
, command
, MAXCOMLEN
);
4086 tme
->tm_command
[MAXCOMLEN
] = '\0';
4088 hashid
= thread
& HASH_MASK
;
4090 tme
->tm_next
= threadmap_hash
[hashid
];
4091 threadmap_hash
[hashid
] = tme
;
4093 if (pid
!= 0 && pid
!= 1) {
4094 if (!strncmp(command
, "LaunchCFMA", 10))
4095 (void)get_real_command_name(pid
, tme
->tm_command
, MAXCOMLEN
);
4101 find_map_entry(uintptr_t thread
)
4106 hashid
= thread
& HASH_MASK
;
4108 for (tme
= threadmap_hash
[hashid
]; tme
; tme
= tme
->tm_next
) {
4109 if (tme
->tm_thread
== thread
)
4117 delete_map_entry(uintptr_t thread
)
4119 threadmap_t tme
= 0;
4120 threadmap_t tme_prev
;
4123 hashid
= thread
& HASH_MASK
;
4125 if ((tme
= threadmap_hash
[hashid
])) {
4126 if (tme
->tm_thread
== thread
)
4127 threadmap_hash
[hashid
] = tme
->tm_next
;
4131 for (tme
= tme
->tm_next
; tme
; tme
= tme
->tm_next
) {
4132 if (tme
->tm_thread
== thread
) {
4133 tme_prev
->tm_next
= tme
->tm_next
;
4141 free(tme
->tm_setptr
);
4143 tme
->tm_next
= threadmap_freelist
;
4144 threadmap_freelist
= tme
;
4151 fs_usage_fd_set(uintptr_t thread
, unsigned int fd
)
4155 if ((tme
= find_map_entry(thread
)) == 0)
4158 * If the map is not allocated, then now is the time
4160 if (tme
->tm_setptr
== (unsigned long *)0) {
4161 if ((tme
->tm_setptr
= (unsigned long *)malloc(FS_USAGE_NFDBYTES(FS_USAGE_FD_SETSIZE
))) == 0)
4164 tme
->tm_setsize
= FS_USAGE_FD_SETSIZE
;
4165 bzero(tme
->tm_setptr
, (FS_USAGE_NFDBYTES(FS_USAGE_FD_SETSIZE
)));
4168 * If the map is not big enough, then reallocate it
4170 while (tme
->tm_setsize
<= fd
) {
4173 n
= tme
->tm_setsize
* 2;
4174 tme
->tm_setptr
= (unsigned long *)realloc(tme
->tm_setptr
, (FS_USAGE_NFDBYTES(n
)));
4176 bzero(&tme
->tm_setptr
[(tme
->tm_setsize
/FS_USAGE_NFDBITS
)], (FS_USAGE_NFDBYTES(tme
->tm_setsize
)));
4177 tme
->tm_setsize
= n
;
4182 tme
->tm_setptr
[fd
/FS_USAGE_NFDBITS
] |= (1 << ((fd
) % FS_USAGE_NFDBITS
));
4188 * 0 : File Descriptor bit is not set
4189 * 1 : File Descriptor bit is set
4192 fs_usage_fd_isset(uintptr_t thread
, unsigned int fd
)
4197 if ((tme
= find_map_entry(thread
))) {
4198 if (tme
->tm_setptr
&& fd
< tme
->tm_setsize
)
4199 ret
= tme
->tm_setptr
[fd
/FS_USAGE_NFDBITS
] & (1 << (fd
% FS_USAGE_NFDBITS
));
4206 fs_usage_fd_clear(uintptr_t thread
, unsigned int fd
)
4210 if ((tme
= find_map_entry(thread
))) {
4211 if (tme
->tm_setptr
&& fd
< tme
->tm_setsize
)
4212 tme
->tm_setptr
[fd
/FS_USAGE_NFDBITS
] &= ~(1 << (fd
% FS_USAGE_NFDBITS
));
4225 ret
= (int)strtol(str
, &cp
, 10);
4227 if (cp
== str
|| *cp
) {
4229 * Assume this is a command string and find matching pids
4234 for (i
= 0; i
< kp_nentries
&& num_of_pids
< (MAX_PIDS
- 1); i
++) {
4235 if (kp_buffer
[i
].kp_proc
.p_stat
== 0)
4238 if (!strncmp(str
, kp_buffer
[i
].kp_proc
.p_comm
,
4239 sizeof(kp_buffer
[i
].kp_proc
.p_comm
) -1))
4240 pids
[num_of_pids
++] = kp_buffer
[i
].kp_proc
.p_pid
;
4244 else if (num_of_pids
< (MAX_PIDS
- 1))
4245 pids
[num_of_pids
++] = ret
;
4251 lookup_name(uint64_t user_addr
, char **type
, char **name
)
4259 if (numFrameworks
) {
4261 if ((user_addr
>= framework32
.b_address
&& user_addr
< framework32
.e_address
) ||
4262 (user_addr
>= framework64
.b_address
&& user_addr
< framework64
.e_address
)) {
4265 last
= numFrameworks
;
4267 for (i
= numFrameworks
/ 2; start
< last
; i
= start
+ ((last
- start
) / 2)) {
4268 if (user_addr
> frameworkInfo
[i
].e_address
)
4273 if (start
< numFrameworks
&&
4274 user_addr
>= frameworkInfo
[start
].b_address
&& user_addr
< frameworkInfo
[start
].e_address
) {
4275 *type
= frameworkType
[frameworkInfo
[start
].r_type
];
4276 *name
= frameworkInfo
[start
].name
;
4284 * Comparison routines for sorting
4286 static int compareFrameworkAddress(const void *aa
, const void *bb
)
4288 LibraryInfo
*a
= (LibraryInfo
*)aa
;
4289 LibraryInfo
*b
= (LibraryInfo
*)bb
;
4291 if (a
->b_address
< b
->b_address
) return -1;
4292 if (a
->b_address
== b
->b_address
) return 0;
4297 int scanline(char *inputstring
, char **argv
, int maxtokens
)
4300 char **ap
= argv
, *p
, *val
;
4302 for (p
= inputstring
; n
< maxtokens
&& p
!= NULL
; ) {
4304 while ((val
= strsep(&p
, " \t")) != NULL
&& *val
== '\0');
4315 int ReadSharedCacheMap(const char *path
, LibraryRange
*lr
, char *linkedit_name
)
4317 uint64_t b_address
, e_address
;
4321 char frameworkName
[256];
4325 int linkedit_found
= 0;
4326 char *substring
, *ptr
;
4328 bzero(buf
, sizeof(buf
));
4329 bzero(tokens
, sizeof(tokens
));
4334 if ((fd
= fopen(path
, "r")) == 0)
4337 while (fgets(buf
, 1023, fd
)) {
4338 if (strncmp(buf
, "mapping", 7))
4341 buf
[strlen(buf
)-1] = 0;
4343 frameworkName
[0] = 0;
4347 * Extract lib name from path name
4349 if ((substring
= strrchr(buf
, '.')))
4352 * There is a ".": name is whatever is between the "/" around the "."
4354 while ( *substring
!= '/') /* find "/" before "." */
4358 strncpy(frameworkName
, substring
, 256); /* copy path from "/" */
4359 frameworkName
[255] = 0;
4360 substring
= frameworkName
;
4362 while ( *substring
!= '/' && *substring
) /* find "/" after "." and stop string there */
4369 * No ".": take segment after last "/"
4376 substring
= ptr
+ 1;
4379 strncpy(frameworkName
, substring
, 256);
4380 frameworkName
[255] = 0;
4382 fnp
= (char *)malloc(strlen(frameworkName
) + 1);
4383 strcpy(fnp
, frameworkName
);
4385 while (fgets(buf
, 1023, fd
) && numFrameworks
< (MAXINDEX
- 2)) {
4389 buf
[strlen(buf
)-1] = 0;
4391 ntokens
= scanline(buf
, tokens
, 64);
4396 if (strncmp(tokens
[0], "__TEXT", 6) == 0)
4398 else if (strncmp(tokens
[0], "__DATA", 6) == 0)
4400 else if (strncmp(tokens
[0], "__OBJC", 6) == 0)
4402 else if (strncmp(tokens
[0], "__IMPORT", 8) == 0)
4404 else if (strncmp(tokens
[0], "__UNICODE", 9) == 0)
4406 else if (strncmp(tokens
[0], "__IMAGE", 7) == 0)
4408 else if (strncmp(tokens
[0], "__LINKEDIT", 10) == 0)
4413 if (type
== LINKEDIT_R
&& linkedit_found
)
4417 b_address
= strtoull(tokens
[1], 0, 16);
4418 e_address
= strtoull(tokens
[3], 0, 16);
4420 frameworkInfo
[numFrameworks
].b_address
= b_address
;
4421 frameworkInfo
[numFrameworks
].e_address
= e_address
;
4422 frameworkInfo
[numFrameworks
].r_type
= type
;
4424 if (type
== LINKEDIT_R
) {
4425 frameworkInfo
[numFrameworks
].name
= linkedit_name
;
4428 frameworkInfo
[numFrameworks
].name
= fnp
;
4430 printf("%s(%d): %qx-%qx\n", frameworkInfo
[numFrameworks
].name
, type
, b_address
, e_address
);
4432 if (lr
->b_address
== 0 || b_address
< lr
->b_address
)
4433 lr
->b_address
= b_address
;
4435 if (lr
->e_address
== 0 || e_address
> lr
->e_address
)
4436 lr
->e_address
= e_address
;
4440 if (type
== LINKEDIT_R
)
4443 if (fgets(buf
, 1023, fd
) == 0)
4446 buf
[strlen(buf
)-1] = 0;
4451 printf("%s range, %qx-%qx\n", path
, lr
->b_address
, lr
->e_address
);
4458 SortFrameworkAddresses()
4461 frameworkInfo
[numFrameworks
].b_address
= frameworkInfo
[numFrameworks
- 1].b_address
+ 0x800000;
4462 frameworkInfo
[numFrameworks
].e_address
= frameworkInfo
[numFrameworks
].b_address
;
4463 frameworkInfo
[numFrameworks
].name
= (char *)0;
4465 qsort(frameworkInfo
, numFrameworks
, sizeof(LibraryInfo
), compareFrameworkAddress
);
4469 struct diskio
*insert_diskio(int type
, int bp
, int dev
, int blkno
, int io_size
, uintptr_t thread
, double curtime
)
4474 if ((dio
= free_diskios
))
4475 free_diskios
= dio
->next
;
4477 if ((dio
= (struct diskio
*)malloc(sizeof(struct diskio
))) == NULL
)
4486 dio
->iosize
= io_size
;
4487 dio
->issued_time
= curtime
;
4488 dio
->issuing_thread
= thread
;
4490 if ((tme
= find_map_entry(thread
))) {
4491 strncpy(dio
->issuing_command
, tme
->tm_command
, MAXCOMLEN
);
4492 dio
->issuing_command
[MAXCOMLEN
-1] = '\0';
4494 strcpy(dio
->issuing_command
, "");
4496 dio
->next
= busy_diskios
;
4498 dio
->next
->prev
= dio
;
4505 struct diskio
*complete_diskio(int bp
, int io_errno
, int resid
, uintptr_t thread
, double curtime
)
4509 for (dio
= busy_diskios
; dio
; dio
= dio
->next
) {
4511 if (dio
->bp
== bp
) {
4512 if (dio
== busy_diskios
) {
4513 if ((busy_diskios
= dio
->next
))
4514 dio
->next
->prev
= NULL
;
4517 dio
->next
->prev
= dio
->prev
;
4518 dio
->prev
->next
= dio
->next
;
4520 dio
->iosize
-= resid
;
4521 dio
->io_errno
= io_errno
;
4522 dio
->completed_time
= curtime
;
4523 dio
->completion_thread
= thread
;
4528 return ((struct diskio
*)0);
4532 void free_diskio(struct diskio
*dio
)
4534 dio
->next
= free_diskios
;
4539 void print_diskio(struct diskio
*dio
)
4544 int format
= FMT_DISKIO
;
4550 if (type
== P_CS_ReadChunk
|| type
== P_CS_WriteChunk
|| type
== P_CS_Originated_Read
||
4551 type
== P_CS_Originated_Write
|| type
== P_CS_MetaRead
|| type
== P_CS_MetaWrite
) {
4555 case P_CS_ReadChunk
:
4558 format
= FMT_DISKIO_CS
;
4560 case P_CS_WriteChunk
:
4563 format
= FMT_DISKIO_CS
;
4568 format
= FMT_DISKIO_CS
;
4570 case P_CS_MetaWrite
:
4573 format
= FMT_DISKIO_CS
;
4575 case P_CS_Originated_Read
:
4579 case P_CS_Originated_Write
:
4584 strncpy(buf
, p
, len
);
4587 switch (type
& P_DISKIO_TYPE
) {
4618 strncpy(buf
, p
, len
);
4620 if (type
& (P_DISKIO_ASYNC
| P_DISKIO_THROTTLE
| P_DISKIO_PASSIVE
)) {
4623 if (type
& P_DISKIO_ASYNC
) {
4624 memcpy(&buf
[len
], "async", 5);
4627 if (type
& P_DISKIO_THROTTLE
)
4629 else if (type
& P_DISKIO_PASSIVE
)
4637 if (check_filter_mode(NULL
, type
, 0, 0, buf
))
4638 format_print(NULL
, buf
, dio
->issuing_thread
, type
, 0, 0, 0, 0, format
, dio
->completed_time
, dio
->issued_time
, 1, "", dio
);
4642 void cache_disk_names()
4647 struct diskrec
*dnp
;
4650 if ((dirp
= opendir("/dev")) == NULL
)
4653 while ((dir
= readdir(dirp
)) != NULL
) {
4654 char nbuf
[MAXPATHLEN
];
4656 if (dir
->d_namlen
< 5 || strncmp("disk", dir
->d_name
, 4))
4659 snprintf(nbuf
, MAXPATHLEN
, "%s/%s", "/dev", dir
->d_name
);
4661 if (stat(nbuf
, &st
) < 0)
4664 if ((dnp
= (struct diskrec
*)malloc(sizeof(struct diskrec
))) == NULL
)
4667 if ((dnp
->diskname
= (char *)malloc(dir
->d_namlen
+ 1)) == NULL
) {
4671 strncpy(dnp
->diskname
, dir
->d_name
, dir
->d_namlen
);
4672 dnp
->diskname
[dir
->d_namlen
] = 0;
4673 dnp
->dev
= st
.st_rdev
;
4675 dnp
->next
= disk_list
;
4678 (void) closedir(dirp
);
4682 void recache_disk_names()
4684 struct diskrec
*dnp
, *next_dnp
;
4686 for (dnp
= disk_list
; dnp
; dnp
= next_dnp
) {
4687 next_dnp
= dnp
->next
;
4689 free(dnp
->diskname
);
4698 char *find_disk_name(int dev
)
4700 struct diskrec
*dnp
;
4709 for (i
= 0; i
< 2; i
++) {
4710 for (dnp
= disk_list
; dnp
; dnp
= dnp
->next
) {
4711 if (dnp
->dev
== dev
)
4712 return (dnp
->diskname
);
4714 recache_disk_names();
4716 return ("NOTFOUND");
4720 char *generate_cs_disk_name(int dev
, char *s
)
4725 sprintf(s
, "disk%ds%d", (dev
>> 16) & 0xffff, dev
& 0xffff);
4733 * ret = 1 means print the entry
4734 * ret = 0 means don't print the entry
4737 check_filter_mode(struct th_info
* ti
, int type
, int error
, int retval
, char *sc_name
)
4740 int network_fd_isset
= 0;
4743 if (filter_mode
== DEFAULT_DO_NOT_FILTER
)
4746 if (sc_name
[0] == 'C' && !strcmp (sc_name
, "CACHE_HIT")) {
4747 if (filter_mode
& CACHEHIT_FILTER
)
4748 /* Do not print if cachehit filter is set */
4753 if (filter_mode
& EXEC_FILTER
) {
4754 if (type
== BSC_execve
|| type
== BSC_posix_spawn
)
4759 if (filter_mode
& PATHNAME_FILTER
) {
4760 if (ti
&& ti
->pathname
[0])
4762 if (type
== BSC_close
|| type
== BSC_close_nocancel
)
4767 if ( !(filter_mode
& (FILESYS_FILTER
| NETWORK_FILTER
)))
4770 if (ti
== (struct th_info
*)0) {
4771 if (filter_mode
& FILESYS_FILTER
)
4779 case BSC_close_nocancel
:
4781 network_fd_isset
= fs_usage_fd_isset(ti
->thread
, fd
);
4784 fs_usage_fd_clear(ti
->thread
,fd
);
4786 if (network_fd_isset
) {
4787 if (filter_mode
& NETWORK_FILTER
)
4789 } else if (filter_mode
& FILESYS_FILTER
)
4795 case BSC_read_nocancel
:
4796 case BSC_write_nocancel
:
4798 * we don't care about error in these cases
4801 network_fd_isset
= fs_usage_fd_isset(ti
->thread
, fd
);
4803 if (network_fd_isset
) {
4804 if (filter_mode
& NETWORK_FILTER
)
4806 } else if (filter_mode
& FILESYS_FILTER
)
4811 case BSC_accept_nocancel
:
4816 fs_usage_fd_set(ti
->thread
, fd
);
4817 if (filter_mode
& NETWORK_FILTER
)
4828 case BSC_sendto_nocancel
:
4829 case BSC_recvfrom_nocancel
:
4830 case BSC_recvmsg_nocancel
:
4831 case BSC_sendmsg_nocancel
:
4832 case BSC_connect_nocancel
:
4836 fs_usage_fd_set(ti
->thread
, fd
);
4837 if (filter_mode
& NETWORK_FILTER
)
4842 case BSC_select_nocancel
:
4843 case BSC_socketpair
:
4845 * Cannot determine info about file descriptors
4847 if (filter_mode
& NETWORK_FILTER
)
4854 * We track these cases for fd state only
4857 network_fd_isset
= fs_usage_fd_isset(ti
->thread
, fd
);
4859 if (error
== 0 && network_fd_isset
) {
4861 * then we are duping a socket descriptor
4863 fd
= retval
; /* the new fd */
4864 fs_usage_fd_set(ti
->thread
, fd
);
4869 if (filter_mode
& FILESYS_FILTER
)
4878 * Allocate a buffer that is large enough to hold the maximum arguments
4879 * to execve(). This is used when getting the arguments to programs
4880 * when we see LaunchCFMApps. If this fails, it is not fatal, we will
4881 * simply not resolve the command name.
4885 init_arguments_buffer()
4891 mib
[1] = KERN_ARGMAX
;
4892 size
= sizeof(argmax
);
4894 if (sysctl(mib
, 2, &argmax
, &size
, NULL
, 0) == -1)
4897 /* Hack to avoid kernel bug. */
4898 if (argmax
> 8192) {
4902 arguments
= (char *)malloc(argmax
);
4907 get_real_command_name(int pid
, char *cbuf
, int csize
)
4910 * Get command and arguments.
4914 char *command_beg
, *command
, *command_end
;
4920 bzero(arguments
, argmax
);
4925 * A sysctl() is made to find out the full path that the command
4929 mib
[1] = KERN_PROCARGS2
;
4933 if (sysctl(mib
, 3, arguments
, (size_t *)&argmax
, NULL
, 0) < 0)
4937 * Skip the saved exec_path
4939 for (cp
= arguments
; cp
< &arguments
[argmax
]; cp
++) {
4942 * End of exec_path reached
4947 if (cp
== &arguments
[argmax
])
4951 * Skip trailing '\0' characters
4953 for (; cp
< &arguments
[argmax
]; cp
++) {
4956 * Beginning of first argument reached
4961 if (cp
== &arguments
[argmax
])
4966 * Make sure that the command is '\0'-terminated. This protects
4967 * against malicious programs; under normal operation this never
4968 * ends up being a problem..
4970 for (; cp
< &arguments
[argmax
]; cp
++) {
4973 * End of first argument reached
4978 if (cp
== &arguments
[argmax
])
4981 command_end
= command
= cp
;
4984 * Get the basename of command
4986 for (command
--; command
>= command_beg
; command
--) {
4987 if (*command
== '/') {
4992 (void) strncpy(cbuf
, (char *)command
, csize
);
4993 cbuf
[csize
-1] = '\0';