jdk/src/solaris/sample/dtrace/hotspot/hotspot_calls_tree.d
author duke
Wed, 05 Jul 2017 17:48:11 +0200
changeset 10204 bbd2c5e0ce05
parent 5506 202f599c92aa
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
#!/usr/sbin/dtrace -Zs
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     3
 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * Redistribution and use in source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * modification, are permitted provided that the following conditions
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *   - Redistributions of source code must retain the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *     notice, this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *   - Redistributions in binary form must reproduce the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *     notice, this list of conditions and the following disclaimer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *     documentation and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    16
 *   - Neither the name of Oracle nor the names of its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *     contributors may be used to endorse or promote products derived
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *     from this software without specific prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Usage:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *   1. hotspot_calls_tree.d -c "java ..."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *   2. hotspot_calls_tree.d -p JAVA_PID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * This script prints calls tree of fired 'hotspot' probes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Notes: 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *    The script uses 'monitors' probes which are disabled by default since
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *    it incurs performance overhead to the application. To enable them, you
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *    need to turn on the ExtendedDTraceProbes VM option. You can either
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *    start the application with -XX:+ExtendedDTraceProbes option or use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *    jinfo command to enable it at runtime as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *       jinfo -flag +ExtendedDTraceProbes <java_pid>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
#pragma D option quiet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#pragma D option destructive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#pragma D option defaultargs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
#pragma D option aggrate=100ms
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
self int indent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
string PAUSE_AT_STARTUP_FILE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
:::BEGIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    SAMPLE_NAME = "hotspot probes tracing";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    printf("BEGIN %s\n\n", SAMPLE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    self->indent = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
hotspot$target:::class-loaded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
hotspot$target:::class-unloaded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
hotspot$target:::compiled-method-load,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
hotspot$target:::compiled-method-unload,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
hotspot$target:::monitor-notify,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
hotspot$target:::monitor-notifyAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    printf("%d %*s <-> %s\n", curcpu->cpu_id, self->indent, "", probename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
hotspot$target:::vm-init-begin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
hotspot$target:::gc-begin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
hotspot$target:::mem-pool-gc-begin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
hotspot$target:::thread-start,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
hotspot$target:::method-compile-begin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
hotspot$target:::monitor-contended-enter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
hotspot$target:::monitor-wait
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    self->indent ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    printf("%d %*s -> %s\n", curcpu->cpu_id, self->indent, "", probename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
hotspot$target:::vm-init-end,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
hotspot$target:::vm-shutdown,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
hotspot$target:::gc-end,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
hotspot$target:::mem-pool-gc-end,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
hotspot$target:::thread-stop,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
hotspot$target:::method-compile-end,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
hotspot$target:::monitor-contended-entered,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
hotspot$target:::monitor-contended-exit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
hotspot$target:::monitor-waited
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    printf("%d %*s <- %s\n", curcpu->cpu_id, self->indent, "", probename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    self->indent --;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
:::END
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    printf("\nEND of %s\n", SAMPLE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
syscall::rexit:entry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
syscall::exit:entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
/pid == $target/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    exit(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
}