File: PeriodicStats.btm

package info (click to toggle)
byteman 4.0.20-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, trixie
  • size: 4,924 kB
  • sloc: java: 42,325; xml: 7,189; sh: 351; makefile: 23
file content (207 lines) | stat: -rw-r--r-- 6,481 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
########################################################################
# JBoss, Home of Professional Open Source
# Copyright 2010, Red Hat and individual contributors
# by the @authors tag. See the copyright.txt in the distribution for a
# full listing of individual contributors.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this software; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA, or see the FSF site: http://www.fsf.org.
#
# @authors Andrew Dinn
#
# Preiodic Statistics Display
#
# A byteman script which collects statistics for actions performed by the
# JVM runtime and uses the periodic helper to dump and clear them at regular
# intervals
#
# to use ths script to trace execution of java program org.my.App execute
#
#  -- set the directory in which byteman has been installed
#  BYTEMAN_HOME= ...
#
#   -- identify the samples helper jar to the boot path
#   SAMPLE_JAR=${BYTEMAN_HOME}/sample/lib/byteman-sample.jar
#
#   -- identify this script
#   SCRIPT={BYTEMAN_HOME}/sample/scripts/PeriodicStats.txt
#
#  ${BYTEMAN_HOME}/bin/bmjava.sh -l $SCRIPT -b $SAMPLE_JAR org.my.App
#
# alternatively to load the script dynamically
#
#   -- start the program with the agent
#  ${BYTEMAN_HOME}/bin/bmjava.sh org.my.App
#
#   -- install the helper library into the bootstrap classpath
#  ${BYTEMAN_HOME}/bin/bmsubmit.sh -b $SAMPLE_JAR
#
#   -- install the script
#  ${BYTEMAN_HOME}/bin/bmsubmit.sh -l $SCRIPT

########################################################################
#
# all rules in this script use the periodic helper which provides support
# for triggering of rules at regular intervals. The helper adds a
# thread in the background when it is activated i.e. when any of the rules
# which employs the helper is first triggered. The thread is shut down
# when the helper is deactivated i.e. once all rules using the helper
# have been uninstalled.

HELPER org.jboss.byteman.sample.helper.PeriodicHelper

# This rule defines the wait interval between periodic triggers. The periodic
# helper thread calls getPeriod when it is started. The rule forces getPeriod
# to return 30,000 causing the thread to wake up at 30 second intervals.

RULE set period
CLASS PeriodicHelper
METHOD getPeriod()
IF TRUE
DO RETURN 30 * 1000
ENDRULE

# this rule is triggered every 30 seconds when the periodic helper thread
# calls method periodicTrigger. It reads and zeroes all the stats counters
# and the prints a formatted trace of JVM activity in the 30 second interval.

RULE dump stats
CLASS PeriodicHelper
METHOD periodicTrigger()
BIND threadCreates = readCounter("thread creates", true);
     threadStarts = readCounter("thread starts", true);
     threadRuns = readCounter("thread runs", true);
     threadExits = readCounter("thread exits", true);
     fileInOpens = readCounter("file in opens", true);
     fileOutOpens = readCounter("file out opens", true);
     fileInCloses = readCounter("file in closes", true);
     fileOutCloses = readCounter("file out closes", true);
     classLoads = readCounter("class loads", true)
IF TRUE
DO traceln("Periodic Statistics");
   traceln("Thread creates    " + threadCreates);
   traceln("Thread starts     " + threadStarts);
   traceln("Thread runs       " + threadRuns);
   traceln("Thread exits      " + threadExits);
   traceln("File [in] opens   " + fileInOpens);
   traceln("File [out] opens  " + fileOutOpens);
   traceln("File [in] closes  " + fileInCloses);
   traceln("File [out] closes " + fileOutCloses);
   traceln("Class loads       " + classLoads);
   traceln("")
ENDRULE

# The remaining rules increment stats counters whenever a sigificant
# event occurs in the JVM.

# this rule counts Thread creates
RULE count thread create
CLASS java.lang.Thread
METHOD <init>
IF TRUE
DO incrementCounter("thread creates")
ENDRULE

# this rule counts Thread starts
RULE count thread start
CLASS java.lang.Thread
METHOD start()
AT CALL start0
IF TRUE
DO incrementCounter("thread starts")
ENDRULE

# this rule counts Thread runs
RULE count thread run
CLASS ^java.lang.Thread
METHOD run()
IF !callerMatches(".*")
DO incrementCounter("thread runs")
ENDRULE

# this rule counts Thread exits
RULE count thread exit
CLASS ^java.lang.Thread
METHOD exit()
IF TRUE
DO incrementCounter("thread exits")
ENDRULE

# this rule counts FileInputStream opens for read from a File
RULE count file open read File
CLASS java.io.FileInputStream
METHOD <init>(java.io.File)
AT RETURN
IF TRUE
DO incrementCounter("file in opens")
ENDRULE

# this rule counts FileInputStream opens for read from a File Descriptor
RULE count file open read File Descriptor
CLASS java.io.FileInputStream
METHOD <init>(FileDescriptor)
AT RETURN
IF TRUE
DO incrementCounter("file in opens")
ENDRULE

# this rule counts FileOutputStream opens for write from a File
RULE count file open write File
CLASS java.io.FileOutputStream
METHOD <init>(java.io.File, boolean)
AT RETURN
IF TRUE
DO incrementCounter("file out opens")
ENDRULE

# this rule counts FileOutputStream opens for write from a File Descriptor
RULE count file open write File Descriptor
CLASS java.io.FileOutputStream
METHOD <init>(FileDescriptor)
AT RETURN
IF TRUE
DO incrementCounter("file out opens")
ENDRULE

# this rule counts FileInputStream closes for a File input stream
RULE count file input stream close
CLASS java.io.FileInputStream
METHOD close()
AT RETURN
IF TRUE
DO incrementCounter("file in closes")
ENDRULE

# this rule counts FileOutputStream closes for a File output stream
RULE count file output stream close
CLASS java.io.FileOutputStream
METHOD close()
AT RETURN
IF TRUE
DO incrementCounter("file out closes")
ENDRULE

# this rule counts class loads which result in a new class being defined
RULE count class loads
CLASS ^java.lang.ClassLoader
METHOD defineClass(String, byte[], int, int, ProtectionDomain)
AT RETURN
IF TRUE
DO incrementCounter("class loads")
ENDRULE