Search in sources :

Example 21 with Method

use of org.spf4j.base.avro.Method in project spf4j by zolyfarkas.

the class Explorer method toSupplier.

// GEN-LAST:event_compareMenuItemActionPerformed
private StackSampleSupplier toSupplier(final File file) throws IOException {
    if (Spf4jFileFilter.SSDUMP.accept(file)) {
        SampleNode samples = loadLegacyFormat(file);
        Instant now = Instant.now();
        return new OneStackSampleSupplier(now, now, samples);
    } else if (Spf4jFileFilter.SSDUMP2.accept(file) || Spf4jFileFilter.SSDUMP2_GZ.accept(file)) {
        SampleNode samples = org.spf4j.ssdump2.Converter.load(file);
        Instant now = Instant.now();
        return new OneStackSampleSupplier(now, now, samples);
    } else if (Spf4jFileFilter.SSDUMP3.accept(file) || Spf4jFileFilter.SSDUMP3_GZ.accept(file)) {
        Map<String, SampleNode> loadLabeledDumps = org.spf4j.ssdump2.Converter.loadLabeledDumps(file);
        Instant now = Instant.now();
        return new MultiStackSampleSupplier(now, now, loadLabeledDumps);
    } else if (Spf4jFileFilter.D3_JSON.accept(file)) {
        try (BufferedReader br = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) {
            Pair<Method, SampleNode> parse = SampleNode.parseD3Json(br);
            Instant now = Instant.now();
            return new OneStackSampleSupplier(now, now, parse.getSecond());
        }
    } else if (Spf4jFileFilter.SPF4J_JSON.accept(file)) {
        try (BufferedReader br = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) {
            Pair<Method, SampleNode> parse = SampleNode.parse(br);
            Instant now = Instant.now();
            return new OneStackSampleSupplier(now, now, parse.getSecond());
        }
    } else if (Spf4jFileFilter.PROFILE_AVRO.accept(file)) {
        return new AvroStackSampleSupplier(file.toPath());
    } else {
        throw new IOException("Unsupported file format " + file);
    }
}
Also used : AvroStackSampleSupplier(org.spf4j.stackmonitor.AvroStackSampleSupplier) Instant(java.time.Instant) BufferedReader(java.io.BufferedReader) SampleNode(org.spf4j.stackmonitor.SampleNode) Method(org.spf4j.base.avro.Method) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Pair(org.spf4j.base.Pair)

Example 22 with Method

use of org.spf4j.base.avro.Method in project spf4j by zolyfarkas.

the class Explorer method openFile.

private void openFile(final File file) throws IOException {
    String fileName = file.getName();
    JInternalFrame frame;
    if (Spf4jFileFilter.TSDB.accept(file)) {
        frame = new TSDBViewJInternalFrame(file);
        frame.setVisible(true);
        desktopPane.add(frame, javax.swing.JLayeredPane.DEFAULT_LAYER);
    } else if (Spf4jFileFilter.TSDB2.accept(file)) {
        frame = new TSDB2ViewJInternalFrame(file);
        frame.setVisible(true);
        desktopPane.add(frame, javax.swing.JLayeredPane.DEFAULT_LAYER);
    } else if (Spf4jFileFilter.AVRO_TABLEDEF.accept(file)) {
        frame = new MStoreViewJInternalFrame(file);
        frame.setVisible(true);
        desktopPane.add(frame, javax.swing.JLayeredPane.DEFAULT_LAYER);
    } else if (Spf4jFileFilter.SSDUMP.accept(file)) {
        SampleNode samples = loadLegacyFormat(file);
        setFrames(samples, fileName);
    } else if (Spf4jFileFilter.SSDUMP2.accept(file) || Spf4jFileFilter.SSDUMP2_GZ.accept(file)) {
        SampleNode samples = org.spf4j.ssdump2.Converter.load(file);
        setFrames(samples, fileName);
    } else if (Spf4jFileFilter.SSDUMP3.accept(file) || Spf4jFileFilter.SSDUMP3_GZ.accept(file)) {
        Map<String, SampleNode> loadLabeledDumps = org.spf4j.ssdump2.Converter.loadLabeledDumps(file);
        setFrames(loadLabeledDumps, fileName);
    } else if (Spf4jFileFilter.D3_JSON.accept(file)) {
        try (BufferedReader br = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) {
            Pair<Method, SampleNode> parse = SampleNode.parseD3Json(br);
            setFrames(parse.getSecond(), fileName);
        }
    } else if (Spf4jFileFilter.SPF4J_JSON.accept(file)) {
        try (BufferedReader br = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) {
            Pair<Method, SampleNode> parse = SampleNode.parse(br);
            setFrames(parse.getSecond(), fileName);
        }
    } else if (Spf4jFileFilter.PROFILE_AVRO.accept(file)) {
        setFrames(new AvroStackSampleSupplier(file.toPath()), fileName);
    } else {
        throw new IOException("Unsupported file format " + fileName);
    }
}
Also used : AvroStackSampleSupplier(org.spf4j.stackmonitor.AvroStackSampleSupplier) Method(org.spf4j.base.avro.Method) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) BufferedReader(java.io.BufferedReader) SampleNode(org.spf4j.stackmonitor.SampleNode) JInternalFrame(javax.swing.JInternalFrame) Map(java.util.Map) Pair(org.spf4j.base.Pair)

