jdk/src/sample/solaris/dtrace/hotspot/gc_time_stat.d
author martin
Thu, 30 Oct 2014 07:31:41 -0700
changeset 28059 e576535359cc
parent 25859 3317bb8137f4
permissions -rw-r--r--
8067377: My hobby: caning, then then canning, the the can-can Summary: Fix ALL the stutters! Reviewed-by: rriggs, mchung, lancea
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. gc_time_stat.d -c "java ..." INTERVAL_SECS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *    2. gc_time_stat.d -p JAVA_PID INTERVAL_SECS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * This script measures the duration of a time spent in GC.  The duration is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * measured for every memory pool every INTERVAL_SECS seconds.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * INTERVAL_SECS is not set then 10 seconds interval is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#pragma D option quiet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#pragma D option destructive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#pragma D option defaultargs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#pragma D option aggrate=100ms
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
string TEST_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
self char *str_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
self string mgr_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
self string pool_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
int INTERVAL_SECS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
:::BEGIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    SAMPLE_NAME = "hotspot GC tracing";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    START_TIME = timestamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    gc_total_time = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    gc_total_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    INTERVAL_SECS = $1 ? $1 : 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    SAMPLING_TIME = timestamp + INTERVAL_SECS * 1000000000ull;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    LINE_SEP = "--------------------------------------------------------";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    printf("BEGIN %s\n\n", SAMPLE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * hotspot:::gc-begin
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *  arg0: uintptr_t,    boolean value which indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *                      if this is to be a full GC or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
hotspot$target:::gc-begin
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    self->gc_ts = timestamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    printf("\nGC started: %Y\n", walltimestamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    printf("%20s | %-20s | %10s\n", "manager", "pool", "time (ms)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    printf(" %s\n", LINE_SEP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
hotspot$target:::gc-end
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
/self->gc_ts/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    self->time = (timestamp - self->gc_ts) / 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    printf(" %s\n", LINE_SEP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    printf("   %40s | %10d\n", "GC total", self->time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    gc_total_time += self->time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    gc_total_count ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    self->gc_ts = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * hotspot:::mem-pool-gc-begin, hotspot:::mem-pool-gc-end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *  arg0: char*,        a pointer to mUTF-8 string data which contains the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *                          of the manager which manages this memory pool
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *  arg1: uintptr_t,    the length of the manager name (in bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *  arg2: char*,        a pointer to mUTF-8 string data which contains the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *                          of the memory pool
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *  arg3: uintptr_t,    the length of the memory pool name (in bytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *  arg4: uintptr_t,    the initial size of the memory pool (in bytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 *  arg5: uintptr_t,    the amount of memory in use in the memory pool
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *                          (in bytes)
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
   114
 *  arg6: uintptr_t,    the number of committed pages in the memory pool
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
   115
 *  arg7: uintptr_t,    the maximum size of the memory pool
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
hotspot$target:::mem-pool-gc-begin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    self->str_ptr = (char*) copyin(arg0, arg1+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    self->str_ptr[arg1] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    self->mgr_name = (string) self->str_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    self->str_ptr = (char*) copyin(arg2, arg3+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    self->str_ptr[arg3] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    self->pool_name = (string) self->str_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    self->mem_pool_ts[self->mgr_name, self->pool_name] = timestamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
hotspot$target:::mem-pool-gc-end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    self->str_ptr = (char*) copyin(arg0, arg1+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    self->str_ptr[arg1] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    self->mgr_name = (string) self->str_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    self->str_ptr = (char*) copyin(arg2, arg3+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    self->str_ptr[arg3] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    self->pool_name = (string) self->str_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    self->time =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        (timestamp - self->mem_pool_ts[self->mgr_name, self->pool_name]) / 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    printf(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        "%20s | %-20s | %10d\n", self->mgr_name, self->pool_name, self->time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    @mem_pool_total_time[self->mgr_name, self->pool_name] = sum(self->time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    self->mem_pool_ts[self->mgr_name, self->pool_name] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    @mem_pool_count[self->mgr_name, self->pool_name] = count();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
tick-1sec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
/timestamp > SAMPLING_TIME/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    trace_time = (timestamp - START_TIME) / 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    printf(" %s\n", LINE_SEP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    printf("\nGC statistics, time: %Y\n\n", walltimestamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    printf("%20s | %-20s | %10s\n", "manager", "pool", "total time");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    printf(" %s\n", LINE_SEP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    printa("%20s | %-20s | %10@d\n", @mem_pool_total_time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    printf(" %s\n", LINE_SEP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    printf("   %40s | %10d\n", "total", gc_total_time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    printf("%20s | %-20s | %10s\n", "manager", "pool", "# of calls");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    printf(" %s\n", LINE_SEP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    printa("%20s | %-20s | %10@d\n", @mem_pool_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    printf(" %s\n", LINE_SEP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    printf("   %40s | %10d\n", "total", gc_total_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    SAMPLING_TIME = timestamp + INTERVAL_SECS * 1000000000ull;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
:::END
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    trace_time = (timestamp - START_TIME) / 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    printf(" %s\n", LINE_SEP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    printf("\nGC statistics, time: %Y\n\n", walltimestamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    printf("%20s | %-20s | %10s\n", "manager", "pool", "total time");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    printf(" %s\n", LINE_SEP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    printa("%20s | %-20s | %10@d\n", @mem_pool_total_time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    printf(" %s\n", LINE_SEP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    printf("   %40s | %10d\n", "total", gc_total_time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    printf("%20s | %-20s | %10s\n", "manager", "pool", "# of calls");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    printf(" %s\n", LINE_SEP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    printa("%20s | %-20s | %10@d\n", @mem_pool_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    printf(" %s\n", LINE_SEP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    printf("   %40s | %10d\n", "total", gc_total_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    printf("\nEND of %s\n", SAMPLE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
syscall::rexit:entry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
syscall::exit:entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
/pid == $target/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
   exit(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
}