Search in sources :

Example 56 with GCEvent

use of com.tagtraum.perf.gcviewer.model.GCEvent in project GCViewer by chewiebug.

the class DataReaderJRockit1_5_0 method read.

public GCModel read() throws IOException {
    if (getLogger().isLoggable(Level.INFO))
        getLogger().info("Reading JRockit 1.5 format...");
    boolean gcSummary = false;
    try {
        GCModel model = new GCModel();
        model.setFormat(GCModel.Format.SUN_X_LOG_GC);
        String line = null;
        GCEvent event = null;
        int nurserySize = -1;
        int startTimeIndex = 0;
        while ((line = in.readLine()) != null && shouldContinue()) {
            final int memoryIndex = line.indexOf(MEMORY_MARKER);
            if (memoryIndex == -1) {
                if (getLogger().isLoggable(Level.FINE))
                    getLogger().fine("Ignoring line " + in.getLineNumber() + ". Missing \"[memory ]\" marker: " + line);
                continue;
            }
            if (line.endsWith(MEMORY_MARKER)) {
                continue;
            }
            if (startTimeIndex == 0) {
                // Not yet initialized. We will initialize position based on this [memory ] log
                startTimeIndex = memoryIndex + MEMORY_MARKER.length() + 1;
                // GC start time index changes if verbosetimestamp used:
                // [INFO ][memory ] 4.817-4.857: GC 1641728K->148365K (3145728K)
                // [memory ][Thu Feb 21 15:08:25 2013][09368] 4.817-4.857: GC 1641728K->148365K (3145728K)
                // skip to position of last "]" occuring after memory marker "[memory ]"
                int verboseTimestampIndex = line.lastIndexOf(']', line.length());
                if (verboseTimestampIndex > startTimeIndex) {
                    if (getLogger().isLoggable(Level.FINE))
                        getLogger().fine("Log entries have verbose timestamp");
                    // skip "] "
                    startTimeIndex = verboseTimestampIndex + 2;
                }
            }
            // print some special statements to the log.
            if (!gcSummary) {
                gcSummary = line.endsWith("Memory usage report");
            }
            if (gcSummary) {
                if (getLogger().isLoggable(Level.INFO))
                    getLogger().info(line.substring(startTimeIndex));
                continue;
            } else if (line.indexOf("Prefetch distance") != -1) {
                if (getLogger().isLoggable(Level.INFO))
                    getLogger().info(line.substring(startTimeIndex));
                continue;
            } else if (line.indexOf("GC mode") != -1) {
                if (getLogger().isLoggable(Level.INFO))
                    getLogger().info(line.substring(startTimeIndex));
                continue;
            } else if (line.indexOf("GC strategy") != -1) {
                //JRockit dynamically changes GC strategy if using gcPrio, ignore these
                if (getLogger().isLoggable(Level.INFO))
                    getLogger().info(line.substring(startTimeIndex));
                continue;
            } else if (line.indexOf("OutOfMemory") != -1) {
                //Log as SEVERE for user, but ignore for parsing
                if (getLogger().isLoggable(Level.WARNING))
                    getLogger().warning("GC log contains OutOfMemory error: " + line.substring(startTimeIndex));
                continue;
            } else if (line.toLowerCase().indexOf("heap size:") != -1) {
                if (getLogger().isLoggable(Level.INFO))
                    getLogger().info(line.substring(startTimeIndex));
                final int nurserySizeStart = line.indexOf(NURSERY_SIZE);
                final int nurserySizeEnd = line.indexOf('K', nurserySizeStart + NURSERY_SIZE.length());
                if (nurserySizeStart != -1) {
                    nurserySize = Integer.parseInt(line.substring(nurserySizeStart + NURSERY_SIZE.length(), nurserySizeEnd));
                }
                continue;
            } else if (line.substring(startTimeIndex).startsWith("<")) {
                // ignore
                if (getLogger().isLoggable(Level.FINE))
                    getLogger().fine(line.substring(startTimeIndex));
                continue;
            } else if (line.indexOf("K->K") != -1) {
                // -: GC K->K (K), ms
                if (getLogger().isLoggable(Level.FINE))
                    getLogger().fine(line.substring(startTimeIndex));
                continue;
            } else if (line.indexOf("->") == -1) {
                // Example: Thu Feb 21 15:09:22 2013][09368] Memory usage report
                if (getLogger().isLoggable(Level.FINE))
                    getLogger().fine(line.substring(startTimeIndex));
                continue;
            }
            final int colon = line.indexOf(':', startTimeIndex);
            if (colon == -1) {
                if (getLogger().isLoggable(Level.WARNING))
                    getLogger().warning("Malformed line (" + in.getLineNumber() + "). Missing colon after start time: " + line);
                continue;
            }
            event = new GCEvent();
            // set timestamp
            final String timestampString = line.substring(startTimeIndex, colon);
            final int minus = timestampString.indexOf('-');
            if (minus == -1) {
                event.setTimestamp(NumberParser.parseDouble(timestampString));
            } else {
                event.setTimestamp(NumberParser.parseDouble(timestampString.substring(0, minus)));
            }
            // set type
            final int typeStart = skipSpaces(colon + 1, line);
            int typeEnd = typeStart;
            while (!Character.isDigit(line.charAt(++typeEnd))) {
            }
            final AbstractGCEvent.Type type = AbstractGCEvent.Type.lookup("jrockit." + line.substring(typeStart, typeEnd).trim());
            if (type == null) {
                if (getLogger().isLoggable(Level.INFO))
                    getLogger().info("Failed to determine type: " + line.substring(startTimeIndex));
                continue;
            }
            event.setType(type);
            // before
            final int startBefore = typeEnd;
            final int endBefore = line.indexOf('K', startBefore);
            event.setPreUsed(Integer.parseInt(line.substring(startBefore, endBefore)));
            // after
            final int startAfter = endBefore + 3;
            final int endAfter = line.indexOf('K', startAfter);
            event.setPostUsed(Integer.parseInt(line.substring(startAfter, endAfter)));
            // total
            final int startTotal = line.indexOf('(', endAfter) + 1;
            final int endTotal = line.indexOf('K', startTotal);
            event.setTotal(Integer.parseInt(line.substring(startTotal, endTotal)));
            // pause
            int startPause = line.indexOf(',', endTotal);
            while (!Character.isDigit(line.charAt(++startPause))) {
            }
            final int endPause = line.indexOf(' ', startPause);
            event.setPause(NumberParser.parseDouble(line.substring(startPause, endPause)) / 1000.0d);
            model.add(event);
            // add artificial detail events
            if (nurserySize != -1 && event.getExtendedType().getGeneration() == Generation.YOUNG) {
                GCEvent detailEvent = new GCEvent();
                detailEvent.setType(event.getExtendedType().getType());
                detailEvent.setTimestamp(event.getTimestamp());
                detailEvent.setTotal(nurserySize);
                event.add(detailEvent);
            }
            if (nurserySize != -1 && event.getExtendedType().getGeneration() == Generation.TENURED) {
                GCEvent detailEvent = new GCEvent();
                detailEvent.setType(event.getExtendedType().getType());
                detailEvent.setTimestamp(event.getTimestamp());
                detailEvent.setTotal(event.getTotal() - nurserySize);
                event.add(detailEvent);
            }
        }
        return model;
    } finally {
        if (in != null)
            try {
                in.close();
            } catch (IOException ioe) {
            }
        if (getLogger().isLoggable(Level.INFO))
            getLogger().info("Reading done.");
    }
}
Also used : AbstractGCEvent(com.tagtraum.perf.gcviewer.model.AbstractGCEvent) IOException(java.io.IOException) GCEvent(com.tagtraum.perf.gcviewer.model.GCEvent) AbstractGCEvent(com.tagtraum.perf.gcviewer.model.AbstractGCEvent) GCModel(com.tagtraum.perf.gcviewer.model.GCModel)

