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 -lutil -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>
54 #ifndef KERNEL_PRIVATE
55 #define KERNEL_PRIVATE
56 #include <sys/kdebug.h>
59 #include <sys/kdebug.h>
60 #endif /*KERNEL_PRIVATE*/
62 #import <mach/clock_types.h>
63 #import <mach/mach_time.h>
67 #define F_OPENFROM 56 /* SPI: open a file relative to fd (must be a dir) */
68 #define F_UNLINKFROM 57 /* SPI: open a file relative to fd (must be a dir) */
69 #define F_CHECK_OPENEVT 58 /* SPI: if a process is marked OPENEVT, or in O_EVTONLY on opens of this vnode */
80 #define RAW_VERSION0 0x55aa0000
81 #define RAW_VERSION1 0x55aa0101
87 typedef struct LibraryRange
{
92 LibraryRange framework32
;
93 LibraryRange framework64
;
105 char *frameworkType
[] = {
116 typedef struct LibraryInfo
{
123 LibraryInfo frameworkInfo
[MAXINDEX
];
124 int numFrameworks
= 0;
128 * MAXCOLS controls when extra data kicks in.
129 * MAX_WIDE_MODE_COLS controls -w mode to get even wider data in path.
130 * If NUMPARMS changes to match the kernel, it will automatically
131 * get reflected in the -w mode output.
134 #define PATHLENGTH (NUMPARMS*sizeof(uintptr_t))
137 #define MAX_WIDE_MODE_COLS (PATHLENGTH + 80)
138 #define MAXWIDTH MAX_WIDE_MODE_COLS + 64
140 #define MAX_PATHNAMES 3
141 #define MAX_SCALL_PATHNAMES 2
143 typedef struct th_info
*th_info_t
;
146 uintptr_t pathname
[NUMPARMS
+ 1]; /* add room for null terminator */
152 uintptr_t child_thread
;
173 struct lookup lookups
[MAX_PATHNAMES
];
177 typedef struct threadmap
* threadmap_t
;
183 unsigned int tm_setsize
; /* this is a bit count */
184 unsigned long *tm_setptr
; /* file descripter bitmap */
185 char tm_command
[MAXCOMLEN
+ 1];
189 typedef struct vnode_info
* vnode_info_t
;
192 vnode_info_t vn_next
;
194 uintptr_t vn_pathname
[NUMPARMS
+ 1];
197 typedef struct meta_info
* meta_info_t
;
205 #define HASH_SIZE 1024
206 #define HASH_MASK (HASH_SIZE - 1)
208 th_info_t th_info_hash
[HASH_SIZE
];
209 th_info_t th_info_freelist
;
211 threadmap_t threadmap_hash
[HASH_SIZE
];
212 threadmap_t threadmap_freelist
;
215 #define VN_HASH_SHIFT 3
216 #define VN_HASH_SIZE 16384
217 #define VN_HASH_MASK (VN_HASH_SIZE - 1)
219 vnode_info_t vn_info_hash
[VN_HASH_SIZE
];
220 meta_info_t m_info_hash
[VN_HASH_SIZE
];
223 int filemgr_in_progress
= 0;
224 int need_new_map
= 1;
230 int one_good_pid
= 0; /* Used to fail gracefully when bad pids given */
231 int select_pid_mode
= 0; /* Flag set indicates that output is restricted
232 to selected pids or commands */
239 #define USLEEP_BEHIND 2
240 #define USLEEP_MAX 32
241 int usleep_ms
= USLEEP_MIN
;
244 * Network only or filesystem only output filter
245 * Default of zero means report all activity - no filtering
247 #define FILESYS_FILTER 0x01
248 #define NETWORK_FILTER 0x02
249 #define EXEC_FILTER 0x08
250 #define PATHNAME_FILTER 0x10
251 #define DISKIO_FILTER 0x20
252 #define DEFAULT_DO_NOT_FILTER 0x00
254 int filter_mode
= DEFAULT_DO_NOT_FILTER
;
256 boolean_t show_cachehits
= FALSE
;
262 struct diskrec
*next
;
278 uintptr_t issuing_thread
;
279 uintptr_t completion_thread
;
280 char issuing_command
[MAXCOMLEN
+ 1];
282 double completed_time
;
286 struct diskrec
*disk_list
= NULL
;
287 struct diskio
*free_diskios
= NULL
;
288 struct diskio
*busy_diskios
= NULL
;
291 struct diskio
*insert_diskio();
292 struct diskio
*find_diskio(int);
293 struct diskio
*complete_diskio();
297 int check_filter_mode(struct th_info
*, int, int, int, char *);
298 void format_print(struct th_info
*, char *, uintptr_t, int, uintptr_t, uintptr_t, uintptr_t, uintptr_t, int, double, double, int, char *, struct diskio
*);
299 void enter_event_now(uintptr_t, int, kd_buf
*, char *, double);
300 void enter_event(uintptr_t, int, kd_buf
*, char *, double);
301 void exit_event(char *, uintptr_t, int, uintptr_t, uintptr_t, uintptr_t, uintptr_t, int, double);
302 void extend_syscall(uintptr_t, int, kd_buf
*);
304 char *generate_cs_disk_name(int, char *s
);
305 char *find_disk_name(int);
306 void cache_disk_names();
307 void recache_disk_names();
309 void lookup_name(uint64_t user_addr
, char **type
, char **name
);
310 int ReadSharedCacheMap(const char *, LibraryRange
*, char *);
311 void SortFrameworkAddresses();
313 void fs_usage_fd_set(uintptr_t, unsigned int);
314 int fs_usage_fd_isset(uintptr_t, unsigned int);
315 void fs_usage_fd_clear(uintptr_t, unsigned int);
317 void init_arguments_buffer();
318 int get_real_command_name(int, char *, int);
320 void delete_all_events();
321 void delete_event(th_info_t
);
322 th_info_t
add_event(uintptr_t, int);
323 th_info_t
find_event(uintptr_t, int);
324 void mark_thread_waited(uintptr_t);
326 void read_command_map();
327 void delete_all_map_entries();
328 void create_map_entry(uintptr_t, int, char *);
329 void delete_map_entry(uintptr_t);
330 threadmap_t
find_map_entry(uintptr_t);
332 char *add_vnode_name(uint64_t, char *);
333 char *find_vnode_name(uint64_t);
334 char *find_meta_name(uint64_t);
335 void add_meta_name(uint64_t, char *);
341 void set_pidexclude();
345 #define CLASS_MASK 0xff000000
346 #define CSC_MASK 0xffff0000
347 #define BSC_INDEX(type) ((type >> 2) & 0x3fff)
350 #define TRACE_DATA_NEWTHREAD 0x07000004
351 #define TRACE_DATA_EXEC 0x07000008
352 #define TRACE_STRING_NEWTHREAD 0x07010004
353 #define TRACE_STRING_EXEC 0x07010008
355 #define MACH_vmfault 0x01300008
356 #define MACH_pageout 0x01300004
357 #define MACH_sched 0x01400000
358 #define MACH_stkhandoff 0x01400008
359 #define MACH_idle 0x01400024
360 #define VFS_LOOKUP 0x03010090
361 #define VFS_ALIAS_VP 0x03010094
363 #define BSC_thread_terminate 0x040c05a4
365 #define HFS_update 0x3018000
366 #define HFS_modify_block_end 0x3018004
368 #define Throttled 0x3010184
369 #define SPEC_ioctl 0x3060000
370 #define SPEC_unmap_info 0x3060004
371 #define proc_exit 0x4010004
373 #define BC_IO_HIT 0x03070010
374 #define BC_IO_HIT_STALLED 0x03070020
375 #define BC_IO_MISS 0x03070040
376 #define BC_IO_MISS_CUT_THROUGH 0x03070080
377 #define BC_PLAYBACK_IO 0x03070100
378 #define BC_STR(s) ( \
379 (s == BC_IO_HIT) ? "HIT" : \
380 (s == BC_IO_HIT_STALLED) ? "STALL" : \
381 (s == BC_IO_MISS) ? "MISS" : \
382 (s == BC_IO_MISS_CUT_THROUGH) ? "CUT" : \
383 (s == BC_PLAYBACK_IO) ? "PLBK" : \
384 (s == 0x0) ? "NONE" : "UNKN" )
387 #define DKIO_NOCACHE 0x80
390 #define P_DISKIO_READ (DKIO_READ << 2)
391 #define P_DISKIO_ASYNC (DKIO_ASYNC << 2)
392 #define P_DISKIO_META (DKIO_META << 2)
393 #define P_DISKIO_PAGING (DKIO_PAGING << 2)
394 #define P_DISKIO_THROTTLE (DKIO_THROTTLE << 2)
395 #define P_DISKIO_PASSIVE (DKIO_PASSIVE << 2)
396 #define P_DISKIO_NOCACHE (DKIO_NOCACHE << 2)
397 #define P_DISKIO_TIER_MASK (DKIO_TIER_MASK << 2)
398 #define P_DISKIO_TIER_SHIFT (DKIO_TIER_SHIFT + 2)
400 #define P_DISKIO (FSDBG_CODE(DBG_DKRW, 0))
401 #define P_DISKIO_DONE (P_DISKIO | (DKIO_DONE << 2))
402 #define P_DISKIO_TYPE (P_DISKIO | P_DISKIO_READ | P_DISKIO_META | P_DISKIO_PAGING)
403 #define P_DISKIO_MASK (CSC_MASK | 0x4)
405 #define P_WrData (P_DISKIO)
406 #define P_RdData (P_DISKIO | P_DISKIO_READ)
407 #define P_WrMeta (P_DISKIO | P_DISKIO_META)
408 #define P_RdMeta (P_DISKIO | P_DISKIO_META | P_DISKIO_READ)
409 #define P_PgOut (P_DISKIO | P_DISKIO_PAGING)
410 #define P_PgIn (P_DISKIO | P_DISKIO_PAGING | P_DISKIO_READ)
412 #define P_CS_Class 0x0a000000 // DBG_CORESTORAGE
413 #define P_CS_Type_Mask 0xfffffff0
414 #define P_CS_IO_Done 0x00000004
416 #define P_CS_ReadChunk 0x0a000200 // chopped up request
417 #define P_CS_WriteChunk 0x0a000210
418 #define P_CS_MetaRead 0x0a000300 // meta data
419 #define P_CS_MetaWrite 0x0a000310
420 #define P_CS_TransformRead 0x0a000500 // background transform
421 #define P_CS_TransformWrite 0x0a000510
422 #define P_CS_MigrationRead 0x0a000600 // composite disk block migration
423 #define P_CS_MigrationWrite 0x0a000610
424 #define P_CS_SYNC_DISK 0x0a010000
426 #define MSC_map_fd 0x010c00ac
428 #define BSC_BASE 0x040C0000
429 #define MSC_BASE 0x010C0000
431 // Network related codes
432 #define BSC_recvmsg 0x040C006C
433 #define BSC_sendmsg 0x040C0070
434 #define BSC_recvfrom 0x040C0074
435 #define BSC_accept 0x040C0078
436 #define BSC_select 0x040C0174
437 #define BSC_socket 0x040C0184
438 #define BSC_connect 0x040C0188
439 #define BSC_bind 0x040C01A0
440 #define BSC_listen 0x040C01A8
441 #define BSC_sendto 0x040C0214
442 #define BSC_socketpair 0x040C021C
443 #define BSC_recvmsg_nocancel 0x040c0644
444 #define BSC_sendmsg_nocancel 0x040c0648
445 #define BSC_recvfrom_nocancel 0x040c064c
446 #define BSC_accept_nocancel 0x040c0650
447 #define BSC_connect_nocancel 0x040c0664
448 #define BSC_sendto_nocancel 0x040c0674
450 #define BSC_exit 0x040C0004
451 #define BSC_read 0x040C000C
452 #define BSC_write 0x040C0010
453 #define BSC_open 0x040C0014
454 #define BSC_close 0x040C0018
455 #define BSC_link 0x040C0024
456 #define BSC_unlink 0x040C0028
457 #define BSC_chdir 0x040c0030
458 #define BSC_fchdir 0x040c0034
459 #define BSC_mknod 0x040C0038
460 #define BSC_chmod 0x040C003C
461 #define BSC_chown 0x040C0040
462 #define BSC_getfsstat 0x040C0048
463 #define BSC_access 0x040C0084
464 #define BSC_chflags 0x040C0088
465 #define BSC_fchflags 0x040C008C
466 #define BSC_sync 0x040C0090
467 #define BSC_dup 0x040C00A4
468 #define BSC_ioctl 0x040C00D8
469 #define BSC_revoke 0x040C00E0
470 #define BSC_symlink 0x040C00E4
471 #define BSC_readlink 0x040C00E8
472 #define BSC_execve 0x040C00EC
473 #define BSC_umask 0x040C00F0
474 #define BSC_chroot 0x040C00F4
475 #define BSC_msync 0x040C0104
476 #define BSC_dup2 0x040C0168
477 #define BSC_fcntl 0x040C0170
478 #define BSC_fsync 0x040C017C
479 #define BSC_readv 0x040C01E0
480 #define BSC_writev 0x040C01E4
481 #define BSC_fchown 0x040C01EC
482 #define BSC_fchmod 0x040C01F0
483 #define BSC_rename 0x040C0200
484 #define BSC_flock 0x040C020C
485 #define BSC_mkfifo 0x040C0210
486 #define BSC_mkdir 0x040C0220
487 #define BSC_rmdir 0x040C0224
488 #define BSC_utimes 0x040C0228
489 #define BSC_futimes 0x040C022C
490 #define BSC_pread 0x040C0264
491 #define BSC_pwrite 0x040C0268
492 #define BSC_statfs 0x040C0274
493 #define BSC_fstatfs 0x040C0278
494 #define BSC_unmount 0x040C027C
495 #define BSC_mount 0x040C029C
496 #define BSC_fdatasync 0x040C02EC
497 #define BSC_stat 0x040C02F0
498 #define BSC_fstat 0x040C02F4
499 #define BSC_lstat 0x040C02F8
500 #define BSC_pathconf 0x040C02FC
501 #define BSC_fpathconf 0x040C0300
502 #define BSC_getdirentries 0x040C0310
503 #define BSC_mmap 0x040c0314
504 #define BSC_lseek 0x040c031c
505 #define BSC_truncate 0x040C0320
506 #define BSC_ftruncate 0x040C0324
507 #define BSC_undelete 0x040C0334
508 #define BSC_open_dprotected_np 0x040C0360
509 #define BSC_getattrlist 0x040C0370
510 #define BSC_setattrlist 0x040C0374
511 #define BSC_getdirentriesattr 0x040C0378
512 #define BSC_exchangedata 0x040C037C
513 #define BSC_checkuseraccess 0x040C0380
514 #define BSC_searchfs 0x040C0384
515 #define BSC_delete 0x040C0388
516 #define BSC_copyfile 0x040C038C
517 #define BSC_fgetattrlist 0x040C0390
518 #define BSC_fsetattrlist 0x040C0394
519 #define BSC_getxattr 0x040C03A8
520 #define BSC_fgetxattr 0x040C03AC
521 #define BSC_setxattr 0x040C03B0
522 #define BSC_fsetxattr 0x040C03B4
523 #define BSC_removexattr 0x040C03B8
524 #define BSC_fremovexattr 0x040C03BC
525 #define BSC_listxattr 0x040C03C0
526 #define BSC_flistxattr 0x040C03C4
527 #define BSC_fsctl 0x040C03C8
528 #define BSC_posix_spawn 0x040C03D0
529 #define BSC_ffsctl 0x040C03D4
530 #define BSC_open_extended 0x040C0454
531 #define BSC_umask_extended 0x040C0458
532 #define BSC_stat_extended 0x040C045C
533 #define BSC_lstat_extended 0x040C0460
534 #define BSC_fstat_extended 0x040C0464
535 #define BSC_chmod_extended 0x040C0468
536 #define BSC_fchmod_extended 0x040C046C
537 #define BSC_access_extended 0x040C0470
538 #define BSC_mkfifo_extended 0x040C048C
539 #define BSC_mkdir_extended 0x040C0490
540 #define BSC_aio_fsync 0x040C04E4
541 #define BSC_aio_return 0x040C04E8
542 #define BSC_aio_suspend 0x040C04EC
543 #define BSC_aio_cancel 0x040C04F0
544 #define BSC_aio_error 0x040C04F4
545 #define BSC_aio_read 0x040C04F8
546 #define BSC_aio_write 0x040C04FC
547 #define BSC_lio_listio 0x040C0500
548 #define BSC_sendfile 0x040C0544
549 #define BSC_stat64 0x040C0548
550 #define BSC_fstat64 0x040C054C
551 #define BSC_lstat64 0x040C0550
552 #define BSC_stat64_extended 0x040C0554
553 #define BSC_lstat64_extended 0x040C0558
554 #define BSC_fstat64_extended 0x040C055C
555 #define BSC_getdirentries64 0x040C0560
556 #define BSC_statfs64 0x040C0564
557 #define BSC_fstatfs64 0x040C0568
558 #define BSC_getfsstat64 0x040C056C
559 #define BSC_pthread_chdir 0x040C0570
560 #define BSC_pthread_fchdir 0x040C0574
561 #define BSC_lchown 0x040C05B0
563 #define BSC_read_nocancel 0x040c0630
564 #define BSC_write_nocancel 0x040c0634
565 #define BSC_open_nocancel 0x040c0638
566 #define BSC_close_nocancel 0x040c063c
567 #define BSC_msync_nocancel 0x040c0654
568 #define BSC_fcntl_nocancel 0x040c0658
569 #define BSC_select_nocancel 0x040c065c
570 #define BSC_fsync_nocancel 0x040c0660
571 #define BSC_readv_nocancel 0x040c066c
572 #define BSC_writev_nocancel 0x040c0670
573 #define BSC_pread_nocancel 0x040c0678
574 #define BSC_pwrite_nocancel 0x040c067c
575 #define BSC_aio_suspend_nocancel 0x40c0694
576 #define BSC_guarded_open_np 0x040c06e4
577 #define BSC_guarded_close_np 0x040c06e8
579 #define BSC_fsgetpath 0x040c06ac
581 #define BSC_getattrlistbulk 0x040c0734
583 #define BSC_openat 0x040c073c
584 #define BSC_openat_nocancel 0x040c0740
585 #define BSC_renameat 0x040c0744
586 #define BSC_chmodat 0x040c074c
587 #define BSC_chownat 0x040c0750
588 #define BSC_fstatat 0x040c0754
589 #define BSC_fstatat64 0x040c0758
590 #define BSC_linkat 0x040c075c
591 #define BSC_unlinkat 0x040c0760
592 #define BSC_readlinkat 0x040c0764
593 #define BSC_symlinkat 0x040c0768
594 #define BSC_mkdirat 0x040c076c
595 #define BSC_getattrlistat 0x040c0770
597 #define BSC_msync_extended 0x040e0104
598 #define BSC_pread_extended 0x040e0264
599 #define BSC_pwrite_extended 0x040e0268
600 #define BSC_mmap_extended 0x040e0314
601 #define BSC_mmap_extended2 0x040f0314
603 // Carbon File Manager support
604 #define FILEMGR_PBGETCATALOGINFO 0x1e000020
605 #define FILEMGR_PBGETCATALOGINFOBULK 0x1e000024
606 #define FILEMGR_PBCREATEFILEUNICODE 0x1e000028
607 #define FILEMGR_PBCREATEDIRECTORYUNICODE 0x1e00002c
608 #define FILEMGR_PBCREATEFORK 0x1e000030
609 #define FILEMGR_PBDELETEFORK 0x1e000034
610 #define FILEMGR_PBITERATEFORK 0x1e000038
611 #define FILEMGR_PBOPENFORK 0x1e00003c
612 #define FILEMGR_PBREADFORK 0x1e000040
613 #define FILEMGR_PBWRITEFORK 0x1e000044
614 #define FILEMGR_PBALLOCATEFORK 0x1e000048
615 #define FILEMGR_PBDELETEOBJECT 0x1e00004c
616 #define FILEMGR_PBEXCHANGEOBJECT 0x1e000050
617 #define FILEMGR_PBGETFORKCBINFO 0x1e000054
618 #define FILEMGR_PBGETVOLUMEINFO 0x1e000058
619 #define FILEMGR_PBMAKEFSREF 0x1e00005c
620 #define FILEMGR_PBMAKEFSREFUNICODE 0x1e000060
621 #define FILEMGR_PBMOVEOBJECT 0x1e000064
622 #define FILEMGR_PBOPENITERATOR 0x1e000068
623 #define FILEMGR_PBRENAMEUNICODE 0x1e00006c
624 #define FILEMGR_PBSETCATALOGINFO 0x1e000070
625 #define FILEMGR_PBSETVOLUMEINFO 0x1e000074
626 #define FILEMGR_FSREFMAKEPATH 0x1e000078
627 #define FILEMGR_FSPATHMAKEREF 0x1e00007c
629 #define FILEMGR_PBGETCATINFO 0x1e010000
630 #define FILEMGR_PBGETCATINFOLITE 0x1e010004
631 #define FILEMGR_PBHGETFINFO 0x1e010008
632 #define FILEMGR_PBXGETVOLINFO 0x1e01000c
633 #define FILEMGR_PBHCREATE 0x1e010010
634 #define FILEMGR_PBHOPENDF 0x1e010014
635 #define FILEMGR_PBHOPENRF 0x1e010018
636 #define FILEMGR_PBHGETDIRACCESS 0x1e01001c
637 #define FILEMGR_PBHSETDIRACCESS 0x1e010020
638 #define FILEMGR_PBHMAPID 0x1e010024
639 #define FILEMGR_PBHMAPNAME 0x1e010028
640 #define FILEMGR_PBCLOSE 0x1e01002c
641 #define FILEMGR_PBFLUSHFILE 0x1e010030
642 #define FILEMGR_PBGETEOF 0x1e010034
643 #define FILEMGR_PBSETEOF 0x1e010038
644 #define FILEMGR_PBGETFPOS 0x1e01003c
645 #define FILEMGR_PBREAD 0x1e010040
646 #define FILEMGR_PBWRITE 0x1e010044
647 #define FILEMGR_PBGETFCBINFO 0x1e010048
648 #define FILEMGR_PBSETFINFO 0x1e01004c
649 #define FILEMGR_PBALLOCATE 0x1e010050
650 #define FILEMGR_PBALLOCCONTIG 0x1e010054
651 #define FILEMGR_PBSETFPOS 0x1e010058
652 #define FILEMGR_PBSETCATINFO 0x1e01005c
653 #define FILEMGR_PBGETVOLPARMS 0x1e010060
654 #define FILEMGR_PBSETVINFO 0x1e010064
655 #define FILEMGR_PBMAKEFSSPEC 0x1e010068
656 #define FILEMGR_PBHGETVINFO 0x1e01006c
657 #define FILEMGR_PBCREATEFILEIDREF 0x1e010070
658 #define FILEMGR_PBDELETEFILEIDREF 0x1e010074
659 #define FILEMGR_PBRESOLVEFILEIDREF 0x1e010078
660 #define FILEMGR_PBFLUSHVOL 0x1e01007c
661 #define FILEMGR_PBHRENAME 0x1e010080
662 #define FILEMGR_PBCATMOVE 0x1e010084
663 #define FILEMGR_PBEXCHANGEFILES 0x1e010088
664 #define FILEMGR_PBHDELETE 0x1e01008c
665 #define FILEMGR_PBDIRCREATE 0x1e010090
666 #define FILEMGR_PBCATSEARCH 0x1e010094
667 #define FILEMGR_PBHSETFLOCK 0x1e010098
668 #define FILEMGR_PBHRSTFLOCK 0x1e01009c
669 #define FILEMGR_PBLOCKRANGE 0x1e0100a0
670 #define FILEMGR_PBUNLOCKRANGE 0x1e0100a4
673 #define FILEMGR_CLASS 0x1e
674 #define FILEMGR_BASE 0x1e000000
676 #define FMT_DEFAULT 0
683 #define FMT_CACHEHIT 7
687 #define FMT_FTRUNC 11
689 #define FMT_SELECT 13
691 #define FMT_AIO_FSYNC 15
692 #define FMT_AIO_RETURN 16
693 #define FMT_AIO_SUSPEND 17
694 #define FMT_AIO_CANCEL 18
696 #define FMT_LIO_LISTIO 20
699 #define FMT_ACCESS 23
701 #define FMT_FCHMOD 25
702 #define FMT_CHMOD_EXT 26
703 #define FMT_FCHMOD_EXT 27
704 #define FMT_CHFLAGS 28
705 #define FMT_FCHFLAGS 29
709 #define FMT_SENDFILE 33
710 #define FMT_IOCTL_SYNC 34
712 #define FMT_UNMOUNT 36
713 #define FMT_DISKIO_CS 37
714 #define FMT_SYNC_DISK_CS 38
715 #define FMT_IOCTL_UNMAP 39
716 #define FMT_UNMAP_INFO 40
717 #define FMT_HFS_update 41
720 #define FMT_CHMODAT 44
721 #define FMT_OPENAT 45
722 #define FMT_RENAMEAT 46
724 #define MAX_BSD_SYSCALL 526
729 } bsd_syscalls
[MAX_BSD_SYSCALL
];
732 int bsd_syscall_types
[] = {
734 BSC_recvmsg_nocancel
,
736 BSC_sendmsg_nocancel
,
738 BSC_recvfrom_nocancel
,
745 BSC_connect_nocancel
,
815 BSC_open_dprotected_np
,
820 BSC_getdirentriesattr
,
849 BSC_aio_suspend_nocancel
,
866 BSC_lstat64_extended
,
867 BSC_fstat64_extended
,
876 BSC_guarded_close_np
,
896 #define MAX_FILEMGR 512
898 struct filemgr_call
{
900 } filemgr_calls
[MAX_FILEMGR
];
903 int filemgr_call_types
[] = {
904 FILEMGR_PBGETCATALOGINFO
,
905 FILEMGR_PBGETCATALOGINFOBULK
,
906 FILEMGR_PBCREATEFILEUNICODE
,
907 FILEMGR_PBCREATEDIRECTORYUNICODE
,
908 FILEMGR_PBCREATEFORK
,
909 FILEMGR_PBDELETEFORK
,
910 FILEMGR_PBITERATEFORK
,
914 FILEMGR_PBALLOCATEFORK
,
915 FILEMGR_PBDELETEOBJECT
,
916 FILEMGR_PBEXCHANGEOBJECT
,
917 FILEMGR_PBGETFORKCBINFO
,
918 FILEMGR_PBGETVOLUMEINFO
,
920 FILEMGR_PBMAKEFSREFUNICODE
,
921 FILEMGR_PBMOVEOBJECT
,
922 FILEMGR_PBOPENITERATOR
,
923 FILEMGR_PBRENAMEUNICODE
,
924 FILEMGR_PBSETCATALOGINFO
,
925 FILEMGR_PBSETVOLUMEINFO
,
926 FILEMGR_FSREFMAKEPATH
,
927 FILEMGR_FSPATHMAKEREF
,
929 FILEMGR_PBGETCATINFO
,
930 FILEMGR_PBGETCATINFOLITE
,
932 FILEMGR_PBXGETVOLINFO
,
936 FILEMGR_PBHGETDIRACCESS
,
937 FILEMGR_PBHSETDIRACCESS
,
947 FILEMGR_PBGETFCBINFO
,
950 FILEMGR_PBALLOCCONTIG
,
952 FILEMGR_PBSETCATINFO
,
953 FILEMGR_PBGETVOLPARMS
,
955 FILEMGR_PBMAKEFSSPEC
,
957 FILEMGR_PBCREATEFILEIDREF
,
958 FILEMGR_PBDELETEFILEIDREF
,
959 FILEMGR_PBRESOLVEFILEIDREF
,
963 FILEMGR_PBEXCHANGEFILES
,
970 FILEMGR_PBUNLOCKRANGE
,
980 int exclude_pids
= 0;
981 int exclude_default_pids
= 1;
984 struct kinfo_proc
*kp_buffer
= 0;
987 #define EVENT_BASE 60000
989 int num_events
= EVENT_BASE
;
992 #define DBG_FUNC_ALL (DBG_FUNC_START | DBG_FUNC_END)
993 #define DBG_FUNC_MASK 0xfffffffc
995 double divisor
= 0.0; /* Trace divisor converts to microseconds */
1001 kbufinfo_t bufinfo
= {0, 0, 0, 0, 0};
1004 /* defines for tracking file descriptor state */
1005 #define FS_USAGE_FD_SETSIZE 256 /* Initial number of file descriptors per
1006 thread that we will track */
1008 #define FS_USAGE_NFDBITS (sizeof (unsigned long) * 8)
1009 #define FS_USAGE_NFDBYTES(n) (((n) / FS_USAGE_NFDBITS) * sizeof (unsigned long))
1011 int trace_enabled
= 0;
1012 int set_remove_flag
= 1;
1016 char *RAW_file
= (char *)0;
1020 uint64_t sample_TOD_secs
;
1021 uint32_t sample_TOD_usecs
;
1023 double bias_now
= 0.0;
1024 double start_time
= 0.0;
1025 double end_time
= 999999999999.9;
1039 void leave() /* exit under normal conditions -- INT handler */
1043 void set_pidcheck();
1044 void set_pidexclude();
1051 if (exclude_pids
== 0) {
1052 for (i
= 0; i
< num_of_pids
; i
++)
1053 set_pidcheck(pids
[i
], 0);
1056 for (i
= 0; i
< num_of_pids
; i
++)
1057 set_pidexclude(pids
[i
], 0);
1073 * This flag is turned off when calling
1074 * quit() due to a set_remove() failure.
1076 if (set_remove_flag
)
1079 fprintf(stderr
, "fs_usage: ");
1081 fprintf(stderr
, "%s", s
);
1087 void get_screenwidth()
1089 struct winsize size
;
1094 if (ioctl(1, TIOCGWINSZ
, &size
) != -1) {
1095 columns
= size
.ws_col
;
1097 if (columns
> MAXWIDTH
)
1113 struct mach_timebase_info mti
;
1115 mach_timebase_info(&mti
);
1117 divisor
= ((double)mti
.denom
/ (double)mti
.numer
) * 1000;
1122 exit_usage(char *myname
) {
1124 fprintf(stderr
, "Usage: %s [-e] [-w] [-f mode] [-b] [-t seconds] [-R rawfile [-S start_time] [-E end_time]] [pid | cmd [pid | cmd] ...]\n", myname
);
1125 fprintf(stderr
, " -e exclude the specified list of pids from the sample\n");
1126 fprintf(stderr
, " and exclude fs_usage by default\n");
1127 fprintf(stderr
, " -w force wider, detailed, output\n");
1128 fprintf(stderr
, " -f output is based on the mode provided\n");
1129 fprintf(stderr
, " mode = \"network\" Show network-related events\n");
1130 fprintf(stderr
, " mode = \"filesys\" Show filesystem-related events\n");
1131 fprintf(stderr
, " mode = \"pathname\" Show only pathname-related events\n");
1132 fprintf(stderr
, " mode = \"exec\" Show only exec and spawn events\n");
1133 fprintf(stderr
, " mode = \"diskio\" Show only disk I/O events\n");
1134 fprintf(stderr
, " mode = \"cachehit\" In addition, show cache hits\n");
1135 fprintf(stderr
, " -b annotate disk I/O events with BootCache info (if available)\n");
1136 fprintf(stderr
, " -t specifies timeout in seconds (for use in automated tools)\n");
1137 fprintf(stderr
, " -R specifies a raw trace file to process\n");
1138 fprintf(stderr
, " -S if -R is specified, selects a start point in microseconds\n");
1139 fprintf(stderr
, " -E if -R is specified, selects an end point in microseconds\n");
1140 fprintf(stderr
, " pid selects process(s) to sample\n");
1141 fprintf(stderr
, " cmd selects process(s) matching command string to sample\n");
1142 fprintf(stderr
, "\n%s will handle a maximum list of %d pids.\n\n", myname
, MAX_PIDS
);
1143 fprintf(stderr
, "By default (no options) the following processes are excluded from the output:\n");
1144 fprintf(stderr
, "fs_usage, Terminal, telnetd, sshd, rlogind, tcsh, csh, sh\n\n");
1150 int filemgr_index(type
) {
1153 return (((type
>> 2) & 0x3fff) + 256);
1155 return (((type
>> 2) & 0x3fff));
1159 void init_tables(void)
1165 for (i
= 0; i
< MAX_BSD_SYSCALL
; i
++) {
1166 bsd_syscalls
[i
].sc_name
= NULL
;
1167 bsd_syscalls
[i
].sc_format
= FMT_DEFAULT
;
1170 for (i
= 0; i
< MAX_FILEMGR
; i
++) {
1171 filemgr_calls
[i
].fm_name
= NULL
;
1174 for (i
= 0; (type
= bsd_syscall_types
[i
]); i
++) {
1176 code
= BSC_INDEX(type
);
1178 if (code
>= MAX_BSD_SYSCALL
) {
1179 printf("BSD syscall init (%x): type exceeds table size\n", type
);
1185 bsd_syscalls
[code
].sc_name
= "sendfile";
1186 bsd_syscalls
[code
].sc_format
= FMT_FD
; /* this should be changed to FMT_SENDFILE */
1187 break; /* once we add an extended info trace event */
1190 case BSC_recvmsg_nocancel
:
1191 bsd_syscalls
[code
].sc_name
= "recvmsg";
1192 bsd_syscalls
[code
].sc_format
= FMT_FD_IO
;
1196 case BSC_sendmsg_nocancel
:
1197 bsd_syscalls
[code
].sc_name
= "sendmsg";
1198 bsd_syscalls
[code
].sc_format
= FMT_FD_IO
;
1202 case BSC_recvfrom_nocancel
:
1203 bsd_syscalls
[code
].sc_name
= "recvfrom";
1204 bsd_syscalls
[code
].sc_format
= FMT_FD_IO
;
1208 case BSC_sendto_nocancel
:
1209 bsd_syscalls
[code
].sc_name
= "sendto";
1210 bsd_syscalls
[code
].sc_format
= FMT_FD_IO
;
1214 case BSC_select_nocancel
:
1215 bsd_syscalls
[code
].sc_name
= "select";
1216 bsd_syscalls
[code
].sc_format
= FMT_SELECT
;
1220 case BSC_accept_nocancel
:
1221 bsd_syscalls
[code
].sc_name
= "accept";
1222 bsd_syscalls
[code
].sc_format
= FMT_FD_2
;
1226 bsd_syscalls
[code
].sc_name
= "socket";
1227 bsd_syscalls
[code
].sc_format
= FMT_SOCKET
;
1231 case BSC_connect_nocancel
:
1232 bsd_syscalls
[code
].sc_name
= "connect";
1233 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1237 bsd_syscalls
[code
].sc_name
= "bind";
1238 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1242 bsd_syscalls
[code
].sc_name
= "listen";
1243 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1247 bsd_syscalls
[code
].sc_name
= "mmap";
1248 bsd_syscalls
[code
].sc_format
= FMT_MMAP
;
1251 case BSC_socketpair
:
1252 bsd_syscalls
[code
].sc_name
= "socketpair";
1256 bsd_syscalls
[code
].sc_name
= "getxattr";
1260 bsd_syscalls
[code
].sc_name
= "setxattr";
1263 case BSC_removexattr
:
1264 bsd_syscalls
[code
].sc_name
= "removexattr";
1268 bsd_syscalls
[code
].sc_name
= "listxattr";
1272 bsd_syscalls
[code
].sc_name
= "stat";
1276 bsd_syscalls
[code
].sc_name
= "stat64";
1279 case BSC_stat_extended
:
1280 bsd_syscalls
[code
].sc_name
= "stat_extended";
1283 case BSC_stat64_extended
:
1284 bsd_syscalls
[code
].sc_name
= "stat_extended64";
1288 bsd_syscalls
[code
].sc_name
= "mount";
1289 bsd_syscalls
[code
].sc_format
= FMT_MOUNT
;
1293 bsd_syscalls
[code
].sc_name
= "unmount";
1294 bsd_syscalls
[code
].sc_format
= FMT_UNMOUNT
;
1298 bsd_syscalls
[code
].sc_name
= "exit";
1302 bsd_syscalls
[code
].sc_name
= "execve";
1305 case BSC_posix_spawn
:
1306 bsd_syscalls
[code
].sc_name
= "posix_spawn";
1310 case BSC_open_nocancel
:
1311 bsd_syscalls
[code
].sc_name
= "open";
1312 bsd_syscalls
[code
].sc_format
= FMT_OPEN
;
1315 case BSC_open_extended
:
1316 bsd_syscalls
[code
].sc_name
= "open_extended";
1317 bsd_syscalls
[code
].sc_format
= FMT_OPEN
;
1320 case BSC_guarded_open_np
:
1321 bsd_syscalls
[code
].sc_name
= "guarded_open_np";
1322 bsd_syscalls
[code
].sc_format
= FMT_OPEN
;
1325 case BSC_open_dprotected_np
:
1326 bsd_syscalls
[code
].sc_name
= "open_dprotected";
1327 bsd_syscalls
[code
].sc_format
= FMT_OPEN
;
1331 bsd_syscalls
[code
].sc_name
= "dup";
1332 bsd_syscalls
[code
].sc_format
= FMT_FD_2
;
1336 bsd_syscalls
[code
].sc_name
= "dup2";
1337 bsd_syscalls
[code
].sc_format
= FMT_FD_2
;
1341 case BSC_close_nocancel
:
1342 bsd_syscalls
[code
].sc_name
= "close";
1343 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1346 case BSC_guarded_close_np
:
1347 bsd_syscalls
[code
].sc_name
= "guarded_close_np";
1348 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1352 case BSC_read_nocancel
:
1353 bsd_syscalls
[code
].sc_name
= "read";
1354 bsd_syscalls
[code
].sc_format
= FMT_FD_IO
;
1358 case BSC_write_nocancel
:
1359 bsd_syscalls
[code
].sc_name
= "write";
1360 bsd_syscalls
[code
].sc_format
= FMT_FD_IO
;
1364 bsd_syscalls
[code
].sc_name
= "fgetxattr";
1365 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1369 bsd_syscalls
[code
].sc_name
= "fsetxattr";
1370 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1373 case BSC_fremovexattr
:
1374 bsd_syscalls
[code
].sc_name
= "fremovexattr";
1375 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1378 case BSC_flistxattr
:
1379 bsd_syscalls
[code
].sc_name
= "flistxattr";
1380 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1384 bsd_syscalls
[code
].sc_name
= "fstat";
1385 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1389 bsd_syscalls
[code
].sc_name
= "fstat64";
1390 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1393 case BSC_fstat_extended
:
1394 bsd_syscalls
[code
].sc_name
= "fstat_extended";
1395 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1398 case BSC_fstat64_extended
:
1399 bsd_syscalls
[code
].sc_name
= "fstat64_extended";
1400 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1404 bsd_syscalls
[code
].sc_name
= "lstat";
1408 bsd_syscalls
[code
].sc_name
= "lstat64";
1411 case BSC_lstat_extended
:
1412 bsd_syscalls
[code
].sc_name
= "lstat_extended";
1415 case BSC_lstat64_extended
:
1416 bsd_syscalls
[code
].sc_name
= "lstat_extended64";
1420 bsd_syscalls
[code
].sc_name
= "link";
1424 bsd_syscalls
[code
].sc_name
= "unlink";
1428 bsd_syscalls
[code
].sc_name
= "mknod";
1432 bsd_syscalls
[code
].sc_name
= "umask";
1433 bsd_syscalls
[code
].sc_format
= FMT_UMASK
;
1436 case BSC_umask_extended
:
1437 bsd_syscalls
[code
].sc_name
= "umask_extended";
1438 bsd_syscalls
[code
].sc_format
= FMT_UMASK
;
1442 bsd_syscalls
[code
].sc_name
= "chmod";
1443 bsd_syscalls
[code
].sc_format
= FMT_CHMOD
;
1446 case BSC_chmod_extended
:
1447 bsd_syscalls
[code
].sc_name
= "chmod_extended";
1448 bsd_syscalls
[code
].sc_format
= FMT_CHMOD_EXT
;
1452 bsd_syscalls
[code
].sc_name
= "fchmod";
1453 bsd_syscalls
[code
].sc_format
= FMT_FCHMOD
;
1456 case BSC_fchmod_extended
:
1457 bsd_syscalls
[code
].sc_name
= "fchmod_extended";
1458 bsd_syscalls
[code
].sc_format
= FMT_FCHMOD_EXT
;
1462 bsd_syscalls
[code
].sc_name
= "chown";
1466 bsd_syscalls
[code
].sc_name
= "lchown";
1470 bsd_syscalls
[code
].sc_name
= "fchown";
1471 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1475 bsd_syscalls
[code
].sc_name
= "access";
1476 bsd_syscalls
[code
].sc_format
= FMT_ACCESS
;
1479 case BSC_access_extended
:
1480 bsd_syscalls
[code
].sc_name
= "access_extended";
1484 bsd_syscalls
[code
].sc_name
= "chdir";
1487 case BSC_pthread_chdir
:
1488 bsd_syscalls
[code
].sc_name
= "pthread_chdir";
1492 bsd_syscalls
[code
].sc_name
= "chroot";
1496 bsd_syscalls
[code
].sc_name
= "utimes";
1500 bsd_syscalls
[code
].sc_name
= "delete-Carbon";
1504 bsd_syscalls
[code
].sc_name
= "undelete";
1508 bsd_syscalls
[code
].sc_name
= "revoke";
1512 bsd_syscalls
[code
].sc_name
= "fsctl";
1516 bsd_syscalls
[code
].sc_name
= "ffsctl";
1517 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1521 bsd_syscalls
[code
].sc_name
= "chflags";
1522 bsd_syscalls
[code
].sc_format
= FMT_CHFLAGS
;
1526 bsd_syscalls
[code
].sc_name
= "fchflags";
1527 bsd_syscalls
[code
].sc_format
= FMT_FCHFLAGS
;
1531 bsd_syscalls
[code
].sc_name
= "fchdir";
1532 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1535 case BSC_pthread_fchdir
:
1536 bsd_syscalls
[code
].sc_name
= "pthread_fchdir";
1537 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1541 bsd_syscalls
[code
].sc_name
= "futimes";
1542 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1546 bsd_syscalls
[code
].sc_name
= "sync";
1550 bsd_syscalls
[code
].sc_name
= "symlink";
1554 bsd_syscalls
[code
].sc_name
= "readlink";
1558 case BSC_fsync_nocancel
:
1559 bsd_syscalls
[code
].sc_name
= "fsync";
1560 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1564 bsd_syscalls
[code
].sc_name
= "fdatasync";
1565 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1569 case BSC_readv_nocancel
:
1570 bsd_syscalls
[code
].sc_name
= "readv";
1571 bsd_syscalls
[code
].sc_format
= FMT_FD_IO
;
1575 case BSC_writev_nocancel
:
1576 bsd_syscalls
[code
].sc_name
= "writev";
1577 bsd_syscalls
[code
].sc_format
= FMT_FD_IO
;
1581 case BSC_pread_nocancel
:
1582 bsd_syscalls
[code
].sc_name
= "pread";
1583 bsd_syscalls
[code
].sc_format
= FMT_PREAD
;
1587 case BSC_pwrite_nocancel
:
1588 bsd_syscalls
[code
].sc_name
= "pwrite";
1589 bsd_syscalls
[code
].sc_format
= FMT_PREAD
;
1593 bsd_syscalls
[code
].sc_name
= "mkdir";
1596 case BSC_mkdir_extended
:
1597 bsd_syscalls
[code
].sc_name
= "mkdir_extended";
1601 bsd_syscalls
[code
].sc_name
= "mkfifo";
1604 case BSC_mkfifo_extended
:
1605 bsd_syscalls
[code
].sc_name
= "mkfifo_extended";
1609 bsd_syscalls
[code
].sc_name
= "rmdir";
1613 bsd_syscalls
[code
].sc_name
= "statfs";
1617 bsd_syscalls
[code
].sc_name
= "statfs64";
1621 bsd_syscalls
[code
].sc_name
= "getfsstat";
1624 case BSC_getfsstat64
:
1625 bsd_syscalls
[code
].sc_name
= "getfsstat64";
1629 bsd_syscalls
[code
].sc_name
= "fstatfs";
1630 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1634 bsd_syscalls
[code
].sc_name
= "fstatfs64";
1635 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1639 bsd_syscalls
[code
].sc_name
= "pathconf";
1643 bsd_syscalls
[code
].sc_name
= "fpathconf";
1644 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1647 case BSC_getdirentries
:
1648 bsd_syscalls
[code
].sc_name
= "getdirentries";
1649 bsd_syscalls
[code
].sc_format
= FMT_FD_IO
;
1652 case BSC_getdirentries64
:
1653 bsd_syscalls
[code
].sc_name
= "getdirentries64";
1654 bsd_syscalls
[code
].sc_format
= FMT_FD_IO
;
1658 bsd_syscalls
[code
].sc_name
= "lseek";
1659 bsd_syscalls
[code
].sc_format
= FMT_LSEEK
;
1663 bsd_syscalls
[code
].sc_name
= "truncate";
1664 bsd_syscalls
[code
].sc_format
= FMT_TRUNC
;
1668 bsd_syscalls
[code
].sc_name
= "ftruncate";
1669 bsd_syscalls
[code
].sc_format
= FMT_FTRUNC
;
1673 bsd_syscalls
[code
].sc_name
= "flock";
1674 bsd_syscalls
[code
].sc_format
= FMT_FLOCK
;
1677 case BSC_getattrlist
:
1678 bsd_syscalls
[code
].sc_name
= "getattrlist";
1681 case BSC_setattrlist
:
1682 bsd_syscalls
[code
].sc_name
= "setattrlist";
1685 case BSC_fgetattrlist
:
1686 bsd_syscalls
[code
].sc_name
= "fgetattrlist";
1687 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1690 case BSC_fsetattrlist
:
1691 bsd_syscalls
[code
].sc_name
= "fsetattrlist";
1692 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1695 case BSC_getdirentriesattr
:
1696 bsd_syscalls
[code
].sc_name
= "getdirentriesattr";
1697 bsd_syscalls
[code
].sc_format
= FMT_FD
;
1700 case BSC_exchangedata
:
1701 bsd_syscalls
[code
].sc_name
= "exchangedata";
1705 bsd_syscalls
[code
].sc_name
= "rename";
1709 bsd_syscalls
[code
].sc_name
= "copyfile";
1712 case BSC_checkuseraccess
:
1713 bsd_syscalls
[code
].sc_name
= "checkuseraccess";
1717 bsd_syscalls
[code
].sc_name
= "searchfs";
1721 bsd_syscalls
[code
].sc_name
= "aio_fsync";
1722 bsd_syscalls
[code
].sc_format
= FMT_AIO_FSYNC
;
1725 case BSC_aio_return
:
1726 bsd_syscalls
[code
].sc_name
= "aio_return";
1727 bsd_syscalls
[code
].sc_format
= FMT_AIO_RETURN
;
1730 case BSC_aio_suspend
:
1731 case BSC_aio_suspend_nocancel
:
1732 bsd_syscalls
[code
].sc_name
= "aio_suspend";
1733 bsd_syscalls
[code
].sc_format
= FMT_AIO_SUSPEND
;
1736 case BSC_aio_cancel
:
1737 bsd_syscalls
[code
].sc_name
= "aio_cancel";
1738 bsd_syscalls
[code
].sc_format
= FMT_AIO_CANCEL
;
1742 bsd_syscalls
[code
].sc_name
= "aio_error";
1743 bsd_syscalls
[code
].sc_format
= FMT_AIO
;
1747 bsd_syscalls
[code
].sc_name
= "aio_read";
1748 bsd_syscalls
[code
].sc_format
= FMT_AIO
;
1752 bsd_syscalls
[code
].sc_name
= "aio_write";
1753 bsd_syscalls
[code
].sc_format
= FMT_AIO
;
1756 case BSC_lio_listio
:
1757 bsd_syscalls
[code
].sc_name
= "lio_listio";
1758 bsd_syscalls
[code
].sc_format
= FMT_LIO_LISTIO
;
1762 case BSC_msync_nocancel
:
1763 bsd_syscalls
[code
].sc_name
= "msync";
1764 bsd_syscalls
[code
].sc_format
= FMT_MSYNC
;
1768 case BSC_fcntl_nocancel
:
1769 bsd_syscalls
[code
].sc_name
= "fcntl";
1770 bsd_syscalls
[code
].sc_format
= FMT_FCNTL
;
1774 bsd_syscalls
[code
].sc_name
= "ioctl";
1775 bsd_syscalls
[code
].sc_format
= FMT_IOCTL
;
1779 bsd_syscalls
[code
].sc_name
= "fsgetpath";
1782 case BSC_getattrlistbulk
:
1783 bsd_syscalls
[code
].sc_name
= "getattrlistbulk";
1787 bsd_syscalls
[code
].sc_name
= "openat";
1788 bsd_syscalls
[code
].sc_format
= FMT_OPENAT
;
1791 case BSC_openat_nocancel
:
1792 bsd_syscalls
[code
].sc_name
= "openat_nocanel";
1793 bsd_syscalls
[code
].sc_format
= FMT_OPENAT
;
1797 bsd_syscalls
[code
].sc_name
= "renameat";
1798 bsd_syscalls
[code
].sc_format
= FMT_RENAMEAT
;
1802 bsd_syscalls
[code
].sc_name
= "chmodat";
1803 bsd_syscalls
[code
].sc_format
= FMT_CHMODAT
;
1807 bsd_syscalls
[code
].sc_name
= "chownat";
1808 bsd_syscalls
[code
].sc_format
= FMT_AT
;
1812 bsd_syscalls
[code
].sc_name
= "fstatat";
1813 bsd_syscalls
[code
].sc_format
= FMT_AT
;
1817 bsd_syscalls
[code
].sc_name
= "fstatat64";
1818 bsd_syscalls
[code
].sc_format
= FMT_AT
;
1822 bsd_syscalls
[code
].sc_name
= "linkat";
1823 bsd_syscalls
[code
].sc_format
= FMT_AT
;
1827 bsd_syscalls
[code
].sc_name
= "unlinkat";
1828 bsd_syscalls
[code
].sc_format
= FMT_AT
;
1831 case BSC_readlinkat
:
1832 bsd_syscalls
[code
].sc_name
= "readlinkat";
1833 bsd_syscalls
[code
].sc_format
= FMT_AT
;
1837 bsd_syscalls
[code
].sc_name
= "symlinkat";
1838 bsd_syscalls
[code
].sc_format
= FMT_AT
;
1842 bsd_syscalls
[code
].sc_name
= "mkdirat";
1843 bsd_syscalls
[code
].sc_format
= FMT_AT
;
1846 case BSC_getattrlistat
:
1847 bsd_syscalls
[code
].sc_name
= "getattrlistat";
1848 bsd_syscalls
[code
].sc_format
= FMT_AT
;
1853 for (i
= 0; (type
= filemgr_call_types
[i
]); i
++) {
1856 code
= filemgr_index(type
);
1858 if (code
>= MAX_FILEMGR
) {
1859 printf("FILEMGR call init (%x): type exceeds table size\n", type
);
1864 case FILEMGR_PBGETCATALOGINFO
:
1865 p
= "GetCatalogInfo";
1868 case FILEMGR_PBGETCATALOGINFOBULK
:
1869 p
= "GetCatalogInfoBulk";
1872 case FILEMGR_PBCREATEFILEUNICODE
:
1873 p
= "CreateFileUnicode";
1876 case FILEMGR_PBCREATEDIRECTORYUNICODE
:
1877 p
= "CreateDirectoryUnicode";
1880 case FILEMGR_PBCREATEFORK
:
1884 case FILEMGR_PBDELETEFORK
:
1888 case FILEMGR_PBITERATEFORK
:
1889 p
= "PBIterateFork";
1892 case FILEMGR_PBOPENFORK
:
1896 case FILEMGR_PBREADFORK
:
1900 case FILEMGR_PBWRITEFORK
:
1904 case FILEMGR_PBALLOCATEFORK
:
1905 p
= "PBAllocateFork";
1908 case FILEMGR_PBDELETEOBJECT
:
1909 p
= "PBDeleteObject";
1912 case FILEMGR_PBEXCHANGEOBJECT
:
1913 p
= "PBExchangeObject";
1916 case FILEMGR_PBGETFORKCBINFO
:
1917 p
= "PBGetForkCBInfo";
1920 case FILEMGR_PBGETVOLUMEINFO
:
1921 p
= "PBGetVolumeInfo";
1924 case FILEMGR_PBMAKEFSREF
:
1928 case FILEMGR_PBMAKEFSREFUNICODE
:
1929 p
= "PBMakeFSRefUnicode";
1932 case FILEMGR_PBMOVEOBJECT
:
1936 case FILEMGR_PBOPENITERATOR
:
1937 p
= "PBOpenIterator";
1940 case FILEMGR_PBRENAMEUNICODE
:
1941 p
= "PBRenameUnicode";
1944 case FILEMGR_PBSETCATALOGINFO
:
1945 p
= "SetCatalogInfo";
1948 case FILEMGR_PBSETVOLUMEINFO
:
1949 p
= "SetVolumeInfo";
1952 case FILEMGR_FSREFMAKEPATH
:
1953 p
= "FSRefMakePath";
1956 case FILEMGR_FSPATHMAKEREF
:
1957 p
= "FSPathMakeRef";
1960 case FILEMGR_PBGETCATINFO
:
1964 case FILEMGR_PBGETCATINFOLITE
:
1965 p
= "GetCatInfoLite";
1968 case FILEMGR_PBHGETFINFO
:
1972 case FILEMGR_PBXGETVOLINFO
:
1973 p
= "PBXGetVolInfo";
1976 case FILEMGR_PBHCREATE
:
1980 case FILEMGR_PBHOPENDF
:
1984 case FILEMGR_PBHOPENRF
:
1988 case FILEMGR_PBHGETDIRACCESS
:
1989 p
= "PBHGetDirAccess";
1992 case FILEMGR_PBHSETDIRACCESS
:
1993 p
= "PBHSetDirAccess";
1996 case FILEMGR_PBHMAPID
:
2000 case FILEMGR_PBHMAPNAME
:
2004 case FILEMGR_PBCLOSE
:
2008 case FILEMGR_PBFLUSHFILE
:
2012 case FILEMGR_PBGETEOF
:
2016 case FILEMGR_PBSETEOF
:
2020 case FILEMGR_PBGETFPOS
:
2024 case FILEMGR_PBREAD
:
2028 case FILEMGR_PBWRITE
:
2032 case FILEMGR_PBGETFCBINFO
:
2036 case FILEMGR_PBSETFINFO
:
2040 case FILEMGR_PBALLOCATE
:
2044 case FILEMGR_PBALLOCCONTIG
:
2045 p
= "PBAllocContig";
2048 case FILEMGR_PBSETFPOS
:
2052 case FILEMGR_PBSETCATINFO
:
2056 case FILEMGR_PBGETVOLPARMS
:
2057 p
= "PBGetVolParms";
2060 case FILEMGR_PBSETVINFO
:
2064 case FILEMGR_PBMAKEFSSPEC
:
2068 case FILEMGR_PBHGETVINFO
:
2072 case FILEMGR_PBCREATEFILEIDREF
:
2073 p
= "PBCreateFileIDRef";
2076 case FILEMGR_PBDELETEFILEIDREF
:
2077 p
= "PBDeleteFileIDRef";
2080 case FILEMGR_PBRESOLVEFILEIDREF
:
2081 p
= "PBResolveFileIDRef";
2084 case FILEMGR_PBFLUSHVOL
:
2088 case FILEMGR_PBHRENAME
:
2092 case FILEMGR_PBCATMOVE
:
2096 case FILEMGR_PBEXCHANGEFILES
:
2097 p
= "PBExchangeFiles";
2100 case FILEMGR_PBHDELETE
:
2104 case FILEMGR_PBDIRCREATE
:
2108 case FILEMGR_PBCATSEARCH
:
2112 case FILEMGR_PBHSETFLOCK
:
2116 case FILEMGR_PBHRSTFLOCK
:
2120 case FILEMGR_PBLOCKRANGE
:
2124 case FILEMGR_PBUNLOCKRANGE
:
2125 p
= "PBUnlockRange";
2132 filemgr_calls
[code
].fm_name
= p
;
2143 char *myname
= "fs_usage";
2147 time_t stop_at_time
= 0;
2149 if (0 != reexec_to_match_kernel()) {
2150 fprintf(stderr
, "Could not re-execute: %d\n", errno
);
2159 if ((myname
= rindex(argv
[0], '/')) == 0)
2165 while ((ch
= getopt(argc
, argv
, "bewf:R:S:E:t:")) != EOF
) {
2171 exclude_default_pids
= 0;
2176 if ((uint
)columns
< MAX_WIDE_MODE_COLS
)
2177 columns
= MAX_WIDE_MODE_COLS
;
2181 if (!strcmp(optarg
, "network"))
2182 filter_mode
|= NETWORK_FILTER
;
2183 else if (!strcmp(optarg
, "filesys"))
2184 filter_mode
|= FILESYS_FILTER
;
2185 else if (!strcmp(optarg
, "cachehit"))
2186 show_cachehits
= TRUE
;
2187 else if (!strcmp(optarg
, "exec"))
2188 filter_mode
|= EXEC_FILTER
;
2189 else if (!strcmp(optarg
, "pathname"))
2190 filter_mode
|= PATHNAME_FILTER
;
2191 else if (!strcmp(optarg
, "diskio"))
2192 filter_mode
|= DISKIO_FILTER
;
2200 stop_at_time
= time(NULL
) + strtoul(optarg
, NULL
, 10);
2209 start_time
= atof(optarg
);
2213 end_time
= atof(optarg
);
2221 if ( geteuid() != 0 ) {
2222 fprintf(stderr
, "'fs_usage' must be run as root...\n");
2230 * when excluding, fs_usage should be the first in line for pids[]
2232 * the !exclude_pids && argc == 0 catches the exclude_default_pids
2233 * case below where exclude_pids is later set and the fs_usage PID
2234 * needs to make it into pids[]
2236 if (exclude_pids
|| (!exclude_pids
&& argc
== 0)) {
2237 if (num_of_pids
< (MAX_PIDS
- 1))
2238 pids
[num_of_pids
++] = getpid();
2242 * If we process any list of pids/cmds, then turn off the defaults
2245 exclude_default_pids
= 0;
2247 while (argc
> 0 && num_of_pids
< (MAX_PIDS
- 1)) {
2254 * Exclude a set of default pids
2256 if (exclude_default_pids
) {
2257 argtopid("Terminal");
2258 argtopid("telnetd");
2261 argtopid("rlogind");
2268 for (i
= 0; i
< num_of_pids
; i
++) {
2270 fprintf(stderr
, "exclude pid %d\n", pids
[i
]);
2272 fprintf(stderr
, "pid %d\n", pids
[i
]);
2276 struct sigaction osa
;
2280 /* set up signal handlers */
2281 signal(SIGINT
, leave
);
2282 signal(SIGQUIT
, leave
);
2284 sigaction(SIGHUP
, (struct sigaction
*)NULL
, &osa
);
2286 if (osa
.sa_handler
== SIG_DFL
)
2287 signal(SIGHUP
, leave
);
2288 signal(SIGTERM
, leave
);
2290 * grab the number of cpus
2295 len
= sizeof(num_cpus
);
2297 sysctl(mib
, 2, &num_cpus
, &len
, NULL
, 0);
2298 num_events
= EVENT_BASE
* num_cpus
;
2300 signal(SIGWINCH
, sigwinch
);
2302 if ((my_buffer
= malloc(num_events
* sizeof(kd_buf
))) == (char *)0)
2303 quit("can't allocate memory for tracing info\n");
2305 if (ReadSharedCacheMap("/var/db/dyld/dyld_shared_cache_i386.map", &framework32
, "/var/db/dyld/dyld_shared_cache_i386")) {
2306 ReadSharedCacheMap("/var/db/dyld/dyld_shared_cache_x86_64.map", &framework64
, "/var/db/dyld/dyld_shared_cache_x86_64");
2308 ReadSharedCacheMap("/var/db/dyld/dyld_shared_cache_ppc.map", &framework32
, "/var/db/dyld/dyld_shared_cache_ppc");
2309 ReadSharedCacheMap("/var/db/dyld/dyld_shared_cache_ppc64.map", &framework64
, "/var/db/dyld/dyld_shared_cache_ppc64");
2311 SortFrameworkAddresses();
2318 set_numbufs(num_events
);
2321 if (exclude_pids
== 0) {
2322 for (i
= 0; i
< num_of_pids
; i
++)
2323 set_pidcheck(pids
[i
], 1);
2325 for (i
= 0; i
< num_of_pids
; i
++)
2326 set_pidexclude(pids
[i
], 1);
2328 if (select_pid_mode
&& !one_good_pid
) {
2330 * An attempt to restrict output to a given
2331 * pid or command has failed. Exit gracefully
2341 init_arguments_buffer();
2350 while (stop_at_time
== 0 || last_time
< stop_at_time
) {
2352 usleep(1000 * usleep_ms
);
2356 last_time
= time((long *)0);
2365 struct kinfo_proc
*kp
;
2369 mib
[2] = KERN_PROC_ALL
;
2372 if (sysctl(mib
, 4, NULL
, &bufSize
, NULL
, 0) < 0)
2373 quit("trace facility failure, KERN_PROC_ALL\n");
2375 if ((kp
= (struct kinfo_proc
*)malloc(bufSize
)) == (struct kinfo_proc
*)0)
2376 quit("can't allocate memory for proc buffer\n");
2378 if (sysctl(mib
, 4, kp
, &bufSize
, NULL
, 0) < 0)
2379 quit("trace facility failure, KERN_PROC_ALL\n");
2381 kp_nentries
= bufSize
/ sizeof(struct kinfo_proc
);
2390 mib
[1] = KERN_KDEBUG
;
2391 mib
[2] = KERN_KDENABLE
; /* protocol */
2394 mib
[5] = 0; /* no flags */
2396 if (sysctl(mib
, 4, NULL
, &needed
, NULL
, 0) < 0)
2397 quit("trace facility failure, KERN_KDENABLE\n");
2406 set_numbufs(int nbufs
)
2409 mib
[1] = KERN_KDEBUG
;
2410 mib
[2] = KERN_KDSETBUF
;
2413 mib
[5] = 0; /* no flags */
2415 if (sysctl(mib
, 4, NULL
, &needed
, NULL
, 0) < 0)
2416 quit("trace facility failure, KERN_KDSETBUF\n");
2419 mib
[1] = KERN_KDEBUG
;
2420 mib
[2] = KERN_KDSETUP
;
2423 mib
[5] = 0; /* no flags */
2425 if (sysctl(mib
, 3, NULL
, &needed
, NULL
, 0) < 0)
2426 quit("trace facility failure, KERN_KDSETUP\n");
2429 #define ENCODE_CSC_LOW(class, subclass) \
2430 ( (uint16_t) ( ((class) & 0xff) << 8 ) | ((subclass) & 0xff) )
2435 uint8_t type_filter_bitmap
[KDBG_TYPEFILTER_BITMAP_SIZE
];
2436 bzero(type_filter_bitmap
, sizeof(type_filter_bitmap
));
2438 setbit(type_filter_bitmap
, ENCODE_CSC_LOW(DBG_TRACE
,DBG_TRACE_DATA
));
2439 setbit(type_filter_bitmap
, ENCODE_CSC_LOW(DBG_TRACE
,DBG_TRACE_STRING
));
2441 setbit(type_filter_bitmap
, ENCODE_CSC_LOW(DBG_MACH
,DBG_MACH_EXCP_SC
)); //0x010c
2442 setbit(type_filter_bitmap
, ENCODE_CSC_LOW(DBG_MACH
,DBG_MACH_VM
)); //0x0130
2443 setbit(type_filter_bitmap
, ENCODE_CSC_LOW(DBG_MACH
,DBG_MACH_SCHED
)); //0x0140
2445 setbit(type_filter_bitmap
, ENCODE_CSC_LOW(DBG_FSYSTEM
,DBG_FSRW
)); //0x0301
2446 setbit(type_filter_bitmap
, ENCODE_CSC_LOW(DBG_FSYSTEM
,DBG_DKRW
)); //0x0302
2447 setbit(type_filter_bitmap
, ENCODE_CSC_LOW(DBG_FSYSTEM
,DBG_IOCTL
)); //0x0306
2448 setbit(type_filter_bitmap
, ENCODE_CSC_LOW(DBG_FSYSTEM
,DBG_BOOTCACHE
)); //0x0307
2450 setbit(type_filter_bitmap
, ENCODE_CSC_LOW(DBG_BSD
,DBG_BSD_EXCP_SC
)); //0x040c
2451 setbit(type_filter_bitmap
, ENCODE_CSC_LOW(DBG_BSD
,DBG_BSD_PROC
)); //0x0401
2452 setbit(type_filter_bitmap
, ENCODE_CSC_LOW(DBG_BSD
,DBG_BSD_SC_EXTENDED_INFO
)); //0x040e
2453 setbit(type_filter_bitmap
, ENCODE_CSC_LOW(DBG_BSD
,DBG_BSD_SC_EXTENDED_INFO2
)); //0x040f
2455 setbit(type_filter_bitmap
, ENCODE_CSC_LOW(DBG_CORESTORAGE
,DBG_CS_IO
)); //0x0a00
2456 setbit(type_filter_bitmap
, ENCODE_CSC_LOW(DBG_CORESTORAGE
, 1)); //0x0a01 for P_SCCS_SYNC_DIS
2458 setbit(type_filter_bitmap
, ENCODE_CSC_LOW(FILEMGR_CLASS
, 0)); //Carbon File Manager
2459 setbit(type_filter_bitmap
, ENCODE_CSC_LOW(FILEMGR_CLASS
, 1)); //Carbon File Manager
2462 int mib
[] = { CTL_KERN
, KERN_KDEBUG
, KERN_KDSET_TYPEFILTER
};
2463 size_t needed
= KDBG_TYPEFILTER_BITMAP_SIZE
;
2464 if(sysctl(mib
, 3, type_filter_bitmap
, &needed
, NULL
, 0)) {
2465 quit("trace facility failure, KERN_KDSET_TYPEFILTER\n");
2470 set_pidcheck(int pid
, int on_off
)
2474 kr
.type
= KDBG_TYPENONE
;
2477 needed
= sizeof(kd_regtype
);
2479 mib
[1] = KERN_KDEBUG
;
2480 mib
[2] = KERN_KDPIDTR
;
2485 if (sysctl(mib
, 3, &kr
, &needed
, NULL
, 0) < 0) {
2487 fprintf(stderr
, "pid %d does not exist\n", pid
);
2493 * on_off == 0 turns off pid exclusion
2494 * on_off == 1 turns on pid exclusion
2497 set_pidexclude(int pid
, int on_off
)
2503 kr
.type
= KDBG_TYPENONE
;
2506 needed
= sizeof(kd_regtype
);
2508 mib
[1] = KERN_KDEBUG
;
2509 mib
[2] = KERN_KDPIDEX
;
2514 if (sysctl(mib
, 3, &kr
, &needed
, NULL
, 0) < 0) {
2516 fprintf(stderr
, "pid %d does not exist\n", pid
);
2521 get_bufinfo(kbufinfo_t
*val
)
2523 needed
= sizeof (*val
);
2525 mib
[1] = KERN_KDEBUG
;
2526 mib
[2] = KERN_KDGETBUF
;
2529 mib
[5] = 0; /* no flags */
2531 if (sysctl(mib
, 3, val
, &needed
, 0, 0) < 0)
2532 quit("trace facility failure, KERN_KDGETBUF\n");
2542 mib
[1] = KERN_KDEBUG
;
2543 mib
[2] = KERN_KDREMOVE
; /* protocol */
2546 mib
[5] = 0; /* no flags */
2548 if (sysctl(mib
, 3, NULL
, &needed
, NULL
, 0) < 0) {
2549 set_remove_flag
= 0;
2552 quit("the trace facility is currently in use...\n fs_usage, sc_usage, and latency use this feature.\n\n");
2554 quit("trace facility failure, KERN_KDREMOVE\n");
2562 kr
.type
= KDBG_RANGETYPE
;
2565 needed
= sizeof(kd_regtype
);
2568 mib
[1] = KERN_KDEBUG
;
2569 mib
[2] = KERN_KDSETREG
;
2572 mib
[5] = 0; /* no flags */
2574 if (sysctl(mib
, 3, &kr
, &needed
, NULL
, 0) < 0)
2575 quit("trace facility failure, KERN_KDSETREG\n");
2578 mib
[1] = KERN_KDEBUG
;
2579 mib
[2] = KERN_KDSETUP
;
2582 mib
[5] = 0; /* no flags */
2584 if (sysctl(mib
, 3, NULL
, &needed
, NULL
, 0) < 0)
2585 quit("trace facility failure, KERN_KDSETUP\n");
2595 uint32_t my_buffer_size
= 0;
2598 get_bufinfo(&bufinfo
);
2600 my_buffer_size
= num_events
* sizeof(kd_buf
);
2607 needed
= bufinfo
.nkdbufs
* sizeof(kd_buf
);
2610 mib
[1] = KERN_KDEBUG
;
2611 mib
[2] = KERN_KDREADTR
;
2614 mib
[5] = 0; /* no flags */
2616 if (sysctl(mib
, 3, my_buffer
, &needed
, NULL
, 0) < 0)
2617 quit("trace facility failure, KERN_KDREADTR\n");
2620 if (count
> (num_events
/ 8)) {
2621 if (usleep_ms
> USLEEP_BEHIND
)
2622 usleep_ms
= USLEEP_BEHIND
;
2623 else if (usleep_ms
> USLEEP_MIN
)
2626 } else if (count
< (num_events
/ 16)) {
2627 if (usleep_ms
< USLEEP_MAX
)
2631 if (bufinfo
.flags
& KDBG_WRAPPED
) {
2632 fprintf(stderr
, "fs_usage: buffer overrun, events generated too quickly: %d\n", count
);
2634 delete_all_events();
2644 if ((bytes_read
= read(RAW_fd
, my_buffer
, my_buffer_size
)) < sizeof(kd_buf
))
2646 count
= bytes_read
/ sizeof(kd_buf
);
2648 kd
= (kd_buf
*)my_buffer
;
2650 fprintf(stderr
, "READTR returned %d items\n", count
);
2652 for (i
= 0; i
< count
; i
++) {
2666 thread
= kd
[i
].arg5
;
2667 debugid
= kd
[i
].debugid
;
2668 type
= kd
[i
].debugid
& DBG_FUNC_MASK
;
2670 now
= kdbg_get_timestamp(&kd
[i
]);
2672 if (i
== 0 && !RAW_flag
) {
2674 curr_time
= time((long *)0);
2676 * Compute bias seconds after each trace buffer read.
2677 * This helps resync timestamps with the system clock
2678 * in the event of a system sleep.
2680 if (bias_secs
== 0 || curr_time
< last_time
|| curr_time
> (last_time
+ 2)) {
2681 l_usecs
= (long long)(now
/ divisor
);
2682 secs
= l_usecs
/ 1000000;
2683 bias_secs
= curr_time
- secs
;
2686 if (RAW_flag
&& bias_now
== 0.0)
2689 if ((type
& P_DISKIO_MASK
) == P_DISKIO
) {
2690 insert_diskio(type
, kd
[i
].arg1
, kd
[i
].arg2
, kd
[i
].arg3
, kd
[i
].arg4
, thread
, (double)now
);
2693 if ((type
& P_DISKIO_MASK
) == P_DISKIO_DONE
) {
2694 if ((dio
= complete_diskio(kd
[i
].arg1
, kd
[i
].arg4
, kd
[i
].arg3
, thread
, (double)now
))) {
2695 dio
->vnodeid
= kd
[i
].arg2
;
2702 if ((type
& CLASS_MASK
) == P_CS_Class
) {
2704 // the usual DBG_FUNC_START/END does not work for i/o since it will
2705 // return on a different thread, this code uses the P_CS_IO_Done (0x4) bit
2706 // instead. the trace command doesn't know how handle either method
2707 // (unmatched start/end or 0x4) but works a little better this way.
2709 int cs_type
= type
& P_CS_Type_Mask
; // strip out the done bit
2710 bool start
= (type
& P_CS_IO_Done
) != P_CS_IO_Done
;
2714 case P_CS_ReadChunk
:
2715 case P_CS_WriteChunk
:
2717 case P_CS_MetaWrite
:
2719 insert_diskio(cs_type
, kd
[i
].arg2
, kd
[i
].arg1
, kd
[i
].arg3
, kd
[i
].arg4
, thread
, (double)now
);
2721 if ((dio
= complete_diskio(kd
[i
].arg2
, kd
[i
].arg4
, kd
[i
].arg3
, thread
, (double)now
))) {
2728 case P_CS_TransformRead
:
2729 case P_CS_TransformWrite
:
2730 case P_CS_MigrationRead
:
2731 case P_CS_MigrationWrite
:
2733 insert_diskio(cs_type
, kd
[i
].arg2
, CS_DEV
, kd
[i
].arg3
, kd
[i
].arg4
, thread
, (double)now
);
2735 if ((dio
= complete_diskio(kd
[i
].arg2
, kd
[i
].arg4
, kd
[i
].arg3
, thread
, (double)now
))) {
2742 case P_CS_SYNC_DISK
:
2744 enter_event(thread
, cs_type
, &kd
[i
], NULL
, (double)now
);
2746 exit_event(" SyncCacheCS", thread
, cs_type
, kd
[i
].arg1
, 0, 0, 0, FMT_SYNC_DISK_CS
, (double)now
);
2751 continue; // ignore other cs timestamps
2756 case TRACE_DATA_NEWTHREAD
:
2758 if ((ti
= add_event(thread
, TRACE_DATA_NEWTHREAD
)) == NULL
)
2760 ti
->child_thread
= kd
[i
].arg1
;
2761 ti
->pid
= kd
[i
].arg2
;
2765 case TRACE_STRING_NEWTHREAD
:
2766 if ((ti
= find_event(thread
, TRACE_DATA_NEWTHREAD
)) == (struct th_info
*)0)
2769 create_map_entry(ti
->child_thread
, ti
->pid
, (char *)&kd
[i
].arg1
);
2774 case TRACE_DATA_EXEC
:
2775 if ((ti
= add_event(thread
, TRACE_DATA_EXEC
)) == NULL
)
2778 ti
->pid
= kd
[i
].arg1
;
2781 case TRACE_STRING_EXEC
:
2782 if ((ti
= find_event(thread
, BSC_execve
))) {
2783 if (ti
->lookups
[0].pathname
[0])
2784 exit_event("execve", thread
, BSC_execve
, 0, 0, 0, 0, FMT_DEFAULT
, (double)now
);
2786 } else if ((ti
= find_event(thread
, BSC_posix_spawn
))) {
2787 if (ti
->lookups
[0].pathname
[0])
2788 exit_event("posix_spawn", thread
, BSC_posix_spawn
, 0, 0, 0, 0, FMT_DEFAULT
, (double)now
);
2790 if ((ti
= find_event(thread
, TRACE_DATA_EXEC
)) == (struct th_info
*)0)
2793 create_map_entry(thread
, ti
->pid
, (char *)&kd
[i
].arg1
);
2798 case BSC_thread_terminate
:
2799 delete_map_entry(thread
);
2806 kd
[i
].arg1
= kd
[i
].arg2
>> 8;
2811 if (kd
[i
].arg4
& MAP_ANON
)
2817 case MACH_stkhandoff
:
2818 mark_thread_waited(thread
);
2822 case BC_IO_HIT_STALLED
:
2824 case BC_IO_MISS_CUT_THROUGH
:
2825 case BC_PLAYBACK_IO
:
2826 if ((dio
= find_diskio(kd
[i
].arg1
)) != NULL
)
2827 dio
->bc_info
= type
;
2830 case HFS_modify_block_end
:
2831 if ((ti
= find_event(thread
, 0))) {
2833 add_meta_name(kd
[i
].arg2
, ti
->nameptr
);
2838 add_vnode_name(kd
[i
].arg2
, find_vnode_name(kd
[i
].arg1
));
2842 if ((ti
= find_event(thread
, 0)) == (struct th_info
*)0)
2845 if (debugid
& DBG_FUNC_START
) {
2847 if (ti
->in_hfs_update
) {
2848 ti
->pn_work_index
= (MAX_PATHNAMES
- 1);
2850 if (ti
->pn_scall_index
< MAX_SCALL_PATHNAMES
)
2851 ti
->pn_work_index
= ti
->pn_scall_index
;
2855 sargptr
= &ti
->lookups
[ti
->pn_work_index
].pathname
[0];
2857 ti
->vnodeid
= kd
[i
].arg1
;
2859 *sargptr
++ = kd
[i
].arg2
;
2860 *sargptr
++ = kd
[i
].arg3
;
2861 *sargptr
++ = kd
[i
].arg4
;
2863 * NULL terminate the 'string'
2867 ti
->pathptr
= sargptr
;
2869 sargptr
= ti
->pathptr
;
2872 * We don't want to overrun our pathname buffer if the
2873 * kernel sends us more VFS_LOOKUP entries than we can
2874 * handle and we only handle 2 pathname lookups for
2875 * a given system call
2880 if ((uintptr_t)sargptr
< (uintptr_t)&ti
->lookups
[ti
->pn_work_index
].pathname
[NUMPARMS
]) {
2882 *sargptr
++ = kd
[i
].arg1
;
2883 *sargptr
++ = kd
[i
].arg2
;
2884 *sargptr
++ = kd
[i
].arg3
;
2885 *sargptr
++ = kd
[i
].arg4
;
2887 * NULL terminate the 'string'
2892 if (debugid
& DBG_FUNC_END
) {
2894 ti
->nameptr
= add_vnode_name(ti
->vnodeid
, &ti
->lookups
[ti
->pn_work_index
].pathname
[0]);
2896 if (ti
->pn_work_index
== ti
->pn_scall_index
) {
2898 ti
->pn_scall_index
++;
2900 if (ti
->pn_scall_index
< MAX_SCALL_PATHNAMES
)
2901 ti
->pathptr
= &ti
->lookups
[ti
->pn_scall_index
].pathname
[0];
2906 ti
->pathptr
= sargptr
;
2911 if (debugid
& DBG_FUNC_START
) {
2914 if ((type
& CLASS_MASK
) == FILEMGR_BASE
) {
2916 index
= filemgr_index(type
);
2918 if (index
>= MAX_FILEMGR
)
2921 if ((p
= filemgr_calls
[index
].fm_name
) == NULL
)
2926 enter_event(thread
, type
, &kd
[i
], p
, (double)now
);
2933 exit_event(" THROTTLED", thread
, type
, 0, 0, 0, 0, FMT_DEFAULT
, (double)now
);
2937 exit_event(" HFS_update", thread
, type
, kd
[i
].arg1
, kd
[i
].arg2
, 0, 0, FMT_HFS_update
, (double)now
);
2940 case SPEC_unmap_info
:
2941 if (check_filter_mode(NULL
, SPEC_unmap_info
, 0, 0, "SPEC_unmap_info"))
2942 format_print(NULL
, " TrimExtent", thread
, type
, kd
[i
].arg1
, kd
[i
].arg2
, kd
[i
].arg3
, 0, FMT_UNMAP_INFO
, now
, now
, 0, "", NULL
);
2946 if (kd
[i
].arg2
== DKIOCSYNCHRONIZECACHE
)
2947 exit_event("IOCTL", thread
, type
, kd
[i
].arg1
, kd
[i
].arg2
, 0, 0, FMT_IOCTL_SYNC
, (double)now
);
2948 else if (kd
[i
].arg2
== DKIOCUNMAP
)
2949 exit_event("IOCTL", thread
, type
, kd
[i
].arg1
, kd
[i
].arg2
, 0, 0, FMT_IOCTL_UNMAP
, (double)now
);
2951 if ((ti
= find_event(thread
, type
)))
2958 exit_event("PAGE_OUT_ANON", thread
, type
, 0, kd
[i
].arg1
, 0, 0, FMT_PGOUT
, (double)now
);
2960 exit_event("PAGE_OUT_FILE", thread
, type
, 0, kd
[i
].arg1
, 0, 0, FMT_PGOUT
, (double)now
);
2964 if (kd
[i
].arg4
== DBG_PAGEIN_FAULT
)
2965 exit_event("PAGE_IN", thread
, type
, 0, kd
[i
].arg1
, kd
[i
].arg2
, 0, FMT_PGIN
, (double)now
);
2966 else if (kd
[i
].arg4
== DBG_PAGEINV_FAULT
)
2967 exit_event("PAGE_IN_FILE", thread
, type
, 0, kd
[i
].arg1
, kd
[i
].arg2
, 0, FMT_PGIN
, (double)now
);
2968 else if (kd
[i
].arg4
== DBG_PAGEIND_FAULT
)
2969 exit_event("PAGE_IN_ANON", thread
, type
, 0, kd
[i
].arg1
, kd
[i
].arg2
, 0, FMT_PGIN
, (double)now
);
2970 else if (kd
[i
].arg4
== DBG_CACHE_HIT_FAULT
)
2971 exit_event("CACHE_HIT", thread
, type
, 0, kd
[i
].arg1
, kd
[i
].arg2
, 0, FMT_CACHEHIT
, (double)now
);
2973 if ((ti
= find_event(thread
, type
)))
2979 exit_event("map_fd", thread
, type
, kd
[i
].arg1
, kd
[i
].arg2
, 0, 0, FMT_FD
, (double)now
);
2982 case BSC_mmap_extended
:
2983 case BSC_mmap_extended2
:
2984 case BSC_msync_extended
:
2985 case BSC_pread_extended
:
2986 case BSC_pwrite_extended
:
2987 extend_syscall(thread
, type
, &kd
[i
]);
2991 if ((type
& CSC_MASK
) == BSC_BASE
) {
2993 if ((index
= BSC_INDEX(type
)) >= MAX_BSD_SYSCALL
)
2996 if (bsd_syscalls
[index
].sc_name
) {
2997 exit_event(bsd_syscalls
[index
].sc_name
, thread
, type
, kd
[i
].arg1
, kd
[i
].arg2
, kd
[i
].arg3
, kd
[i
].arg4
,
2998 bsd_syscalls
[index
].sc_format
, (double)now
);
3000 if (type
== BSC_exit
)
3001 delete_map_entry(thread
);
3003 } else if ((type
& CLASS_MASK
) == FILEMGR_BASE
) {
3005 if ((index
= filemgr_index(type
)) >= MAX_FILEMGR
)
3008 if (filemgr_calls
[index
].fm_name
) {
3009 exit_event(filemgr_calls
[index
].fm_name
, thread
, type
, kd
[i
].arg1
, kd
[i
].arg2
, kd
[i
].arg3
, kd
[i
].arg4
,
3010 FMT_DEFAULT
, (double)now
);
3019 enter_event_now(uintptr_t thread
, int type
, kd_buf
*kd
, char *name
, double now
)
3033 if ((ti
= add_event(thread
, type
)) == NULL
)
3037 ti
->arg1
= kd
->arg1
;
3038 ti
->arg2
= kd
->arg2
;
3039 ti
->arg3
= kd
->arg3
;
3040 ti
->arg4
= kd
->arg4
;
3045 ti
->in_hfs_update
= 1;
3049 if ((type
& CLASS_MASK
) == FILEMGR_BASE
&&
3050 (!RAW_flag
|| (now
>= start_time
&& now
<= end_time
))) {
3052 filemgr_in_progress
++;
3056 l_usecs
= (long long)((now
- bias_now
) / divisor
);
3057 l_usecs
+= (sample_TOD_secs
* 1000000) + sample_TOD_usecs
;
3059 l_usecs
= (long long)(now
/ divisor
);
3060 secs
= l_usecs
/ 1000000;
3061 curr_time
= bias_secs
+ secs
;
3063 sprintf(buf
, "%-8.8s", &(ctime(&curr_time
)[11]));
3064 tsclen
= strlen(buf
);
3066 if (columns
> MAXCOLS
|| wideflag
) {
3067 usecs
= l_usecs
- (long long)((long long)secs
* 1000000);
3068 sprintf(&buf
[tsclen
], ".%06ld", (long)usecs
);
3069 tsclen
= strlen(buf
);
3073 * Print timestamp column
3077 tme
= find_map_entry(thread
);
3079 sprintf(buf
, " %-25.25s ", name
);
3080 nmclen
= strlen(buf
);
3083 sprintf(buf
, "(%d, 0x%lx, 0x%lx, 0x%lx)", (short)kd
->arg1
, kd
->arg2
, kd
->arg3
, kd
->arg4
);
3084 argsclen
= strlen(buf
);
3087 * Calculate white space out to command
3089 if (columns
> MAXCOLS
|| wideflag
) {
3090 clen
= columns
- (tsclen
+ nmclen
+ argsclen
+ 20 + 11);
3092 clen
= columns
- (tsclen
+ nmclen
+ argsclen
+ 12);
3095 printf("%s", buf
); /* print the kdargs */
3096 memset(buf
, ' ', clen
);
3100 else if ((argsclen
+ clen
) > 0) {
3102 * no room so wipe out the kdargs
3104 memset(buf
, ' ', (argsclen
+ clen
));
3105 buf
[argsclen
+ clen
] = '\0';
3108 if (columns
> MAXCOLS
|| wideflag
)
3109 printf("%s.%d\n", tme
->tm_command
, (int)thread
);
3111 printf("%-12.12s\n", tme
->tm_command
);
3113 printf(" %-24.24s (%5d, %#lx, 0x%lx, 0x%lx)\n", name
, (short)kd
->arg1
, kd
->arg2
, kd
->arg3
, kd
->arg4
);
3119 enter_event(uintptr_t thread
, int type
, kd_buf
*kd
, char *name
, double now
)
3125 case P_CS_SYNC_DISK
:
3132 enter_event_now(thread
, type
, kd
, name
, now
);
3136 if ((type
& CSC_MASK
) == BSC_BASE
) {
3138 if ((index
= BSC_INDEX(type
)) >= MAX_BSD_SYSCALL
)
3141 if (bsd_syscalls
[index
].sc_name
)
3142 enter_event_now(thread
, type
, kd
, name
, now
);
3145 if ((type
& CLASS_MASK
) == FILEMGR_BASE
) {
3147 if ((index
= filemgr_index(type
)) >= MAX_FILEMGR
)
3150 if (filemgr_calls
[index
].fm_name
)
3151 enter_event_now(thread
, type
, kd
, name
, now
);
3157 * Handle system call extended trace data.
3159 * Wipe out the kd args that were collected upon syscall_entry
3160 * because it is the extended info that we really want, and it
3161 * is all we really need.
3165 extend_syscall(uintptr_t thread
, int type
, kd_buf
*kd
)
3170 case BSC_mmap_extended
:
3171 if ((ti
= find_event(thread
, BSC_mmap
)) == (struct th_info
*)0)
3173 ti
->arg8
= ti
->arg3
; /* save protection */
3174 ti
->arg1
= kd
->arg1
; /* the fd */
3175 ti
->arg3
= kd
->arg2
; /* bottom half address */
3176 ti
->arg5
= kd
->arg3
; /* bottom half size */
3178 case BSC_mmap_extended2
:
3179 if ((ti
= find_event(thread
, BSC_mmap
)) == (struct th_info
*)0)
3181 ti
->arg2
= kd
->arg1
; /* top half address */
3182 ti
->arg4
= kd
->arg2
; /* top half size */
3183 ti
->arg6
= kd
->arg3
; /* top half file offset */
3184 ti
->arg7
= kd
->arg4
; /* bottom half file offset */
3186 case BSC_msync_extended
:
3187 if ((ti
= find_event(thread
, BSC_msync
)) == (struct th_info
*)0) {
3188 if ((ti
= find_event(thread
, BSC_msync_nocancel
)) == (struct th_info
*)0)
3191 ti
->arg4
= kd
->arg1
; /* top half address */
3192 ti
->arg5
= kd
->arg2
; /* top half size */
3194 case BSC_pread_extended
:
3195 if ((ti
= find_event(thread
, BSC_pread
)) == (struct th_info
*)0) {
3196 if ((ti
= find_event(thread
, BSC_pread_nocancel
)) == (struct th_info
*)0)
3199 ti
->arg1
= kd
->arg1
; /* the fd */
3200 ti
->arg2
= kd
->arg2
; /* nbytes */
3201 ti
->arg3
= kd
->arg3
; /* top half offset */
3202 ti
->arg4
= kd
->arg4
; /* bottom half offset */
3204 case BSC_pwrite_extended
:
3205 if ((ti
= find_event(thread
, BSC_pwrite
)) == (struct th_info
*)0) {
3206 if ((ti
= find_event(thread
, BSC_pwrite_nocancel
)) == (struct th_info
*)0)
3209 ti
->arg1
= kd
->arg1
; /* the fd */
3210 ti
->arg2
= kd
->arg2
; /* nbytes */
3211 ti
->arg3
= kd
->arg3
; /* top half offset */
3212 ti
->arg4
= kd
->arg4
; /* bottom half offset */
3221 exit_event(char *sc_name
, uintptr_t thread
, int type
, uintptr_t arg1
, uintptr_t arg2
, uintptr_t arg3
, uintptr_t arg4
,
3222 int format
, double now
)
3226 if ((ti
= find_event(thread
, type
)) == (struct th_info
*)0)
3231 if (check_filter_mode(ti
, type
, arg1
, arg2
, sc_name
))
3232 format_print(ti
, sc_name
, thread
, type
, arg1
, arg2
, arg3
, arg4
, format
, now
, ti
->stime
, ti
->waited
, (char *)&ti
->lookups
[0].pathname
[0], NULL
);
3237 ti
->in_hfs_update
= 0;
3240 if ((type
& CLASS_MASK
) == FILEMGR_BASE
) {
3243 if (filemgr_in_progress
> 0)
3244 filemgr_in_progress
--;
3251 get_mode_nibble(char * buf
, int smode
, int special
, char x_on
, char x_off
)
3270 get_mode_string(int mode
, char *buf
)
3272 memset(buf
, '-', 9);
3275 get_mode_nibble(&buf
[6], mode
, (mode
& 01000), 't', 'T');
3276 get_mode_nibble(&buf
[3], (mode
>>3), (mode
& 02000), 's', 'S');
3277 get_mode_nibble(&buf
[0], (mode
>>6), (mode
& 04000), 's', 'S');
3281 int clip_64bit(char *s
, uint64_t value
)
3285 if ( (value
& 0xff00000000000000LL
) )
3286 clen
= printf("%s0x%16.16qx", s
, value
);
3287 else if ( (value
& 0x00ff000000000000LL
) )
3288 clen
= printf("%s0x%14.14qx ", s
, value
);
3289 else if ( (value
& 0x0000ff0000000000LL
) )
3290 clen
= printf("%s0x%12.12qx ", s
, value
);
3291 else if ( (value
& 0x000000ff00000000LL
) )
3292 clen
= printf("%s0x%10.10qx ", s
, value
);
3294 clen
= printf("%s0x%8.8qx ", s
, value
);
3301 format_print(struct th_info
*ti
, char *sc_name
, uintptr_t thread
, int type
, uintptr_t arg1
, uintptr_t arg2
, uintptr_t arg3
, uintptr_t arg4
,
3302 int format
, double now
, double stime
, int waited
, char *pathname
, struct diskio
*dio
)
3317 char *framework_name
;
3318 char *framework_type
;
3322 char cs_diskname
[32];
3324 static char timestamp
[32];
3325 static int last_timestamp
= -1;
3326 static int timestamp_len
= 0;
3331 l_usecs
= (long long)((now
- bias_now
) / divisor
);
3333 if ((double)l_usecs
< start_time
|| (double)l_usecs
> end_time
)
3336 l_usecs
+= (sample_TOD_secs
* 1000000) + sample_TOD_usecs
;
3339 l_usecs
= (long long)(now
/ divisor
);
3340 secs
= l_usecs
/ 1000000;
3341 curr_time
= bias_secs
+ secs
;
3346 command_name
= dio
->issuing_command
;
3350 if ((tme
= find_map_entry(thread
)))
3351 command_name
= tme
->tm_command
;
3353 if (last_timestamp
!= curr_time
) {
3354 timestamp_len
= sprintf(timestamp
, "%-8.8s", &(ctime(&curr_time
)[11]));
3355 last_timestamp
= curr_time
;
3357 if (columns
> MAXCOLS
|| wideflag
) {
3360 tlen
= timestamp_len
;
3362 usec
= (l_usecs
- (long long)((long long)secs
* 1000000));
3364 sprintf(×tamp
[tlen
], ".%06ld", (long)usec
);
3367 timestamp
[tlen
] = '\0';
3369 if (filemgr_in_progress
) {
3370 if (class != FILEMGR_CLASS
) {
3371 if (find_event(thread
, -1))
3378 if ((class == FILEMGR_CLASS
) && (columns
> MAXCOLS
|| wideflag
))
3379 clen
= printf("%s %-20.20s", timestamp
, sc_name
);
3380 else if (in_filemgr
)
3381 clen
= printf("%s %-15.15s", timestamp
, sc_name
);
3383 clen
= printf("%s %-17.17s", timestamp
, sc_name
);
3386 framework_name
= NULL
;
3388 if (columns
> MAXCOLS
|| wideflag
) {
3390 off_t offset_reassembled
= 0LL;
3398 * pathname based system calls or
3399 * calls with no fd or pathname (i.e. sync)
3402 clen
+= printf(" [%3d] ", arg1
);
3404 clen
+= printf(" ");
3409 * fd based system call... no I/O
3412 clen
+= printf(" F=%-3d[%3d]", ti
->arg1
, arg1
);
3414 clen
+= printf(" F=%-3d", ti
->arg1
);
3422 clen
+= printf(" F=%-3d[%3d]", ti
->arg1
, arg1
);
3424 clen
+= printf(" F=%-3d F=%-3d", ti
->arg1
, arg2
);
3429 * system calls with fd's that return an I/O completion count
3432 clen
+= printf(" F=%-3d[%3d]", ti
->arg1
, arg1
);
3434 clen
+= printf(" F=%-3d B=0x%-6x", ti
->arg1
, arg2
);
3441 user_addr
= ((uint64_t)arg2
<< 32) | (uint32_t)arg3
;
3443 lookup_name(user_addr
, &framework_type
, &framework_name
);
3444 clen
+= clip_64bit(" A=", user_addr
);
3451 user_addr
= ((uint64_t)arg2
<< 32) | (uint32_t)arg3
;
3453 lookup_name(user_addr
, &framework_type
, &framework_name
);
3454 clen
+= clip_64bit(" A=", user_addr
);
3461 clen
+= printf(" B=0x%-8x", arg2
);
3464 case FMT_HFS_update
:
3467 int sflag
= (int)arg2
;
3469 memset(sbuf
, '_', 6);
3486 clen
+= printf(" (%s) ", sbuf
);
3488 pathname
= find_vnode_name(arg1
);
3499 clen
+= printf(" D=0x%8.8x [%3d]", dio
->blkno
, dio
->io_errno
);
3502 clen
+= printf(" D=0x%8.8x B=0x%-6x BC:%s /dev/%s ", dio
->blkno
, dio
->iosize
, BC_STR(dio
->bc_info
), find_disk_name(dio
->dev
));
3504 clen
+= printf(" D=0x%8.8x B=0x%-6x /dev/%s ", dio
->blkno
, dio
->iosize
, find_disk_name(dio
->dev
));
3507 if (!(type
& P_DISKIO_READ
))
3508 pathname
= find_meta_name(dio
->blkno
);
3510 pathname
= find_vnode_name(dio
->vnodeid
);
3520 clen
+= printf(" D=0x%8.8x [%3d]", dio
->blkno
, dio
->io_errno
);
3522 clen
+= printf(" D=0x%8.8x B=0x%-6x /dev/%s", dio
->blkno
, dio
->iosize
, generate_cs_disk_name(dio
->dev
, &cs_diskname
[0]));
3525 case FMT_SYNC_DISK_CS
:
3527 * physical disk sync cache
3529 clen
+= printf(" /dev/%s", generate_cs_disk_name(arg1
, &cs_diskname
[0]));
3542 if (ti
->arg3
& MS_ASYNC
)
3543 mlen
+= sprintf(&buf
[mlen
], "MS_ASYNC | ");
3545 mlen
+= sprintf(&buf
[mlen
], "MS_SYNC | ");
3547 if (ti
->arg3
& MS_INVALIDATE
)
3548 mlen
+= sprintf(&buf
[mlen
], "MS_INVALIDATE | ");
3549 if (ti
->arg3
& MS_KILLPAGES
)
3550 mlen
+= sprintf(&buf
[mlen
], "MS_KILLPAGES | ");
3551 if (ti
->arg3
& MS_DEACTIVATE
)
3552 mlen
+= sprintf(&buf
[mlen
], "MS_DEACTIVATE | ");
3554 if (ti
->arg3
& ~(MS_ASYNC
| MS_SYNC
| MS_INVALIDATE
| MS_KILLPAGES
| MS_DEACTIVATE
))
3555 mlen
+= sprintf(&buf
[mlen
], "UNKNOWN | ");
3558 buf
[mlen
- 3] = '\0';
3561 clen
+= printf(" [%3d]", arg1
);
3563 user_addr
= (((off_t
)(unsigned int)(ti
->arg4
)) << 32) | (unsigned int)(ti
->arg1
);
3564 clen
+= clip_64bit(" A=", user_addr
);
3566 user_size
= (((off_t
)(unsigned int)(ti
->arg5
)) << 32) | (unsigned int)(ti
->arg2
);
3568 clen
+= printf(" B=0x%-16qx <%s>", user_size
, buf
);
3582 if (ti
->arg2
& LOCK_SH
)
3583 mlen
+= sprintf(&buf
[mlen
], "LOCK_SH | ");
3584 if (ti
->arg2
& LOCK_EX
)
3585 mlen
+= sprintf(&buf
[mlen
], "LOCK_EX | ");
3586 if (ti
->arg2
& LOCK_NB
)
3587 mlen
+= sprintf(&buf
[mlen
], "LOCK_NB | ");
3588 if (ti
->arg2
& LOCK_UN
)
3589 mlen
+= sprintf(&buf
[mlen
], "LOCK_UN | ");
3591 if (ti
->arg2
& ~(LOCK_SH
| LOCK_EX
| LOCK_NB
| LOCK_UN
))
3592 mlen
+= sprintf(&buf
[mlen
], "UNKNOWN | ");
3595 buf
[mlen
- 3] = '\0';
3598 clen
+= printf(" F=%-3d[%3d] <%s>", ti
->arg1
, arg1
, buf
);
3600 clen
+= printf(" F=%-3d <%s>", ti
->arg1
, buf
);
3614 clen
+= printf(" F=%-3d[%3d]", ti
->arg1
, arg1
);
3616 clen
+= printf(" F=%-3d", ti
->arg1
);
3680 case F_PATHPKG_CHECK
:
3681 p
= "PATHPKG_CHECK";
3695 case F_CHECK_OPENEVT
:
3696 p
= "CHECK_OPENEVT";
3706 case F_GLOBAL_NOCACHE
:
3708 p
= "CACHING OFF (GLOBAL)";
3710 p
= "CACHING ON (GLOBAL)";
3716 clen
+= printf(" <%s>", p
);
3718 clen
+= printf(" <%s> F=%d", p
, fd
);
3720 clen
+= printf(" <CMD=%d>", ti
->arg2
);
3731 clen
+= printf(" F=%-3d[%3d]", ti
->arg1
, arg1
);
3733 clen
+= printf(" F=%-3d", ti
->arg1
);
3735 clen
+= printf(" <CMD=0x%x>", ti
->arg2
);
3740 case FMT_IOCTL_SYNC
:
3745 clen
+= printf(" <DKIOCSYNCHRONIZECACHE> /dev/%s", find_disk_name(arg1
));
3750 case FMT_IOCTL_UNMAP
:
3755 clen
+= printf(" <DKIOCUNMAP> /dev/%s", find_disk_name(arg1
));
3760 case FMT_UNMAP_INFO
:
3762 clen
+= printf(" D=0x%8.8x B=0x%-6x /dev/%s", arg2
, arg3
, find_disk_name(arg1
));
3772 clen
+= printf(" [%3d]", arg1
);
3774 clen
+= printf(" S=%-3d", arg2
);
3781 * pread, pwrite, lseek
3783 clen
+= printf(" F=%-3d", ti
->arg1
);
3786 clen
+= printf("[%3d] ", arg1
);
3788 if (format
== FMT_PREAD
)
3789 clen
+= printf(" B=0x%-8x ", arg2
);
3791 clen
+= printf(" ");
3793 if (format
== FMT_PREAD
)
3794 offset_reassembled
= (((off_t
)(unsigned int)(ti
->arg3
)) << 32) | (unsigned int)(ti
->arg4
);
3797 offset_reassembled
= (((off_t
)(unsigned int)(arg2
)) << 32) | (unsigned int)(arg3
);
3799 offset_reassembled
= (((off_t
)(unsigned int)(arg3
)) << 32) | (unsigned int)(arg2
);
3801 clen
+= clip_64bit("O=", offset_reassembled
);
3803 if (format
== FMT_LSEEK
) {
3806 if (ti
->arg4
== SEEK_SET
)
3808 else if (ti
->arg4
== SEEK_CUR
)
3810 else if (ti
->arg4
== SEEK_END
)
3815 clen
+= printf(" <%s>", mode
);
3823 clen
+= printf(" F=%-3d ", ti
->arg1
);
3826 clen
+= printf("[%3d] ", arg1
);
3829 user_addr
= (((off_t
)(unsigned int)(ti
->arg2
)) << 32) | (unsigned int)(ti
->arg3
);
3831 clen
+= clip_64bit("A=", user_addr
);
3833 offset_reassembled
= (((off_t
)(unsigned int)(ti
->arg6
)) << 32) | (unsigned int)(ti
->arg7
);
3835 clen
+= clip_64bit("O=", offset_reassembled
);
3837 user_size
= (((off_t
)(unsigned int)(ti
->arg4
)) << 32) | (unsigned int)(ti
->arg5
);
3839 clen
+= printf("B=0x%-16qx", user_size
);
3841 clen
+= printf(" <");
3843 if (ti
->arg8
& PROT_READ
)
3844 clen
+= printf("READ");
3846 if (ti
->arg8
& PROT_WRITE
)
3847 clen
+= printf("|WRITE");
3849 if (ti
->arg8
& PROT_EXEC
)
3850 clen
+= printf("|EXEC");
3852 clen
+= printf(">");
3859 * ftruncate, truncate
3861 if (format
== FMT_FTRUNC
)
3862 clen
+= printf(" F=%-3d", ti
->arg1
);
3864 clen
+= printf(" ");
3867 clen
+= printf("[%3d]", arg1
);
3870 offset_reassembled
= (((off_t
)(unsigned int)(ti
->arg2
)) << 32) | (unsigned int)(ti
->arg3
);
3872 offset_reassembled
= (((off_t
)(unsigned int)(ti
->arg3
)) << 32) | (unsigned int)(ti
->arg2
);
3874 clen
+= clip_64bit(" O=", offset_reassembled
);
3887 if (format
== FMT_FCHFLAGS
) {
3889 clen
+= printf(" F=%-3d[%3d]", ti
->arg1
, arg1
);
3891 clen
+= printf(" F=%-3d", ti
->arg1
);
3894 clen
+= printf(" [%3d] ", arg1
);
3899 if (ti
->arg2
& UF_NODUMP
)
3900 mlen
+= sprintf(&buf
[mlen
], "UF_NODUMP | ");
3901 if (ti
->arg2
& UF_IMMUTABLE
)
3902 mlen
+= sprintf(&buf
[mlen
], "UF_IMMUTABLE | ");
3903 if (ti
->arg2
& UF_APPEND
)
3904 mlen
+= sprintf(&buf
[mlen
], "UF_APPEND | ");
3905 if (ti
->arg2
& UF_OPAQUE
)
3906 mlen
+= sprintf(&buf
[mlen
], "UF_OPAQUE | ");
3907 if (ti
->arg2
& SF_ARCHIVED
)
3908 mlen
+= sprintf(&buf
[mlen
], "SF_ARCHIVED | ");
3909 if (ti
->arg2
& SF_IMMUTABLE
)
3910 mlen
+= sprintf(&buf
[mlen
], "SF_IMMUTABLE | ");
3911 if (ti
->arg2
& SF_APPEND
)
3912 mlen
+= sprintf(&buf
[mlen
], "SF_APPEND | ");
3915 mlen
+= sprintf(&buf
[mlen
], "CLEAR_ALL_FLAGS | ");
3916 else if (ti
->arg2
& ~(UF_NODUMP
| UF_IMMUTABLE
| UF_APPEND
| SF_ARCHIVED
| SF_IMMUTABLE
| SF_APPEND
))
3917 mlen
+= sprintf(&buf
[mlen
], "UNKNOWN | ");
3926 memset(&buf
[mlen
], ' ', 19 - mlen
);
3929 clen
+= printf("%s", buf
);
3937 case FMT_FCHMOD_EXT
:
3943 * fchmod, fchmod_extended, chmod, chmod_extended
3947 if (format
== FMT_FCHMOD
|| format
== FMT_FCHMOD_EXT
) {
3949 clen
+= printf(" F=%-3d[%3d] ", ti
->arg1
, arg1
);
3951 clen
+= printf(" F=%-3d ", ti
->arg1
);
3954 clen
+= printf(" [%3d] ", arg1
);
3956 clen
+= printf(" ");
3958 if (format
== FMT_UMASK
)
3960 else if (format
== FMT_FCHMOD
|| format
== FMT_CHMOD
|| format
== FMT_CHMODAT
)
3965 get_mode_string(mode
, &buf
[0]);
3968 clen
+= printf("<%s> ", buf
);
3970 clen
+= printf("<%s>", buf
);
3981 memset(mode
, '_', 4);
3984 if (ti
->arg2
& R_OK
)
3986 if (ti
->arg2
& W_OK
)
3988 if (ti
->arg2
& X_OK
)
3990 if (ti
->arg2
== F_OK
)
3994 clen
+= printf(" [%3d] (%s) ", arg1
, mode
);
3996 clen
+= printf(" (%s) ", mode
);
4005 clen
+= printf(" [%3d] <FLGS=0x%x> ", arg1
, ti
->arg3
);
4007 clen
+= printf(" <FLGS=0x%x> ", ti
->arg3
);
4017 if (ti
->arg2
& MNT_FORCE
)
4018 mountflag
= "<FORCE>";
4023 clen
+= printf(" [%3d] %s ", arg1
, mountflag
);
4025 clen
+= printf(" %s ", mountflag
);
4039 memset(mode
, '_', 6);
4042 if (ti
->arg2
& O_RDWR
) {
4045 } else if (ti
->arg2
& O_WRONLY
)
4050 if (ti
->arg2
& O_CREAT
)
4053 if (ti
->arg2
& O_APPEND
)
4056 if (ti
->arg2
& O_TRUNC
)
4059 if (ti
->arg2
& O_EXCL
)
4063 clen
+= printf(" [%3d] (%s) ", arg1
, mode
);
4065 clen
+= printf(" F=%-3d (%s) ", arg2
, mode
);
4099 domain
= "AF_IMPLINK";
4110 type
= "SOCK_STREAM";
4114 type
= "SOCK_DGRAM";
4121 case SOCK_SEQPACKET
:
4122 type
= "SOCK_SEQPACKET";
4135 clen
+= printf(" [%3d] <%s, %s, 0x%x>", arg1
, domain
, type
, ti
->arg3
);
4137 clen
+= printf(" F=%-3d <%s, %s, 0x%x>", arg2
, domain
, type
, ti
->arg3
);
4144 * aio_fsync [errno] AIOCBP OP
4148 if (ti
->arg1
== O_SYNC
|| ti
->arg1
== 0)
4151 else if (ti
->arg1
== O_DSYNC
)
4158 clen
+= printf(" [%3d] P=0x%8.8x <%s>", arg1
, ti
->arg2
, op
);
4160 clen
+= printf(" P=0x%8.8x <%s>", ti
->arg2
, op
);
4164 case FMT_AIO_RETURN
:
4166 * aio_return [errno] AIOCBP IOSIZE
4169 clen
+= printf(" [%3d] P=0x%8.8x", arg1
, ti
->arg1
);
4171 clen
+= printf(" P=0x%8.8x B=0x%-8x", ti
->arg1
, arg2
);
4174 case FMT_AIO_SUSPEND
:
4176 * aio_suspend [errno] NENTS
4179 clen
+= printf(" [%3d] N=%d", arg1
, ti
->arg2
);
4181 clen
+= printf(" N=%d", ti
->arg2
);
4184 case FMT_AIO_CANCEL
:
4186 * aio_cancel [errno] FD or AIOCBP (if non-null)
4190 clen
+= printf(" [%3d] P=0x%8.8x", arg1
, ti
->arg2
);
4192 clen
+= printf(" P=0x%8.8x", ti
->arg2
);
4195 clen
+= printf(" F=%-3d[%3d]", ti
->arg1
, arg1
);
4197 clen
+= printf(" F=%-3d", ti
->arg1
);
4203 * aio_error, aio_read, aio_write [errno] AIOCBP
4206 clen
+= printf(" [%3d] P=0x%8.8x", arg1
, ti
->arg1
);
4208 clen
+= printf(" P=0x%8.8x", ti
->arg1
);
4211 case FMT_LIO_LISTIO
:
4214 * lio_listio [errno] NENTS MODE
4218 if (ti
->arg1
== LIO_NOWAIT
)
4220 else if (ti
->arg1
== LIO_WAIT
)
4226 clen
+= printf(" [%3d] N=%d <%s>", arg1
, ti
->arg3
, op
);
4228 clen
+= printf(" N=%d <%s>", ti
->arg3
, op
);
4236 * Calculate space available to print pathname
4238 if (columns
> MAXCOLS
|| wideflag
)
4239 clen
= columns
- (clen
+ 14 + 20 + 11);
4241 clen
= columns
- (clen
+ 14 + 12);
4243 if (class != FILEMGR_CLASS
&& !nopadding
)
4247 len
= sprintf(&buf
[0], " %s %s ", framework_type
, framework_name
);
4248 else if (*pathname
!= '\0') {
4253 len
= sprintf(&buf
[0], " [%d]/%s ", ti
->arg1
, pathname
);
4256 len
= sprintf(&buf
[0], " [%d]/%s ", ti
->arg3
, pathname
);
4259 len
= sprintf(&buf
[0], " %s ", pathname
);
4262 if (format
== FMT_MOUNT
&& ti
->lookups
[1].pathname
[0]) {
4265 memset(&buf
[len
], ' ', 2);
4267 len2
= sprintf(&buf
[len
+2], " %s ", (char *)&ti
->lookups
[1].pathname
[0]);
4268 len
= len
+ 2 + len2
;
4275 * Add null padding if column length
4276 * is wider than the pathname length.
4278 memset(&buf
[len
], ' ', clen
- len
);
4283 } else if (clen
== len
) {
4286 } else if ((clen
> 0) && (clen
< len
)) {
4288 * This prints the tail end of the pathname
4290 buf
[len
-clen
] = ' ';
4292 pathname
= &buf
[len
- clen
];
4299 * fudge some additional system call overhead
4300 * that currently isn't tracked... this also
4301 * insures that we see a minimum of 1 us for
4304 usecs
= (unsigned long)(((now
- stime
) + (divisor
-1)) / divisor
);
4305 secs
= usecs
/ 1000000;
4306 usecs
-= secs
* 1000000;
4308 if (class != FILEMGR_CLASS
&& !nopadding
)
4318 if (columns
> MAXCOLS
|| wideflag
)
4319 printf("%s%s %3ld.%06ld%s %s.%d\n", p1
, pathname
, (unsigned long)secs
, (unsigned long)usecs
, p2
, command_name
, (int)thread
);
4321 printf("%s%s %3ld.%06ld%s %-12.12s\n", p1
, pathname
, (unsigned long)secs
, (unsigned long)usecs
, p2
, command_name
);
4326 add_meta_name(uint64_t blockno
, char *pathname
) {
4330 hashid
= blockno
& VN_HASH_MASK
;
4332 for (mi
= m_info_hash
[hashid
]; mi
; mi
= mi
->m_next
) {
4333 if (mi
->m_blkno
== blockno
)
4337 mi
= (meta_info_t
)malloc(sizeof(struct meta_info
));
4339 mi
->m_next
= m_info_hash
[hashid
];
4340 m_info_hash
[hashid
] = mi
;
4341 mi
->m_blkno
= blockno
;
4343 mi
->m_nameptr
= pathname
;
4347 find_meta_name(uint64_t blockno
) {
4351 hashid
= blockno
& VN_HASH_MASK
;
4353 for (mi
= m_info_hash
[hashid
]; mi
; mi
= mi
->m_next
) {
4354 if (mi
->m_blkno
== blockno
)
4355 return (mi
->m_nameptr
);
4362 add_vnode_name(uint64_t vn_id
, char *pathname
) {
4366 hashid
= (vn_id
>> VN_HASH_SHIFT
) & VN_HASH_MASK
;
4368 for (vn
= vn_info_hash
[hashid
]; vn
; vn
= vn
->vn_next
) {
4369 if (vn
->vn_id
== vn_id
)
4373 vn
= (vnode_info_t
)malloc(sizeof(struct vnode_info
));
4375 vn
->vn_next
= vn_info_hash
[hashid
];
4376 vn_info_hash
[hashid
] = vn
;
4379 strcpy(vn
->vn_pathname
, pathname
);
4381 return (&vn
->vn_pathname
);
4386 find_vnode_name(uint64_t vn_id
) {
4390 hashid
= (vn_id
>> VN_HASH_SHIFT
) & VN_HASH_MASK
;
4392 for (vn
= vn_info_hash
[hashid
]; vn
; vn
= vn
->vn_next
) {
4393 if (vn
->vn_id
== vn_id
)
4394 return (vn
->vn_pathname
);
4401 delete_event(th_info_t ti_to_delete
) {
4406 hashid
= ti_to_delete
->thread
& HASH_MASK
;
4408 if ((ti
= th_info_hash
[hashid
])) {
4409 if (ti
== ti_to_delete
)
4410 th_info_hash
[hashid
] = ti
->next
;
4414 for (ti
= ti
->next
; ti
; ti
= ti
->next
) {
4415 if (ti
== ti_to_delete
) {
4416 ti_prev
->next
= ti
->next
;
4423 ti
->next
= th_info_freelist
;
4424 th_info_freelist
= ti
;
4430 add_event(uintptr_t thread
, int type
) {
4435 if ((ti
= th_info_freelist
))
4436 th_info_freelist
= ti
->next
;
4438 ti
= (th_info_t
)malloc(sizeof(struct th_info
));
4440 hashid
= thread
& HASH_MASK
;
4442 ti
->next
= th_info_hash
[hashid
];
4443 th_info_hash
[hashid
] = ti
;
4445 ti
->thread
= thread
;
4450 ti
->in_hfs_update
= 0;
4452 ti
->pathptr
= &ti
->lookups
[0].pathname
[0];
4453 ti
->pn_scall_index
= 0;
4454 ti
->pn_work_index
= 0;
4456 for (i
= 0; i
< MAX_PATHNAMES
; i
++)
4457 ti
->lookups
[i
].pathname
[0] = 0;
4463 find_event(uintptr_t thread
, int type
) {
4467 hashid
= thread
& HASH_MASK
;
4469 for (ti
= th_info_hash
[hashid
]; ti
; ti
= ti
->next
) {
4470 if (ti
->thread
== thread
) {
4471 if (type
== ti
->type
)
4473 if (ti
->in_filemgr
) {
4482 return ((th_info_t
) 0);
4486 delete_all_events() {
4488 th_info_t ti_next
= 0;
4491 for (i
= 0; i
< HASH_SIZE
; i
++) {
4493 for (ti
= th_info_hash
[i
]; ti
; ti
= ti_next
) {
4495 ti
->next
= th_info_freelist
;
4496 th_info_freelist
= ti
;
4498 th_info_hash
[i
] = 0;
4504 mark_thread_waited(uintptr_t thread
) {
4508 hashid
= thread
& HASH_MASK
;
4510 for (ti
= th_info_hash
[hashid
]; ti
; ti
= ti
->next
) {
4511 if (ti
->thread
== thread
)
4517 void read_command_map()
4521 int total_threads
= 0;
4522 kd_threadmap
*mapptr
= 0;
4524 delete_all_map_entries();
4528 total_threads
= bufinfo
.nkdthreads
;
4529 size
= bufinfo
.nkdthreads
* sizeof(kd_threadmap
);
4532 if ((mapptr
= (kd_threadmap
*) malloc(size
))) {
4535 bzero (mapptr
, size
);
4537 * Now read the threadmap
4540 mib
[1] = KERN_KDEBUG
;
4541 mib
[2] = KERN_KDTHRMAP
;
4544 mib
[5] = 0; /* no flags */
4546 if (sysctl(mib
, 3, mapptr
, &size
, NULL
, 0) < 0) {
4548 * This is not fatal -- just means I cant map command strings
4559 RAW_fd
= open(RAW_file
, O_RDONLY
);
4562 perror("Can't open RAW file");
4565 if (read(RAW_fd
, &header
, sizeof(RAW_header
)) != sizeof(RAW_header
)) {
4566 perror("read failed");
4569 if (header
.version_no
!= RAW_VERSION1
) {
4570 header
.version_no
= RAW_VERSION0
;
4571 header
.TOD_secs
= time((long *)0);
4572 header
.TOD_usecs
= 0;
4574 lseek(RAW_fd
, (off_t
)0, SEEK_SET
);
4576 if (read(RAW_fd
, &header
.thread_count
, sizeof(int)) != sizeof(int)) {
4577 perror("read failed");
4581 sample_TOD_secs
= header
.TOD_secs
;
4582 sample_TOD_usecs
= header
.TOD_usecs
;
4584 total_threads
= header
.thread_count
;
4585 size
= total_threads
* sizeof(kd_threadmap
);
4588 if ((mapptr
= (kd_threadmap
*) malloc(size
))) {
4589 bzero (mapptr
, size
);
4591 if (read(RAW_fd
, mapptr
, size
) != size
) {
4597 if (header
.version_no
!= RAW_VERSION0
) {
4598 offset
= lseek(RAW_fd
, (off_t
)0, SEEK_CUR
);
4599 offset
= (offset
+ (4095)) & ~4095;
4601 lseek(RAW_fd
, offset
, SEEK_SET
);
4604 for (i
= 0; i
< total_threads
; i
++)
4605 create_map_entry(mapptr
[i
].thread
, mapptr
[i
].valid
, &mapptr
[i
].command
[0]);
4611 void delete_all_map_entries()
4613 threadmap_t tme
= 0;
4614 threadmap_t tme_next
= 0;
4617 for (i
= 0; i
< HASH_SIZE
; i
++) {
4619 for (tme
= threadmap_hash
[i
]; tme
; tme
= tme_next
) {
4621 free(tme
->tm_setptr
);
4622 tme_next
= tme
->tm_next
;
4623 tme
->tm_next
= threadmap_freelist
;
4624 threadmap_freelist
= tme
;
4626 threadmap_hash
[i
] = 0;
4631 void create_map_entry(uintptr_t thread
, int pid
, char *command
)
4636 if ((tme
= threadmap_freelist
))
4637 threadmap_freelist
= tme
->tm_next
;
4639 tme
= (threadmap_t
)malloc(sizeof(struct threadmap
));
4641 tme
->tm_thread
= thread
;
4642 tme
->tm_setsize
= 0;
4645 (void)strncpy (tme
->tm_command
, command
, MAXCOMLEN
);
4646 tme
->tm_command
[MAXCOMLEN
] = '\0';
4648 hashid
= thread
& HASH_MASK
;
4650 tme
->tm_next
= threadmap_hash
[hashid
];
4651 threadmap_hash
[hashid
] = tme
;
4653 if (pid
!= 0 && pid
!= 1) {
4654 if (!strncmp(command
, "LaunchCFMA", 10))
4655 (void)get_real_command_name(pid
, tme
->tm_command
, MAXCOMLEN
);
4661 find_map_entry(uintptr_t thread
)
4666 hashid
= thread
& HASH_MASK
;
4668 for (tme
= threadmap_hash
[hashid
]; tme
; tme
= tme
->tm_next
) {
4669 if (tme
->tm_thread
== thread
)
4677 delete_map_entry(uintptr_t thread
)
4679 threadmap_t tme
= 0;
4680 threadmap_t tme_prev
;
4683 hashid
= thread
& HASH_MASK
;
4685 if ((tme
= threadmap_hash
[hashid
])) {
4686 if (tme
->tm_thread
== thread
)
4687 threadmap_hash
[hashid
] = tme
->tm_next
;
4691 for (tme
= tme
->tm_next
; tme
; tme
= tme
->tm_next
) {
4692 if (tme
->tm_thread
== thread
) {
4693 tme_prev
->tm_next
= tme
->tm_next
;
4701 free(tme
->tm_setptr
);
4703 tme
->tm_next
= threadmap_freelist
;
4704 threadmap_freelist
= tme
;
4711 fs_usage_fd_set(uintptr_t thread
, unsigned int fd
)
4715 if ((tme
= find_map_entry(thread
)) == 0)
4718 * If the map is not allocated, then now is the time
4720 if (tme
->tm_setptr
== (unsigned long *)0) {
4721 if ((tme
->tm_setptr
= (unsigned long *)malloc(FS_USAGE_NFDBYTES(FS_USAGE_FD_SETSIZE
))) == 0)
4724 tme
->tm_setsize
= FS_USAGE_FD_SETSIZE
;
4725 bzero(tme
->tm_setptr
, (FS_USAGE_NFDBYTES(FS_USAGE_FD_SETSIZE
)));
4728 * If the map is not big enough, then reallocate it
4730 while (tme
->tm_setsize
<= fd
) {
4733 n
= tme
->tm_setsize
* 2;
4734 tme
->tm_setptr
= (unsigned long *)realloc(tme
->tm_setptr
, (FS_USAGE_NFDBYTES(n
)));
4736 bzero(&tme
->tm_setptr
[(tme
->tm_setsize
/FS_USAGE_NFDBITS
)], (FS_USAGE_NFDBYTES(tme
->tm_setsize
)));
4737 tme
->tm_setsize
= n
;
4742 tme
->tm_setptr
[fd
/FS_USAGE_NFDBITS
] |= (1 << ((fd
) % FS_USAGE_NFDBITS
));
4748 * 0 : File Descriptor bit is not set
4749 * 1 : File Descriptor bit is set
4752 fs_usage_fd_isset(uintptr_t thread
, unsigned int fd
)
4757 if ((tme
= find_map_entry(thread
))) {
4758 if (tme
->tm_setptr
&& fd
< tme
->tm_setsize
)
4759 ret
= tme
->tm_setptr
[fd
/FS_USAGE_NFDBITS
] & (1 << (fd
% FS_USAGE_NFDBITS
));
4766 fs_usage_fd_clear(uintptr_t thread
, unsigned int fd
)
4770 if ((tme
= find_map_entry(thread
))) {
4771 if (tme
->tm_setptr
&& fd
< tme
->tm_setsize
)
4772 tme
->tm_setptr
[fd
/FS_USAGE_NFDBITS
] &= ~(1 << (fd
% FS_USAGE_NFDBITS
));
4785 ret
= (int)strtol(str
, &cp
, 10);
4787 if (cp
== str
|| *cp
) {
4789 * Assume this is a command string and find matching pids
4794 for (i
= 0; i
< kp_nentries
&& num_of_pids
< (MAX_PIDS
- 1); i
++) {
4795 if (kp_buffer
[i
].kp_proc
.p_stat
== 0)
4798 if (!strncmp(str
, kp_buffer
[i
].kp_proc
.p_comm
,
4799 sizeof(kp_buffer
[i
].kp_proc
.p_comm
) -1))
4800 pids
[num_of_pids
++] = kp_buffer
[i
].kp_proc
.p_pid
;
4804 else if (num_of_pids
< (MAX_PIDS
- 1))
4805 pids
[num_of_pids
++] = ret
;
4811 lookup_name(uint64_t user_addr
, char **type
, char **name
)
4819 if (numFrameworks
) {
4821 if ((user_addr
>= framework32
.b_address
&& user_addr
< framework32
.e_address
) ||
4822 (user_addr
>= framework64
.b_address
&& user_addr
< framework64
.e_address
)) {
4825 last
= numFrameworks
;
4827 for (i
= numFrameworks
/ 2; start
< last
; i
= start
+ ((last
- start
) / 2)) {
4828 if (user_addr
> frameworkInfo
[i
].e_address
)
4833 if (start
< numFrameworks
&&
4834 user_addr
>= frameworkInfo
[start
].b_address
&& user_addr
< frameworkInfo
[start
].e_address
) {
4835 *type
= frameworkType
[frameworkInfo
[start
].r_type
];
4836 *name
= frameworkInfo
[start
].name
;
4844 * Comparison routines for sorting
4846 static int compareFrameworkAddress(const void *aa
, const void *bb
)
4848 LibraryInfo
*a
= (LibraryInfo
*)aa
;
4849 LibraryInfo
*b
= (LibraryInfo
*)bb
;
4851 if (a
->b_address
< b
->b_address
) return -1;
4852 if (a
->b_address
== b
->b_address
) return 0;
4857 int scanline(char *inputstring
, char **argv
, int maxtokens
)
4860 char **ap
= argv
, *p
, *val
;
4862 for (p
= inputstring
; n
< maxtokens
&& p
!= NULL
; ) {
4864 while ((val
= strsep(&p
, " \t")) != NULL
&& *val
== '\0');
4875 int ReadSharedCacheMap(const char *path
, LibraryRange
*lr
, char *linkedit_name
)
4877 uint64_t b_address
, e_address
;
4881 char frameworkName
[256];
4885 int linkedit_found
= 0;
4886 char *substring
, *ptr
;
4888 bzero(buf
, sizeof(buf
));
4889 bzero(tokens
, sizeof(tokens
));
4894 if ((fd
= fopen(path
, "r")) == 0)
4897 while (fgets(buf
, 1023, fd
)) {
4898 if (strncmp(buf
, "mapping", 7))
4901 buf
[strlen(buf
)-1] = 0;
4903 frameworkName
[0] = 0;
4907 * Extract lib name from path name
4909 if ((substring
= strrchr(buf
, '.')))
4912 * There is a ".": name is whatever is between the "/" around the "."
4914 while ( *substring
!= '/') /* find "/" before "." */
4918 strncpy(frameworkName
, substring
, 256); /* copy path from "/" */
4919 frameworkName
[255] = 0;
4920 substring
= frameworkName
;
4922 while ( *substring
!= '/' && *substring
) /* find "/" after "." and stop string there */
4929 * No ".": take segment after last "/"
4936 substring
= ptr
+ 1;
4939 strncpy(frameworkName
, substring
, 256);
4940 frameworkName
[255] = 0;
4942 fnp
= (char *)malloc(strlen(frameworkName
) + 1);
4943 strcpy(fnp
, frameworkName
);
4945 while (fgets(buf
, 1023, fd
) && numFrameworks
< (MAXINDEX
- 2)) {
4949 buf
[strlen(buf
)-1] = 0;
4951 ntokens
= scanline(buf
, tokens
, 64);
4956 if (strncmp(tokens
[0], "__TEXT", 6) == 0)
4958 else if (strncmp(tokens
[0], "__DATA", 6) == 0)
4960 else if (strncmp(tokens
[0], "__OBJC", 6) == 0)
4962 else if (strncmp(tokens
[0], "__IMPORT", 8) == 0)
4964 else if (strncmp(tokens
[0], "__UNICODE", 9) == 0)
4966 else if (strncmp(tokens
[0], "__IMAGE", 7) == 0)
4968 else if (strncmp(tokens
[0], "__LINKEDIT", 10) == 0)
4973 if (type
== LINKEDIT_R
&& linkedit_found
)
4977 b_address
= strtoull(tokens
[1], 0, 16);
4978 e_address
= strtoull(tokens
[3], 0, 16);
4980 frameworkInfo
[numFrameworks
].b_address
= b_address
;
4981 frameworkInfo
[numFrameworks
].e_address
= e_address
;
4982 frameworkInfo
[numFrameworks
].r_type
= type
;
4984 if (type
== LINKEDIT_R
) {
4985 frameworkInfo
[numFrameworks
].name
= linkedit_name
;
4988 frameworkInfo
[numFrameworks
].name
= fnp
;
4990 printf("%s(%d): %qx-%qx\n", frameworkInfo
[numFrameworks
].name
, type
, b_address
, e_address
);
4992 if (lr
->b_address
== 0 || b_address
< lr
->b_address
)
4993 lr
->b_address
= b_address
;
4995 if (lr
->e_address
== 0 || e_address
> lr
->e_address
)
4996 lr
->e_address
= e_address
;
5000 if (type
== LINKEDIT_R
)
5003 if (fgets(buf
, 1023, fd
) == 0)
5006 buf
[strlen(buf
)-1] = 0;
5011 printf("%s range, %qx-%qx\n", path
, lr
->b_address
, lr
->e_address
);
5018 SortFrameworkAddresses()
5021 frameworkInfo
[numFrameworks
].b_address
= frameworkInfo
[numFrameworks
- 1].b_address
+ 0x800000;
5022 frameworkInfo
[numFrameworks
].e_address
= frameworkInfo
[numFrameworks
].b_address
;
5023 frameworkInfo
[numFrameworks
].name
= (char *)0;
5025 qsort(frameworkInfo
, numFrameworks
, sizeof(LibraryInfo
), compareFrameworkAddress
);
5029 struct diskio
*insert_diskio(int type
, int bp
, int dev
, int blkno
, int io_size
, uintptr_t thread
, double curtime
)
5034 if ((dio
= free_diskios
))
5035 free_diskios
= dio
->next
;
5037 if ((dio
= (struct diskio
*)malloc(sizeof(struct diskio
))) == NULL
)
5046 dio
->iosize
= io_size
;
5047 dio
->issued_time
= curtime
;
5048 dio
->issuing_thread
= thread
;
5052 if ((tme
= find_map_entry(thread
))) {
5053 strncpy(dio
->issuing_command
, tme
->tm_command
, MAXCOMLEN
);
5054 dio
->issuing_command
[MAXCOMLEN
] = '\0';
5056 strcpy(dio
->issuing_command
, "");
5058 dio
->next
= busy_diskios
;
5060 dio
->next
->prev
= dio
;
5066 struct diskio
*find_diskio(int bp
) {
5069 for (dio
= busy_diskios
; dio
; dio
= dio
->next
) {
5078 struct diskio
*complete_diskio(int bp
, int io_errno
, int resid
, uintptr_t thread
, double curtime
)
5082 if ((dio
= find_diskio(bp
)) == NULL
) return NULL
;
5084 if (dio
== busy_diskios
) {
5085 if ((busy_diskios
= dio
->next
))
5086 dio
->next
->prev
= NULL
;
5089 dio
->next
->prev
= dio
->prev
;
5090 dio
->prev
->next
= dio
->next
;
5093 dio
->iosize
-= resid
;
5094 dio
->io_errno
= io_errno
;
5095 dio
->completed_time
= curtime
;
5096 dio
->completion_thread
= thread
;
5102 void free_diskio(struct diskio
*dio
)
5104 dio
->next
= free_diskios
;
5109 void print_diskio(struct diskio
*dio
)
5114 int format
= FMT_DISKIO
;
5120 if ((type
& P_CS_Class
) == P_CS_Class
) {
5124 case P_CS_ReadChunk
:
5127 format
= FMT_DISKIO_CS
;
5129 case P_CS_WriteChunk
:
5132 format
= FMT_DISKIO_CS
;
5137 format
= FMT_DISKIO_CS
;
5139 case P_CS_MetaWrite
:
5142 format
= FMT_DISKIO_CS
;
5144 case P_CS_TransformRead
:
5148 case P_CS_TransformWrite
:
5152 case P_CS_MigrationRead
:
5156 case P_CS_MigrationWrite
:
5161 strncpy(buf
, p
, len
);
5164 switch (type
& P_DISKIO_TYPE
) {
5197 strncpy(buf
, p
, len
);
5201 if (type
& P_DISKIO_ASYNC
)
5206 if (type
& P_DISKIO_NOCACHE
)
5209 int tier
= (type
& P_DISKIO_TIER_MASK
) >> P_DISKIO_TIER_SHIFT
;
5212 if (tier
> 0 && tier
< 10)
5213 buf
[len
++] = '0' + tier
;
5216 if (type
& P_DISKIO_PASSIVE
)
5224 if (check_filter_mode(NULL
, type
, 0, 0, buf
))
5225 format_print(NULL
, buf
, dio
->issuing_thread
, type
, 0, 0, 0, 0, format
, dio
->completed_time
, dio
->issued_time
, 1, "", dio
);
5229 void cache_disk_names()
5234 struct diskrec
*dnp
;
5237 if ((dirp
= opendir("/dev")) == NULL
)
5240 while ((dir
= readdir(dirp
)) != NULL
) {
5241 char nbuf
[MAXPATHLEN
];
5243 if (dir
->d_namlen
< 5 || strncmp("disk", dir
->d_name
, 4))
5246 snprintf(nbuf
, MAXPATHLEN
, "%s/%s", "/dev", dir
->d_name
);
5248 if (stat(nbuf
, &st
) < 0)
5251 if ((dnp
= (struct diskrec
*)malloc(sizeof(struct diskrec
))) == NULL
)
5254 if ((dnp
->diskname
= (char *)malloc(dir
->d_namlen
+ 1)) == NULL
) {
5258 strncpy(dnp
->diskname
, dir
->d_name
, dir
->d_namlen
);
5259 dnp
->diskname
[dir
->d_namlen
] = 0;
5260 dnp
->dev
= st
.st_rdev
;
5262 dnp
->next
= disk_list
;
5265 (void) closedir(dirp
);
5269 void recache_disk_names()
5271 struct diskrec
*dnp
, *next_dnp
;
5273 for (dnp
= disk_list
; dnp
; dnp
= next_dnp
) {
5274 next_dnp
= dnp
->next
;
5276 free(dnp
->diskname
);
5285 char *find_disk_name(int dev
)
5287 struct diskrec
*dnp
;
5296 for (i
= 0; i
< 2; i
++) {
5297 for (dnp
= disk_list
; dnp
; dnp
= dnp
->next
) {
5298 if (dnp
->dev
== dev
)
5299 return (dnp
->diskname
);
5301 recache_disk_names();
5303 return ("NOTFOUND");
5307 char *generate_cs_disk_name(int dev
, char *s
)
5312 sprintf(s
, "disk%ds%d", (dev
>> 16) & 0xffff, dev
& 0xffff);
5320 * ret = 1 means print the entry
5321 * ret = 0 means don't print the entry
5325 * meaning of filter flags:
5326 * cachehit turn on display of CACHE_HIT events (which are filtered out by default)
5328 * exec show exec/posix_spawn
5329 * pathname show events with a pathname and close()
5330 * diskio show disk I/Os
5331 * filesys show filesystem events
5332 * network show network events
5334 * filters may be combined; default is all filters on (except cachehit)
5337 check_filter_mode(struct th_info
*ti
, int type
, int error
, int retval
, char *sc_name
)
5340 int network_fd_isset
= 0;
5343 /* cachehit is special -- it's not on by default */
5344 if (sc_name
[0] == 'C' && !strcmp(sc_name
, "CACHE_HIT")) {
5345 if (show_cachehits
) return 1;
5349 if (filter_mode
== DEFAULT_DO_NOT_FILTER
)
5352 if (filter_mode
& DISKIO_FILTER
) {
5353 if ((type
& P_DISKIO_MASK
) == P_DISKIO
)
5357 if (filter_mode
& EXEC_FILTER
) {
5358 if (type
== BSC_execve
|| type
== BSC_posix_spawn
)
5362 if (filter_mode
& PATHNAME_FILTER
) {
5363 if (ti
&& ti
->lookups
[0].pathname
[0])
5365 if (type
== BSC_close
|| type
== BSC_close_nocancel
||
5366 type
== BSC_guarded_close_np
)
5370 if (ti
== (struct th_info
*)0) {
5371 if (filter_mode
& FILESYS_FILTER
)
5379 case BSC_close_nocancel
:
5380 case BSC_guarded_close_np
:
5382 network_fd_isset
= fs_usage_fd_isset(ti
->thread
, fd
);
5385 fs_usage_fd_clear(ti
->thread
,fd
);
5387 if (network_fd_isset
) {
5388 if (filter_mode
& NETWORK_FILTER
)
5391 if (filter_mode
& FILESYS_FILTER
)
5397 case BSC_read_nocancel
:
5398 case BSC_write_nocancel
:
5400 * we don't care about error in these cases
5403 network_fd_isset
= fs_usage_fd_isset(ti
->thread
, fd
);
5405 if (network_fd_isset
) {
5406 if (filter_mode
& NETWORK_FILTER
)
5409 if (filter_mode
& FILESYS_FILTER
)
5414 case BSC_accept_nocancel
:
5419 fs_usage_fd_set(ti
->thread
, fd
);
5420 if (filter_mode
& NETWORK_FILTER
)
5431 case BSC_sendto_nocancel
:
5432 case BSC_recvfrom_nocancel
:
5433 case BSC_recvmsg_nocancel
:
5434 case BSC_sendmsg_nocancel
:
5435 case BSC_connect_nocancel
:
5439 fs_usage_fd_set(ti
->thread
, fd
);
5440 if (filter_mode
& NETWORK_FILTER
)
5445 case BSC_select_nocancel
:
5446 case BSC_socketpair
:
5448 * Cannot determine info about file descriptors
5450 if (filter_mode
& NETWORK_FILTER
)
5457 * We track these cases for fd state only
5460 network_fd_isset
= fs_usage_fd_isset(ti
->thread
, fd
);
5462 if (error
== 0 && network_fd_isset
) {
5464 * then we are duping a socket descriptor
5466 fd
= retval
; /* the new fd */
5467 fs_usage_fd_set(ti
->thread
, fd
);
5472 if (filter_mode
& FILESYS_FILTER
)
5481 * Allocate a buffer that is large enough to hold the maximum arguments
5482 * to execve(). This is used when getting the arguments to programs
5483 * when we see LaunchCFMApps. If this fails, it is not fatal, we will
5484 * simply not resolve the command name.
5488 init_arguments_buffer()
5494 mib
[1] = KERN_ARGMAX
;
5495 size
= sizeof(argmax
);
5497 if (sysctl(mib
, 2, &argmax
, &size
, NULL
, 0) == -1)
5500 /* Hack to avoid kernel bug. */
5501 if (argmax
> 8192) {
5505 arguments
= (char *)malloc(argmax
);
5510 get_real_command_name(int pid
, char *cbuf
, int csize
)
5513 * Get command and arguments.
5517 char *command_beg
, *command
, *command_end
;
5523 bzero(arguments
, argmax
);
5528 * A sysctl() is made to find out the full path that the command
5532 mib
[1] = KERN_PROCARGS2
;
5536 if (sysctl(mib
, 3, arguments
, (size_t *)&argmax
, NULL
, 0) < 0)
5540 * Skip the saved exec_path
5542 for (cp
= arguments
; cp
< &arguments
[argmax
]; cp
++) {
5545 * End of exec_path reached
5550 if (cp
== &arguments
[argmax
])
5554 * Skip trailing '\0' characters
5556 for (; cp
< &arguments
[argmax
]; cp
++) {
5559 * Beginning of first argument reached
5564 if (cp
== &arguments
[argmax
])
5569 * Make sure that the command is '\0'-terminated. This protects
5570 * against malicious programs; under normal operation this never
5571 * ends up being a problem..
5573 for (; cp
< &arguments
[argmax
]; cp
++) {
5576 * End of first argument reached
5581 if (cp
== &arguments
[argmax
])
5584 command_end
= command
= cp
;
5587 * Get the basename of command
5589 for (command
--; command
>= command_beg
; command
--) {
5590 if (*command
== '/') {
5595 (void) strncpy(cbuf
, (char *)command
, csize
);
5596 cbuf
[csize
-1] = '\0';