Dtrace-Ebook.Pdf
Total Page:16
File Type:pdf, Size:1020Kb
The illumos Dynamic Tracing Guide The contents of this Documentation are subject to the Public Documentation License Version 1.01 (the “License”); you may only use this Documentation if you comply with the terms of this License. Further information about the License is available in AppendixA. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this document, and the publisher was aware of the trademark claim, the designations have been followed by the “™” or the “®” symbol, or printed with initial capital letters or in all capitals. This distribution may include materials developed by third parties. Parts of the product may be derived from Berkeley BSD systems, licensed from the University of California. UNIX is a registered trademark of The Open Group. illumos and the illumos logo are trademarks or registered trademarks of Garrett D’Amore. Sun, Sun Microsystems, StarOffice, Java, and Solaris are trademarks or registered trademarks of Oracle, Inc. or its subsidiaries in the U.S. and other countries. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the U.S. and other countries. Products bearing SPARC trademarks are based upon an architecture developed by Sun Microsystems, Inc. DOCUMENTATION IS PROVIDED “AS IS” AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTA- TIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID. Copyright © 2008 Sun Microsystems, Inc. Copyright © 2016 Joyent, Inc. Contents Contents i List of Figures ix List of Tables ix 1 Introduction 1 1.1 DTrace on other Operating Systems . .1 1.2 Getting Started . .2 1.3 Providers and Probes . .3 1.4 Compilation and Instrumentation . .5 1.5 Variables and Arithmetic Expressions . .6 1.6 Predicates . .8 1.7 Output Formatting . 12 1.8 Arrays . 14 1.9 External Symbols and Types . 16 2 Types, Operators, and Expressions 17 2.1 Identifier Names and Keywords . 17 2.2 Data Types and Sizes . 18 2.3 Constants . 19 2.4 Arithmetic Operators . 20 2.5 Relational Operators . 21 2.6 Logical Operators . 22 2.7 Bitwise Operators . 22 2.8 Assignment Operators . 23 2.9 Increment and Decrement Operators . 24 2.10 Conditional Expressions . 24 2.11 Type Conversions . 25 2.12 Precedence . 26 3 Variables 29 3.1 Scalar Variables . 29 3.2 Associative Arrays . 30 3.3 Thread-Local Variables . 31 3.4 Clause-Local Variables . 33 3.5 Built-in Variables . 35 3.6 External Variables . 37 i CONTENTS 4 D Program Structure 39 4.1 Probe Clauses and Declarations . 39 4.2 Probe Descriptions . 39 4.3 Predicates . 41 4.4 Actions . 41 4.5 Use of the C Preprocessor . 41 5 Pointers and Arrays 43 5.1 Pointers and Addresses . 43 5.2 Pointer Safety . 44 5.3 Array Declarations and Storage . 45 5.4 Pointer and Array Relationship . 46 5.5 Pointer Arithmetic . 47 5.6 Generic Pointers . 48 5.7 Multi-Dimensional Arrays . 48 5.8 Pointers to DTrace Objects . 48 5.9 Pointers and Address Spaces . 49 6 Strings 51 6.1 String Representation . 51 6.2 String Constants . 52 6.3 String Assignment . 52 6.4 String Conversion . 52 6.5 String Comparison . 53 7 Structs and Unions 55 7.1 Structs . 55 7.2 Pointers to Structs . 57 7.3 Unions . 60 7.4 Member Sizes and Offsets . 63 7.5 Bit-Fields . 63 8 Type and Constant Definitions 65 8.1 Typedef . 65 8.2 Enumerations . 65 8.3 Inlines . 67 8.4 Type Namespaces . 67 9 Aggregations 69 9.1 Aggregating Functions . 69 9.2 Aggregations . 70 9.3 Printing Aggregations . 78 9.4 Data Normalization . 78 9.5 Clearing Aggregations . 81 9.6 Truncating aggregations . 82 9.7 Minimizing Drops . 83 10 Actions and Subroutines 85 10.1 Actions . 85 10.2 Default Action . 85 ii Contents 10.3 Data Recording Actions . 86 trace ........................................... 86 tracemem ......................................... 86 print ........................................... 87 printf ........................................... 87 printa ........................................... 87 stack ........................................... 88 ustack ........................................... 89 jstack ........................................... 92 10.4 Destructive Actions . 92 Process Destructive Actions . 93 stop ........................................ 93 raise ....................................... 93 copyout ...................................... 93 copyoutstr ................................... 93 system ...................................... 93 Kernel Destructive Actions . 95 breakpoint ................................... 95 panic ....................................... 96 chill ....................................... 97 10.5 Special Actions . 98 Speculative Actions . 98 exit ............................................ 98 10.6 Subroutines . 98 alloca ........................................... 98 basename ......................................... 98 bcopy ........................................... 99 cleanpath ........................................ 99 copyin ........................................... 99 copyinstr ........................................ 99 copyinto ......................................... 100 ddi_pathname ...................................... 100 dirname .......................................... 100 htons ........................................... 100 htonl ........................................... 100 htonll ........................................... 100 index ........................................... 101 inet_ntoa ........................................ 101 inet_ntoa6 ....................................... 101 inet_ntop ........................................ 101 lltostr .......................................... 101 getmajor ......................................... 101 getminor ......................................... 102 msgdsize ......................................... 102 msgsize .......................................... 102 mutex_owned ....................................... 102 mutex_owner ....................................... 102 mutex_type_adaptive ................................ 102 mutex_type_spin ................................... 103 iii CONTENTS ntohs ........................................... 103 ntohl ........................................... 103 ntohll ........................................... 103 progenyof ........................................ 103 rand ............................................ 103 rindex ........................................... 104 rw_iswriter ....................................... 104 rw_read_held ...................................... 104 rw_write_held ..................................... 104 speculation ....................................... 104 strchr ........................................... 104 strjoin .......................................... 104 strlen ........................................... 105 strrchr .......................................... 105 strstr ........................................... 105 strtok ........................................... 105 substr ........................................... 105 tolower .......................................... 105 toupper .......................................... 106 11 Buffers and Buffering 107 11.1 Principal Buffers . 107 11.2 Principal Buffer Policies . 107 switch Policy . 107 fill Policy . 108 fill Policy and END Probes . ..