Example 57 with GCEvent

use of com.tagtraum.perf.gcviewer.model.GCEvent in project GCViewer by chewiebug.

the class DataReaderIBM1_3_0 method read.

public GCModel read() throws IOException {
    if (getLogger().isLoggable(Level.INFO))
        getLogger().info("Reading IBM 1.3.0 format...");
    try {
        GCModel model = new GCModel();
        model.setFormat(GCModel.Format.IBM_VERBOSE_GC);
        int state = 0;
        String line = null;
        AbstractGCEvent<GCEvent> lastEvent = new GCEvent();
        GCEvent event = null;
        while ((line = in.readLine()) != null && shouldContinue()) {
            String trimmedLine = line.trim();
            if ((!trimmedLine.equals("")) && (!trimmedLine.startsWith("<GC: ")) && (!(trimmedLine.startsWith("<") && trimmedLine.endsWith(">")))) {
                if (getLogger().isLoggable(Level.WARNING))
                    getLogger().warning("Malformed line (" + in.getLineNumber() + "): " + line);
                state = 0;
            }
            switch(state) {
                case 0:
                    if (line.indexOf("Allocation Failure.") != -1) {
                        event = new GCEvent();
                        event.setType(AbstractGCEvent.Type.FULL_GC);
                        event.setTimestamp(lastEvent.getTimestamp() + parseTimeSinceLastAF(line));
                        state++;
                        break;
                    }
                case 1:
                    if (line.indexOf("managing allocation failure, action=1") != -1) {
                        event.setPreUsed(parsePreUsed(line));
                        state++;
                        break;
                    }
                case 2:
                    if (line.indexOf("freed") != -1 && line.indexOf("unloaded") == -1) {
                        event.setPostUsed(parsePostUsed(line));
                        event.setTotal(parseTotalAfterGC(line));
                        state++;
                        break;
                    }
                case 3:
                    if (line.indexOf("expanded heap by ") != -1) {
                        event.setTotal(parseTotalAfterHeapExpansion(line));
                        state++;
                        break;
                    }
                case 4:
                    if (line.indexOf("completed in ") != -1) {
                        event.setPause(parsePause(line));
                        model.add(event);
                        lastEvent = event;
                        event = null;
                        state = 0;
                    }
                default:
            }
        }
        return model;
    } finally {
        if (in != null)
            try {
                in.close();
            } catch (IOException ioe) {
            }
        if (getLogger().isLoggable(Level.INFO))
            getLogger().info("Reading done.");
    }
}
Also used : IOException(java.io.IOException) GCEvent(com.tagtraum.perf.gcviewer.model.GCEvent) AbstractGCEvent(com.tagtraum.perf.gcviewer.model.AbstractGCEvent) GCModel(com.tagtraum.perf.gcviewer.model.GCModel)

