Search in sources :

Example 1 with Method

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

the class SampleNode method addSample.

void addSample(final StackTraceElement[] stackTrace, final int from) {
    sampleCount++;
    if (from >= 0) {
        Method method = Method.getMethod(stackTrace[from]);
        SampleNode subNode = null;
        if (subNodes == null) {
            subNodes = new THashMap(4);
        } else {
            subNode = subNodes.get(method);
        }
        if (subNode == null) {
            subNodes.put(method, new SampleNode(stackTrace, from - 1));
        } else {
            subNode.addSample(stackTrace, from - 1);
        }
    }
}
Also used : THashMap(gnu.trove.map.hash.THashMap) Method(org.spf4j.base.Method)

Example 2 with Method

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

the class Converter method convert.

public static SampleNode convert(final Iterator<ASample> samples) {
    TIntObjectMap<SampleNode> index = new TIntObjectHashMap<>();
    while (samples.hasNext()) {
        ASample asmp = samples.next();
        SampleNode sn = new SampleNode(asmp.count, new THashMap<Method, SampleNode>(4));
        SampleNode parent = index.get(asmp.parentId);
        if (parent != null) {
            AMethod method = asmp.getMethod();
            Method m = Method.getMethod(method.declaringClass, method.getName());
            final Map<Method, SampleNode> subNodes = parent.getSubNodes();
            if (subNodes == null) {
                throw new IllegalStateException("Bug, state " + index + "; at node " + asmp);
            }
            subNodes.put(m, sn);
        }
        index.put(asmp.id, sn);
    }
    return index.get(0);
}
Also used : TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) ASample(org.spf4j.ssdump2.avro.ASample) SampleNode(org.spf4j.stackmonitor.SampleNode) Method(org.spf4j.base.Method) AMethod(org.spf4j.ssdump2.avro.AMethod) AMethod(org.spf4j.ssdump2.avro.AMethod)

Example 3 with Method

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

the class Converter method convert.

public static <E extends Exception> int convert(final Method method, final SampleNode node, final int parentId, final int id, final Handler<ASample, E> handler) throws E {
    final Deque<TraversalNode> dq = new ArrayDeque<>();
    dq.addLast(new TraversalNode(method, node, parentId));
    int nid = id;
    while (!dq.isEmpty()) {
        TraversalNode first = dq.removeFirst();
        Method m = first.getMethod();
        ASample sample = new ASample();
        sample.id = nid;
        SampleNode n = first.getNode();
        sample.count = n.getSampleCount();
        AMethod am = new AMethod();
        am.setName(m.getMethodName());
        am.setDeclaringClass(m.getDeclaringClass());
        sample.method = am;
        sample.parentId = first.getParentId();
        final TMap<Method, SampleNode> subNodes = n.getSubNodes();
        final int pid = nid;
        if (subNodes != null) {
            subNodes.forEachEntry((a, b) -> {
                dq.addLast(new TraversalNode(a, b, pid));
                return true;
            });
        }
        handler.handle(sample, parentId);
        nid++;
    }
    return nid;
}
Also used : ASample(org.spf4j.ssdump2.avro.ASample) Method(org.spf4j.base.Method) AMethod(org.spf4j.ssdump2.avro.AMethod) SampleNode(org.spf4j.stackmonitor.SampleNode) AMethod(org.spf4j.ssdump2.avro.AMethod) ArrayDeque(java.util.ArrayDeque)

Example 4 with Method

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

the class SampleNode method forEach.

public void forEach(final InvocationHandler handler, final Method from, final Method to, final Map<Method, Integer> ancestors) {
    handler.handle(from, to, sampleCount, ancestors);
    if (subNodes != null) {
        Integer val = ancestors.get(to);
        if (val != null) {
            val = val + 1;
        } else {
            val = 1;
        }
        ancestors.put(to, val);
        for (Map.Entry<Method, SampleNode> subs : subNodes.entrySet()) {
            Method toKey = subs.getKey();
            subs.getValue().forEach(handler, to, toKey, ancestors);
        }
        val = ancestors.get(to);
        if (val == 1) {
            ancestors.remove(to);
        } else {
            val = val - 1;
            ancestors.put(to, val);
        }
    }
}
Also used : Method(org.spf4j.base.Method) TMap(gnu.trove.map.TMap) HashMap(java.util.HashMap) Map(java.util.Map) THashMap(gnu.trove.map.hash.THashMap)

Example 5 with Method

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

the class MethodTest method testSomeMethod.

@Test
@SuppressFBWarnings("PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS")
public void testSomeMethod() {
    Method m1 = Method.getMethod("a", "b");
    Method m2 = Method.getMethod("a", "b");
    Assert.assertTrue(m1 == m2);
    Assert.assertEquals(m2, m1);
    Assert.assertEquals("a", m1.getDeclaringClass());
    Assert.assertEquals("b", m1.getMethodName());
    Assert.assertEquals(m1, Method.from(m1.toString()));
}
Also used : Method(org.spf4j.base.Method) Test(org.junit.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

Method (org.spf4j.base.Method)5 THashMap (gnu.trove.map.hash.THashMap)2 AMethod (org.spf4j.ssdump2.avro.AMethod)2 ASample (org.spf4j.ssdump2.avro.ASample)2 SampleNode (org.spf4j.stackmonitor.SampleNode)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 TMap (gnu.trove.map.TMap)1 TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)1 ArrayDeque (java.util.ArrayDeque)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1