Skip to content

Commit

Permalink
Add specialized LeanNode for thread-level
Browse files Browse the repository at this point in the history
  • Loading branch information
PhRX committed Feb 1, 2017
1 parent fe19173 commit 8ae98ca
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 28 deletions.
Expand Up @@ -30,13 +30,18 @@ public class AggregationProfile

private Map<Aggregator<?, ?, ?>, Aggregation<?, ?>> cachedAggregations;

public AggregationProfile(LeanProfile sourceProfile)
public AggregationProfile(LeanProfile source)
{
source = sourceProfile;
this.source = source;
fqmnLinks = new HashMap<>();
global = new NumericInfo();
cachedAggregations = new HashMap<>();

// ThreadInfo objects are stored separately in the LeanLogCollector (to avoid the assumption that a ThreadMeta
// will always be emitted before the first sample for the thread comes in), so we put them into the root
// LeanThreadNodes here.
source.getThreads().forEach((id, node) -> node.setThreadInfo(source.getThreadInfo(id)));

aggregateGlobal();
calculateLinks();
}
Expand All @@ -53,7 +58,8 @@ public NumericInfo getGlobalData()

public FqmnLink getFqmnLink(LeanNode node)
{
return fqmnLinks.get(source.getMethodMap().get(node.getFrame().getMethodId()).getFqmn());
return fqmnLinks
.get(source.getMethodInfoMap().get(node.getFrame().getMethodId()).getFqmn());
}

public Map<String, FqmnLink> getFqmnLinks()
Expand Down Expand Up @@ -92,7 +98,7 @@ private void calculateLinks()

private void link(Long threadId, LeanNode node)
{
String fqmn = source.getMethodMap().get(node.getFrame().getMethodId()).getFqmn();
String fqmn = source.getMethodInfoMap().get(node.getFrame().getMethodId()).getFqmn();
FqmnLink link = fqmnLinks.computeIfAbsent(fqmn, FqmnLink::new);

link.addSibling(threadId, node);
Expand Down
Expand Up @@ -14,6 +14,7 @@
import com.insightfullogic.honest_profiler.core.aggregation.result.straight.Tree;
import com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode;
import com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfile;
import com.insightfullogic.honest_profiler.core.profiles.lean.LeanThreadNode;
import com.insightfullogic.honest_profiler.core.profiles.lean.NumericInfo;

/**
Expand Down Expand Up @@ -64,7 +65,7 @@ public Tree<String> aggregate(AggregationProfile source, AggregationProfile inpu
* @return a {@link Node} containing the aggregated thread-level information
*/
private Node<String> getThreadNode(Tree<String> tree, LeanProfile profile, Long threadId,
LeanNode node)
LeanThreadNode node)
{
return new Node<>(profile.getThreadName(threadId), node.getData(), tree);
}
Expand Down
Expand Up @@ -15,6 +15,7 @@
import com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode;
import com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfile;
import com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfileListener;
import com.insightfullogic.honest_profiler.core.profiles.lean.LeanThreadNode;
import com.insightfullogic.honest_profiler.core.profiles.lean.MethodInfo;
import com.insightfullogic.honest_profiler.core.profiles.lean.ThreadInfo;

Expand All @@ -37,7 +38,7 @@ public class LeanLogCollector implements LogEventListener, ProfileSource
private final Map<Long, ThreadInfo> threadMap;
// Maps thread ids to the profile trees for the threads. The root contains
// the Thread-level data, anything below are stackframe-level data.
private final Map<Long, LeanNode> threadData;
private final Map<Long, LeanThreadNode> threadData;

private Deque<StackFrame> stackTrace;

Expand Down Expand Up @@ -100,7 +101,7 @@ public void handle(TraceStart traceStart)
collectThreadDump();

currentNode = threadData
.computeIfAbsent(traceStart.getThreadId(), v -> new LeanNode(null, null));
.computeIfAbsent(traceStart.getThreadId(), v -> new LeanThreadNode());