Example 58 with GCEvent

use of com.tagtraum.perf.gcviewer.model.GCEvent in project GCViewer by chewiebug.

the class FullGCLineRenderer method paintComponent.

public void paintComponent(Graphics2D g2d) {
    // make sure that we ignore the AntiAliasing flag as it does not make sense for vertical lines
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    double scaleFactor = getModelChart().getScaleFactor();
    Rectangle clipBounds = g2d.getClipBounds();
    int minX = clipBounds.x;
    int maxX = clipBounds.x + clipBounds.width;
    int height = getHeight();
    int lastScaledTimestamp = Integer.MIN_VALUE;
    for (Iterator<GCEvent> i = getModelChart().getModel().getFullGCEvents(); i.hasNext(); ) {
        GCEvent event = i.next();
        int scaledTimestamp = (int) (scaleFactor * (event.getTimestamp() - getModelChart().getModel().getFirstPauseTimeStamp()));
        if (scaledTimestamp != lastScaledTimestamp && scaledTimestamp >= minX && scaledTimestamp <= maxX) {
            g2d.drawLine(scaledTimestamp, 0, scaledTimestamp, height);
            lastScaledTimestamp = scaledTimestamp;
        }
    }
}
Also used : GCEvent(com.tagtraum.perf.gcviewer.model.GCEvent)

Example 59 with GCEvent

use of com.tagtraum.perf.gcviewer.model.GCEvent in project GCViewer by chewiebug.

the class TotalHeapRenderer method computePolygon.