Example 23 with Method

use of org.spf4j.base.avro.Method in project spf4j by zolyfarkas.

the class StackPanelBase method actionPerformed.

@Override
public final void actionPerformed(final ActionEvent e) {
    final String actionCommand = e.getActionCommand();
    switch(actionCommand) {
        case "FILTER":
            history.addLast(Pair.of(method, samples));
            filter();
            break;
        case "DRILL":
            history.addLast(Pair.of(method, samples));
            drill();
            break;
        case "BACK":
            Pair<Method, SampleNode> prev = history.pollLast();
            if (prev != null) {
                updateSamples(prev.getFirst(), prev.getSecond());
                repaint();
            }
            break;
        case "COPY":
            final String detail = getDetail(new Point(xx, yy));
            java.awt.Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new Transferable() {

                @Override
                public DataFlavor[] getTransferDataFlavors() {
                    return new DataFlavor[] { DataFlavor.stringFlavor };
                }

                @Override
                public boolean isDataFlavorSupported(final DataFlavor flavor) {
                    return flavor.equals(DataFlavor.stringFlavor);
                }

                @Override
                public Object getTransferData(final DataFlavor flavor) {
                    return detail;
                }
            }, new ClipboardOwner() {

                @Override
                public void lostOwnership(final Clipboard clipboard, final Transferable contents) {
                }
            });
            break;
        default:
            break;
    }
}
Also used : Transferable(java.awt.datatransfer.Transferable) ClipboardOwner(java.awt.datatransfer.ClipboardOwner) Method(org.spf4j.base.avro.Method) SampleNode(org.spf4j.stackmonitor.SampleNode) Point(java.awt.Point) Clipboard(java.awt.datatransfer.Clipboard) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 24 with Method

use of org.spf4j.base.avro.Method in project spf4j by zolyfarkas.

the class FlameStackPanelTest method testHotStackPanelCycle.

@Test
public void testHotStackPanelCycle() throws IOException, InterruptedException {
    Pair<Method, SampleNode> parse = SampleNode.parse(new StringReader("{\"ROOT@65406@ZMacBookPro-2.local\":2,\"c\":" + "[{\"a@C\":1,\"c\":[{\"b@C\":1}]},{\"b@C\":1,\"c\":[{\"a@C\":1}]}]}"));
    HotFlameStackPanel panel = new HotFlameStackPanel(parse.getFirst(), parse.getSecond(), new LinkedList<>());
    testPanel(panel);
}
Also used : StringReader(java.io.StringReader) Method(org.spf4j.base.avro.Method) SampleNode(org.spf4j.stackmonitor.SampleNode) Test(org.junit.Test)

Example 25 with Method

use of org.spf4j.base.avro.Method in project spf4j by zolyfarkas.

the class Methods method getMethod.

/*
     * this function is to allow reuse of Method instances.
     * not thread safe, use with care, see description for suppressed findbugs bug for more detail.
   */
@SuppressFBWarnings("PMB_POSSIBLE_MEMORY")
public static synchronized Method getMethod(final String className, final String methodName) {
    Map<String, Method> mtom = INSTANCE_REPO.get(className);
    Method result;
    if (mtom == null) {
        mtom = new THashMap<>(5);
        result = new Method(className, methodName);
        mtom.put(methodName, result);
        INSTANCE_REPO.put(className, mtom);
    } else {
        result = mtom.get(methodName);
        if (result == null) {
            result = new Method(className, methodName);
            mtom.put(methodName, result);
        }
    }
    return result;
}
Also used : Method(org.spf4j.base.avro.Method) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

Method (org.spf4j.base.avro.Method)29 Test (org.junit.Test)8 SampleNode (org.spf4j.stackmonitor.SampleNode)8 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)6 Map (java.util.Map)5 TMap (gnu.trove.map.TMap)3 IOException (java.io.IOException)3 Pair (org.spf4j.base.Pair)3 JsonParser (com.fasterxml.jackson.core.JsonParser)2 TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)2 Point (java.awt.Point)2 BufferedReader (java.io.BufferedReader)2 StringReader (java.io.StringReader)2 UncheckedIOException (java.io.UncheckedIOException)2 Nullable (javax.annotation.Nullable)2 StackSampleElement (org.spf4j.base.avro.StackSampleElement)2 AvroStackSampleSupplier (org.spf4j.stackmonitor.AvroStackSampleSupplier)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonToken (com.fasterxml.jackson.core.JsonToken)1 Clipboard (java.awt.datatransfer.Clipboard)1