emitProfileIfNeeded();
stackTrace.clear();
Expand Down
Expand Up @@ -39,7 +39,7 @@ public LeanNode(FrameInfo frame, long nanos, LeanNode parent)
*
* @param source the source SlimNode which is being copied
*/
private LeanNode(LeanNode source, LeanNode newParent)
protected LeanNode(LeanNode source, LeanNode newParent)
{
this.frame = source.frame;
this.data = source.data.copy();
Expand Down
Expand Up @@ -6,52 +6,50 @@
import com.insightfullogic.honest_profiler.core.profiles.Profile;

/**
* Alternative to {@link Profile} which stores/collects all info only once,
* eliminating redundancy. The granularity is at stackframe level, keyed by
* class name, method name, bci and line number.
* Alternative to {@link Profile} which stores/collects all info only once, eliminating redundancy. The granularity is
* at stackframe level, keyed by class name, method name, bci and line number.
*
* Any aggregation other than counts and time addition at the lowest level is
* relegated to post-processing.
* Any aggregation other than counts and time addition at the lowest level is relegated to post-processing.
*/
public class LeanProfile
{
private final Map<Long, MethodInfo> methodMap;
private final Map<Long, ThreadInfo> threadMap;
private final Map<Long, LeanNode> threads;
private final Map<Long, MethodInfo> methodInfoMap;
private final Map<Long, ThreadInfo> threadInfoMap;
private final Map<Long, LeanThreadNode> threads;

public LeanProfile(Map<Long, MethodInfo> methodMap,
Map<Long, ThreadInfo> threadMap,
Map<Long, LeanNode> threadData)
Map<Long, LeanThreadNode> threadData)
{
this.methodMap = new HashMap<>(methodMap);
this.threadMap = new HashMap<>(threadMap);
this.methodInfoMap = new HashMap<>(methodMap);
this.threadInfoMap = new HashMap<>(threadMap);
this.threads = new HashMap<>();
threadData.forEach((key, value) -> this.threads.put(key, value.copy()));
}

public Map<Long, MethodInfo> getMethodMap()
public Map<Long, MethodInfo> getMethodInfoMap()
{
return methodMap;
return methodInfoMap;
}

public Map<Long, ThreadInfo> getThreadMap()
public ThreadInfo getThreadInfo(long id)
{
return threadMap;
return threadInfoMap.get(id);
}

public Map<Long, LeanNode> getThreads()
public Map<Long, LeanThreadNode> getThreads()
{
return threads;
}

public String getFqmn(LeanNode node)
{
return getMethodMap().get(node.getFrame().getMethodId()).getFqmn();
return getMethodInfoMap().get(node.getFrame().getMethodId()).getFqmn();
}

public String getThreadName(Long threadId)
{
ThreadInfo info = getThreadMap().get(threadId);
ThreadInfo info = getThreadInfo(threadId);
return info == null ? "Unknown <" + threadId + ">" : info.getIdentification();
}

Expand All @@ -62,8 +60,8 @@ public String toString()
result.append("LP :\n");
threads.forEach(
(id, node) -> result.append(" Thread ")
.append(threadMap.get(id) == null ? "UNKNOWN" : threadMap.get(id).getName())
.append(node.toDeepString(1, methodMap)));
.append(threadInfoMap.get(id) == null ? "UNKNOWN" : threadInfoMap.get(id).getName())
.append(node.toDeepString(1, methodInfoMap)));
return result.toString();
}
}
@@ -0,0 +1,33 @@
package com.insightfullogic.honest_profiler.core.profiles.lean;

public class LeanThreadNode extends LeanNode
{
private ThreadInfo threadInfo;

public LeanThreadNode()
{
super((FrameInfo)null, null);
}

private LeanThreadNode(LeanThreadNode source)
{
super(source, null);
this.threadInfo = source.threadInfo;
}

public ThreadInfo getThreadInfo()
{
return threadInfo;
}

public void setThreadInfo(ThreadInfo threadInfo)
{
this.threadInfo = threadInfo;
}

@Override
public LeanThreadNode copy()
{
return new LeanThreadNode(this);
}
}

0 comments on commit 8ae98ca

Please sign in to comment.