public Polygon computePolygon(ModelChart modelChart, GCModel model) {
    ScaledPolygon polygon = createMemoryScaledPolygon();
    polygon.addPoint(0.0d, 0.0d);
    int lastTotal = 0;
    for (Iterator<AbstractGCEvent<?>> i = model.getStopTheWorldEvents(); i.hasNext(); ) {
        AbstractGCEvent<?> abstractGCEvent = i.next();
        if (abstractGCEvent instanceof GCEvent) {
            GCEvent event = (GCEvent) abstractGCEvent;
            if (event.getTotal() > 0) {
                // -> skip them
                if (polygon.npoints == 1) {
                    // first point needs to be treated different from the rest,
                    // because otherwise the polygon would not start with a vertical line at 0,
                    // but with a slanting line between 0 and after the first pause
                    polygon.addPoint(0, (double) event.getTotal());
                }
                polygon.addPoint(event.getTimestamp() - model.getFirstPauseTimeStamp() + event.getPause(), event.getTotal());
                lastTotal = event.getTotal();
            }
        }
    }
    polygon.addPointNotOptimised(model.getRunningTime(), lastTotal);
    polygon.addPointNotOptimised(model.getRunningTime(), 0.0d);
    return polygon;
}
Also used : AbstractGCEvent(com.tagtraum.perf.gcviewer.model.AbstractGCEvent) GCEvent(com.tagtraum.perf.gcviewer.model.GCEvent) AbstractGCEvent(com.tagtraum.perf.gcviewer.model.AbstractGCEvent) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint)

Example 60 with GCEvent

use of com.tagtraum.perf.gcviewer.model.GCEvent in project GCViewer by chewiebug.

the class TotalYoungRenderer method computePolygon.

public Polygon computePolygon(ModelChart modelChart, GCModel model) {
    ScaledPolygon polygon = createMemoryScaledPolygon();
    polygon.addPoint(0.0d, 0.0d);
    double lastTenured = 0;
    double lastYoung = 0;
    for (Iterator<AbstractGCEvent<?>> i = model.getStopTheWorldEvents(); i.hasNext(); ) {
        AbstractGCEvent<?> abstractGCEvent = i.next();
        if (abstractGCEvent instanceof GCEvent) {
            GCEvent event = (GCEvent) abstractGCEvent;
            double tenuredSize = 0;
            double youngSize = 0;
            GCEvent young = event.getYoung();
            GCEvent tenured = event.getTenured();
            if (hasMemoryInformation(event) && young != null && tenured != null) {
                if (modelChart.isShowTenured()) {
                    tenuredSize = tenured.getTotal();
                }
                youngSize = young.getTotal();
                if (polygon.npoints == 1) {
                    // first point needs to be treated different from the rest,
                    // because otherwise the polygon would not start with a vertical line at 0,
                    // but with a slanting line between 0 and after the first pause
                    polygon.addPoint(0, tenuredSize + youngSize);
                }
                polygon.addPoint(event.getTimestamp() - model.getFirstPauseTimeStamp() + event.getPause(), tenuredSize + youngSize);
                lastYoung = youngSize;
                lastTenured = tenuredSize;
            }
        }
    }
    polygon.addPointNotOptimised(model.getRunningTime(), lastTenured + lastYoung);
    polygon.addPointNotOptimised(model.getRunningTime(), 0.0d);
    return polygon;
}
Also used : AbstractGCEvent(com.tagtraum.perf.gcviewer.model.AbstractGCEvent) GCEvent(com.tagtraum.perf.gcviewer.model.GCEvent) AbstractGCEvent(com.tagtraum.perf.gcviewer.model.AbstractGCEvent)

Aggregations

GCEvent (com.tagtraum.perf.gcviewer.model.GCEvent)60 GCModel (com.tagtraum.perf.gcviewer.model.GCModel)45 Test (org.junit.Test)33 AbstractGCEvent (com.tagtraum.perf.gcviewer.model.AbstractGCEvent)26 GcResourceFile (com.tagtraum.perf.gcviewer.model.GcResourceFile)21 GCResource (com.tagtraum.perf.gcviewer.model.GCResource)13 IOException (java.io.IOException)11 ByteArrayInputStream (java.io.ByteArrayInputStream)5 SimpleDateFormat (java.text.SimpleDateFormat)3 StringTokenizer (java.util.StringTokenizer)3 Paint (java.awt.Paint)2 StartElement (javax.xml.stream.events.StartElement)2 XMLEvent (javax.xml.stream.events.XMLEvent)2 Before (org.junit.Before)2 Type (com.tagtraum.perf.gcviewer.model.AbstractGCEvent.Type)1 ConcurrentGCEvent (com.tagtraum.perf.gcviewer.model.ConcurrentGCEvent)1 VmOperationEvent (com.tagtraum.perf.gcviewer.model.VmOperationEvent)1 GradientPaint (java.awt.GradientPaint)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1