48 * jint vector_length; // length of the vector. If 0, then scalar.
49 * jbyte data_type; // JNI field descriptor type
50 * jbyte flags; // miscellaneous attribute flags
51 * // 0x01 - supported
52 * jbyte data_units; // unit of measure attribute
53 * jbyte data_variability; // variability attribute
54 * jbyte data_offset; // offset to data item, relative to start
55 * // of entry.
56 * } PerfDataEntry;
57 * </pre>
58 *
59 * @author Brian Doherty
60 * @since 1.5
61 * @see AbstractPerfDataBuffer
62 */
63 public class PerfDataBuffer extends PerfDataBufferImpl {
64
65 private static final boolean DEBUG = false;
66 private static final int syncWaitMs =
67 Integer.getInteger("sun.jvmstat.perdata.syncWaitMs", 5000);
68 private static final ArrayList EMPTY_LIST = new ArrayList(0);
69
70 /*
71 * These are primarily for documentary purposes and the match up
72 * with the PerfDataEntry structure in perfMemory.hpp. They are
73 * generally unused in this code, but they are kept consistent with
74 * the data structure just in case some unforseen need arrises.
75 */
76 private final static int PERFDATA_ENTRYLENGTH_OFFSET=0;
77 private final static int PERFDATA_ENTRYLENGTH_SIZE=4; // sizeof(int)
78 private final static int PERFDATA_NAMEOFFSET_OFFSET=4;
79 private final static int PERFDATA_NAMEOFFSET_SIZE=4; // sizeof(int)
80 private final static int PERFDATA_VECTORLENGTH_OFFSET=8;
81 private final static int PERFDATA_VECTORLENGTH_SIZE=4; // sizeof(int)
82 private final static int PERFDATA_DATATYPE_OFFSET=12;
83 private final static int PERFDATA_DATATYPE_SIZE=1; // sizeof(byte)
84 private final static int PERFDATA_FLAGS_OFFSET=13;
85 private final static int PERFDATA_FLAGS_SIZE=1; // sizeof(byte)
86 private final static int PERFDATA_DATAUNITS_OFFSET=14;
87 private final static int PERFDATA_DATAUNITS_SIZE=1; // sizeof(byte)
88 private final static int PERFDATA_DATAVAR_OFFSET=15;
181 if (insertedMonitors != null) {
182 insertedMonitors.add(monitor);
183 }
184 }
185 monitor = getNextMonitorEntry();
186 }
187 }
188 }
189
190 /**
191 * {@inheritDoc}
192 */
193 protected MonitorStatus getMonitorStatus(Map<String, Monitor> map) throws MonitorException {
194 assert Thread.holdsLock(this);
195 assert insertedMonitors != null;
196
197 // load any new monitors
198 getNewMonitors(map);
199
200 // current implementation doesn't support deletion of reuse of entries
201 ArrayList removed = EMPTY_LIST;
202 ArrayList inserted = insertedMonitors;
203
204 insertedMonitors = new ArrayList<Monitor>();
205 return new MonitorStatus(inserted, removed);
206 }
207
208 /**
209 * Build the pseudo monitors used to map the prolog data into counters.
210 */
211 protected void buildPseudoMonitors(Map<String, Monitor> map) {
212 Monitor monitor = null;
213 String name = null;
214 IntBuffer ib = null;
215
216 name = PerfDataBufferPrologue.PERFDATA_MAJOR_NAME;
217 ib = prologue.majorVersionBuffer();
218 monitor = new PerfIntegerMonitor(name, Units.NONE,
219 Variability.CONSTANT, false, ib);
220 map.put(name, monitor);
221
222 name = PerfDataBufferPrologue.PERFDATA_MINOR_NAME;
223 ib = prologue.minorVersionBuffer();
224 monitor = new PerfIntegerMonitor(name, Units.NONE,
507 + ", name = " + name
508 + ", type_code = " + typeCode + " (0x"
509 + Integer.toHexString(typeCodeByte) + ")");
510 }
511 }
512
513 // setup index to next entry for next iteration of the loop.
514 nextEntry = entryStart + entryLength;
515 return monitor;
516 }
517
518 /**
519 * Method to dump debugging information
520 */
521 private void dumpAll(Map<String, Monitor> map, int lvmid) {
522 if (DEBUG) {
523 Set<String> keys = map.keySet();
524
525 System.err.println("Dump for " + lvmid);
526 int j = 0;
527 for (Iterator i = keys.iterator(); i.hasNext(); j++) {
528 Monitor monitor = map.get(i.next());
529 System.err.println(j + "\t" + monitor.getName()
530 + "=" + monitor.getValue());
531 }
532 System.err.println("nextEntry = " + nextEntry);
533 System.err.println("Buffer info:");
534 System.err.println("buffer = " + buffer);
535 }
536 }
537
538 /**
539 * Method to dump the fixed portion of an entry.
540 */
541 private void dump_entry_fixed(int entry_start, int nameOffset,
542 int vectorLength, byte typeCodeByte,
543 byte flags, byte unitsByte, byte varByte,
544 int dataOffset) {
545 if (DEBUG) {
546 System.err.println("Entry at offset: 0x"
547 + Integer.toHexString(entry_start));
|
48 * jint vector_length; // length of the vector. If 0, then scalar.
49 * jbyte data_type; // JNI field descriptor type
50 * jbyte flags; // miscellaneous attribute flags
51 * // 0x01 - supported
52 * jbyte data_units; // unit of measure attribute
53 * jbyte data_variability; // variability attribute
54 * jbyte data_offset; // offset to data item, relative to start
55 * // of entry.
56 * } PerfDataEntry;
57 * </pre>
58 *
59 * @author Brian Doherty
60 * @since 1.5
61 * @see AbstractPerfDataBuffer
62 */
63 public class PerfDataBuffer extends PerfDataBufferImpl {
64
65 private static final boolean DEBUG = false;
66 private static final int syncWaitMs =
67 Integer.getInteger("sun.jvmstat.perdata.syncWaitMs", 5000);
68 private static final ArrayList<Monitor> EMPTY_LIST = new ArrayList<>(0);
69
70 /*
71 * These are primarily for documentary purposes and the match up
72 * with the PerfDataEntry structure in perfMemory.hpp. They are
73 * generally unused in this code, but they are kept consistent with
74 * the data structure just in case some unforseen need arrises.
75 */
76 private final static int PERFDATA_ENTRYLENGTH_OFFSET=0;
77 private final static int PERFDATA_ENTRYLENGTH_SIZE=4; // sizeof(int)
78 private final static int PERFDATA_NAMEOFFSET_OFFSET=4;
79 private final static int PERFDATA_NAMEOFFSET_SIZE=4; // sizeof(int)
80 private final static int PERFDATA_VECTORLENGTH_OFFSET=8;
81 private final static int PERFDATA_VECTORLENGTH_SIZE=4; // sizeof(int)
82 private final static int PERFDATA_DATATYPE_OFFSET=12;
83 private final static int PERFDATA_DATATYPE_SIZE=1; // sizeof(byte)
84 private final static int PERFDATA_FLAGS_OFFSET=13;
85 private final static int PERFDATA_FLAGS_SIZE=1; // sizeof(byte)
86 private final static int PERFDATA_DATAUNITS_OFFSET=14;
87 private final static int PERFDATA_DATAUNITS_SIZE=1; // sizeof(byte)
88 private final static int PERFDATA_DATAVAR_OFFSET=15;
181 if (insertedMonitors != null) {
182 insertedMonitors.add(monitor);
183 }
184 }
185 monitor = getNextMonitorEntry();
186 }
187 }
188 }
189
190 /**
191 * {@inheritDoc}
192 */
193 protected MonitorStatus getMonitorStatus(Map<String, Monitor> map) throws MonitorException {
194 assert Thread.holdsLock(this);
195 assert insertedMonitors != null;
196
197 // load any new monitors
198 getNewMonitors(map);
199
200 // current implementation doesn't support deletion of reuse of entries
201 ArrayList<Monitor> removed = EMPTY_LIST;
202 ArrayList<Monitor> inserted = insertedMonitors;
203
204 insertedMonitors = new ArrayList<>();
205 return new MonitorStatus(inserted, removed);
206 }
207
208 /**
209 * Build the pseudo monitors used to map the prolog data into counters.
210 */
211 protected void buildPseudoMonitors(Map<String, Monitor> map) {
212 Monitor monitor = null;
213 String name = null;
214 IntBuffer ib = null;
215
216 name = PerfDataBufferPrologue.PERFDATA_MAJOR_NAME;
217 ib = prologue.majorVersionBuffer();
218 monitor = new PerfIntegerMonitor(name, Units.NONE,
219 Variability.CONSTANT, false, ib);
220 map.put(name, monitor);
221
222 name = PerfDataBufferPrologue.PERFDATA_MINOR_NAME;
223 ib = prologue.minorVersionBuffer();
224 monitor = new PerfIntegerMonitor(name, Units.NONE,
507 + ", name = " + name
508 + ", type_code = " + typeCode + " (0x"
509 + Integer.toHexString(typeCodeByte) + ")");
510 }
511 }
512
513 // setup index to next entry for next iteration of the loop.
514 nextEntry = entryStart + entryLength;
515 return monitor;
516 }
517
518 /**
519 * Method to dump debugging information
520 */
521 private void dumpAll(Map<String, Monitor> map, int lvmid) {
522 if (DEBUG) {
523 Set<String> keys = map.keySet();
524
525 System.err.println("Dump for " + lvmid);
526 int j = 0;
527 for (Iterator<String> i = keys.iterator(); i.hasNext(); j++) {
528 Monitor monitor = map.get(i.next());
529 System.err.println(j + "\t" + monitor.getName()
530 + "=" + monitor.getValue());
531 }
532 System.err.println("nextEntry = " + nextEntry);
533 System.err.println("Buffer info:");
534 System.err.println("buffer = " + buffer);
535 }
536 }
537
538 /**
539 * Method to dump the fixed portion of an entry.
540 */
541 private void dump_entry_fixed(int entry_start, int nameOffset,
542 int vectorLength, byte typeCodeByte,
543 byte flags, byte unitsByte, byte varByte,
544 int dataOffset) {
545 if (DEBUG) {
546 System.err.println("Entry at offset: 0x"
547 + Integer.toHexString(entry_start));
|