jdk/src/sample/solaris/dtrace/hotspot/method_invocation_stat.d
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 5506 jdk/src/solaris/sample/dtrace/hotspot/method_invocation_stat.d@202f599c92aa
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
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. method_invocation_stat.d -c "java ..."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *    2. method_invocation_stat.d -p JAVA_PID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * This script collects statistics about Java method invocations.
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
 *  - These probes are disabled by default since it incurs performance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *    overhead to the application. To trace the method-entry and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *    method-exit probes, you need to turn on the ExtendedDTraceProbes VM
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *    option.  
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *    You can either start the application with -XX:+ExtendedDTraceProbes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *    option or use the jinfo command to enable it at runtime as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *       jinfo -flag +ExtendedDTraceProbes <java_pid>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#pragma D option quiet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#pragma D option destructive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
#pragma D option defaultargs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#pragma D option bufsize=16m
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
#pragma D option aggrate=100ms
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
self char *str_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
self string class_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
self string method_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
self string signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
self string package_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
self string last_class_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
long long JAVA_CALLS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
long long JNI_CALLS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
long long SYS_CALLS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
int SYS_DEEP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
long long LAST_SYS_TS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
long long START_TIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
long long JAVA_TIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
long long RUN_TIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
long long SYS_TIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
BEGIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    SAMPLE_NAME = "hotspot method invocation tracing";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    START_TIME = timestamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    SYS_TIME = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    printf("BEGIN %s\n\n", SAMPLE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * hotspot:::method-entry, hotspot:::method-return probe arguments:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *  arg0: uintptr_t,    Java thread id
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *  arg1: char*,        a pointer to mUTF-8 string containing the name of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *                          the class of the method being entered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *  arg2: uintptr_t,    the length of the class name (in bytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *  arg3: char*,        a pointer to mUTF-8 string data which contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *                          name of the method being entered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *  arg4: uintptr_t,    the length of the method name (in bytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *  arg5: char*,        a pointer to mUTF-8 string data which contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *                          signature of the method being entered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *  arg6: uintptr_t,    the length of the signature(in bytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
hotspot$target:::method-entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    self->str_ptr = (char*) copyin(arg1, arg2+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    self->str_ptr[arg2] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    self->class_name = (string) self->str_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    self->str_ptr = (char*) copyin(arg3, arg4+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    self->str_ptr[arg4] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    self->method_name = (string) self->str_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    self->str_ptr = (char*) copyin(arg5, arg6+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    self->str_ptr[arg6] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    self->signature = (string) self->str_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    self->package_name = dirname(self->class_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    JAVA_CALLS ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    @method_calls[self->class_name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                  self->method_name, self->signature] = count();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    @class_calls[self->class_name] = count();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    @package_calls[self->package_name] = count();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
hotspot_jni$target:::*-entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    JNI_CALLS ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    @jni_calls[probename] = count();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
syscall:::entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
/pid == $target && SYS_DEEP == 0/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    LAST_SYS_TS = timestamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
syscall:::entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
/pid == $target/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    SYS_DEEP ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    @sys_calls[probefunc] = count();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    SYS_CALLS ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
syscall:::return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
/pid == $target/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    SYS_DEEP --;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
syscall:::return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
/pid == $target && SYS_DEEP == 0/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    SYS_TIME += (timestamp - LAST_SYS_TS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
:::END
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    RUN_TIME = (timestamp - START_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    JAVA_TIME = (RUN_TIME - SYS_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    printf("System calls:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    printa("%10@d %s\n", @sys_calls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    printf("JNI calls:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    printa("%10@d %s\n", @jni_calls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    printf("Top packages calls:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    printa("%10@d %s\n", @package_calls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    printf("Top class calls:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    printa("%10@d %s\n", @class_calls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    printf("Top method calls:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    printa("%10@d %s:%s:%s\n", @method_calls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    printf("=======================================\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    printf("JAVA_CALLS: %10d\n", JAVA_CALLS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    printf(" JNI_CALLS: %10d\n", JNI_CALLS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    printf(" SYS_CALLS: %10d\n", SYS_CALLS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    printf("Run time:       %15d\n", RUN_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    printf("Syscall time:   %15d\n", SYS_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    printf("Java+JNI time:  %15d\n", JAVA_TIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
:::END
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    printf("\nEND %s\n", SAMPLE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
syscall::rexit:entry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
syscall::exit:entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
/pid == $target/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    exit(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
}