Skip to content

Commit

Permalink
Everything working again except filtering which needs reimplementation
Browse files Browse the repository at this point in the history
Trying to figure out some differences with the original reporting. There
were some issues at the top-level (thread and the first frame(s) just
underneath) which are now reported more correctly, it seems. At the same
time, some top-level traces hanging off the thread level seem a bit
strange. Still, it might well be what is actually in the log file,
according to the semantics.
  • Loading branch information
PhRX committed Jan 18, 2017
1 parent dfef87c commit 3dff989
Show file tree
Hide file tree
Showing 39 changed files with 835 additions and 400 deletions.
Expand Up @@ -22,9 +22,12 @@
package com.insightfullogic.honest_profiler.core; package com.insightfullogic.honest_profiler.core;


import com.insightfullogic.honest_profiler.core.collector.LogCollector; import com.insightfullogic.honest_profiler.core.collector.LogCollector;
import com.insightfullogic.honest_profiler.core.collector.lean.LeanLogCollector;
import com.insightfullogic.honest_profiler.core.collector.lean.LeanProfileUpdateModerator;
import com.insightfullogic.honest_profiler.core.parser.LogEventListener; import com.insightfullogic.honest_profiler.core.parser.LogEventListener;
import com.insightfullogic.honest_profiler.core.parser.LogParser; import com.insightfullogic.honest_profiler.core.parser.LogParser;
import com.insightfullogic.honest_profiler.core.profiles.ProfileListener; import com.insightfullogic.honest_profiler.core.profiles.ProfileListener;
import com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfileListener;
import com.insightfullogic.honest_profiler.core.sources.LogSource; import com.insightfullogic.honest_profiler.core.sources.LogSource;


import static org.slf4j.LoggerFactory.getLogger; import static org.slf4j.LoggerFactory.getLogger;
Expand All @@ -50,6 +53,15 @@ public static void pipeFile(final LogSource logSource, final ProfileListener lis
new ThreadedAgent(getLogger(ThreadedAgent.class), conductor::poll).start(); new ThreadedAgent(getLogger(ThreadedAgent.class), conductor::poll).start();
} }


public static void pipeFile(final LogSource logSource, LeanLogCollector logCollector, final LeanProfileListener listener)
{
LeanProfileUpdateModerator moderator = new LeanProfileUpdateModerator(getLogger(LeanProfileUpdateModerator.class), listener);
moderator.start();

final Conductor conductor = pipe(logSource, logCollector, true);
new ThreadedAgent(getLogger(ThreadedAgent.class), conductor::poll).start();
}

public static void consumeFile(final LogSource logSource, final ProfileListener listener) public static void consumeFile(final LogSource logSource, final ProfileListener listener)
{ {
pipe(logSource, listener, false).run(); pipe(logSource, listener, false).run();
Expand Down
@@ -1,7 +1,6 @@
package com.insightfullogic.honest_profiler.core.aggregation; package com.insightfullogic.honest_profiler.core.aggregation;


import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;


import com.insightfullogic.honest_profiler.core.aggregation.aggregator.Aggregator; import com.insightfullogic.honest_profiler.core.aggregation.aggregator.Aggregator;
Expand All @@ -19,24 +18,22 @@
*/ */
public class AggregationProfile public class AggregationProfile
{ {
private static final Aggregator<AggregationProfile, List<AggregatedEntry>> flatAggregator = new FlatByFqmnAggregator(); private static final Aggregator<AggregationProfile, String, AggregatedEntry<String>> flatAggregator = new FlatByFqmnAggregator();
private static final Aggregator<AggregationProfile, List<AggregatedNode>> treeAggregator = new TreeByFqmnAggregator(); private static final Aggregator<AggregationProfile, String, AggregatedNode<String>> treeAggregator = new TreeByFqmnAggregator();


private final LeanProfile sourceProfile; private final LeanProfile sourceProfile;
private final Map<String, FqmnLink> fqmnLinks; private final Map<String, FqmnLink> fqmnLinks;
private final Map<Long, LeanNode> threadRoots;


private final LeanNode profileNode; private final LeanNode profileNode;


private Aggregation<List<AggregatedEntry>> flatAggregation; private Aggregation<String, AggregatedEntry<String>> flatAggregation;
private Aggregation<List<AggregatedNode>> treeAggregation; private Aggregation<String, AggregatedNode<String>> treeAggregation;


public AggregationProfile(LeanProfile sourceProfile) public AggregationProfile(LeanProfile sourceProfile)
{ {
this.sourceProfile = sourceProfile; this.sourceProfile = sourceProfile;


fqmnLinks = new HashMap<>(); fqmnLinks = new HashMap<>();
threadRoots = new HashMap<>();


this.profileNode = new LeanNode(null, null); this.profileNode = new LeanNode(null, null);


Expand All @@ -45,7 +42,7 @@ public AggregationProfile(LeanProfile sourceProfile)
aggregate(); aggregate();
} }


public LeanProfile getSourceProfile() public LeanProfile getSource()
{ {
return sourceProfile; return sourceProfile;
} }
Expand All @@ -66,17 +63,12 @@ public Map<String, FqmnLink> getFqmnLinks()
return fqmnLinks; return fqmnLinks;
} }


public Map<Long, LeanNode> getThreadRoots() public Aggregation<String, AggregatedEntry<String>> getFlatAggregation()
{
return threadRoots;
}

public Aggregation<List<AggregatedEntry>> getFlatAggregation()
{ {
return flatAggregation; return flatAggregation;
} }


public Aggregation<List<AggregatedNode>> getTreeAggregation() public Aggregation<String, AggregatedNode<String>> getTreeAggregation()
{ {
return treeAggregation; return treeAggregation;
} }
Expand All @@ -89,7 +81,7 @@ private void aggregate()


private void aggregateTopLevel() private void aggregateTopLevel()
{ {
NumericInfo aggregated = threadRoots.values().stream().collect( NumericInfo aggregated = sourceProfile.getThreads().values().stream().collect(
NumericInfo::new, NumericInfo::new,
(data, node) -> data.add(node.getData()), (data, node) -> data.add(node.getData()),
(data1, data2) -> data1.add(data2)); (data1, data2) -> data1.add(data2));
Expand All @@ -98,12 +90,12 @@ private void aggregateTopLevel()


private void calculateLinks() private void calculateLinks()
{ {
sourceProfile.getThreadData() sourceProfile.getThreads()
.forEach((threadId, threadData) -> threadData.getChildren().forEach( .forEach((threadId, threadData) -> threadData.getChildren().forEach(
node -> threadRoots.put(threadId, link(threadId, node)))); node -> link(threadId, node)));
} }


private LeanNode link(Long threadId, LeanNode node) private void link(Long threadId, LeanNode node)
{ {
String fqmn = sourceProfile.getMethodMap().get(node.getFrame().getMethodId()).getFqmn(); String fqmn = sourceProfile.getMethodMap().get(node.getFrame().getMethodId()).getFqmn();
FqmnLink link = fqmnLinks.computeIfAbsent(fqmn, FqmnLink::new); FqmnLink link = fqmnLinks.computeIfAbsent(fqmn, FqmnLink::new);
Expand All @@ -120,6 +112,7 @@ private LeanNode link(Long threadId, LeanNode node)
getFqmnLink(parent).addChild(threadId, node); getFqmnLink(parent).addChild(threadId, node);
} }
} }
return node;
node.getChildren().forEach(child -> link(threadId, child));
} }
} }
@@ -1,6 +1,7 @@
package com.insightfullogic.honest_profiler.core.aggregation.aggregator; package com.insightfullogic.honest_profiler.core.aggregation.aggregator;


import com.insightfullogic.honest_profiler.core.aggregation.result.Aggregation; import com.insightfullogic.honest_profiler.core.aggregation.result.Aggregation;
import com.insightfullogic.honest_profiler.core.aggregation.result.Keyed;
import com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode; import com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode;


/** /**
Expand All @@ -9,7 +10,7 @@
* @param <I> * @param <I>
* @param <R> * @param <R>
*/ */
public interface Aggregator<I, R> public interface Aggregator<I, K, T extends Keyed<K>>
{ {
Aggregation<R> aggregate(I input, LeanNode reference); Aggregation<K, T> aggregate(I input, LeanNode reference);
} }
Expand Up @@ -10,14 +10,15 @@
import com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode; import com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode;
import com.insightfullogic.honest_profiler.core.profiles.lean.NumericInfo; import com.insightfullogic.honest_profiler.core.profiles.lean.NumericInfo;


public class FlatByFqmnAggregator implements Aggregator<AggregationProfile, List<AggregatedEntry>> public class FlatByFqmnAggregator
implements Aggregator<AggregationProfile, String, AggregatedEntry<String>>
{ {
@Override @Override
public Aggregation<List<AggregatedEntry>> aggregate(AggregationProfile input, public Aggregation<String, AggregatedEntry<String>> aggregate(AggregationProfile input,
LeanNode reference) LeanNode reference)
{ {
List<AggregatedEntry> result = new ArrayList<>(); List<AggregatedEntry<String>> result = new ArrayList<>();
Aggregation<List<AggregatedEntry>> aggregation = new Aggregation<List<AggregatedEntry>>( Aggregation<String, AggregatedEntry<String>> aggregation = new Aggregation<>(
result, result,
reference); reference);


Expand All @@ -27,7 +28,7 @@ public Aggregation<List<AggregatedEntry>> aggregate(AggregationProfile input,
.map(LeanNode::getData) .map(LeanNode::getData)
.collect(NumericInfo::new, (x, y) -> x.add(y), (x, y) -> x.add(y)); .collect(NumericInfo::new, (x, y) -> x.add(y), (x, y) -> x.add(y));


result.add(new AggregatedEntry(link.getFqmn(), sum, aggregation)); result.add(new AggregatedEntry<>(link.getFqmn(), sum, aggregation));
}); });


return aggregation; return aggregation;
Expand Down
Expand Up @@ -14,67 +14,67 @@
import com.insightfullogic.honest_profiler.core.aggregation.result.Aggregation; import com.insightfullogic.honest_profiler.core.aggregation.result.Aggregation;
import com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode; 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.LeanProfile;
import com.insightfullogic.honest_profiler.core.profiles.lean.NumericInfo;


public class TreeByFqmnAggregator implements Aggregator<AggregationProfile, List<AggregatedNode>> public class TreeByFqmnAggregator
implements Aggregator<AggregationProfile, String, AggregatedNode<String>>
{ {
@Override @Override
public Aggregation<List<AggregatedNode>> aggregate(AggregationProfile input, LeanNode reference) public Aggregation<String, AggregatedNode<String>> aggregate(AggregationProfile input,
LeanNode reference)
{ {


List<AggregatedNode> threadNodes = new ArrayList<>(); List<AggregatedNode<String>> nodes = new ArrayList<>();
Aggregation<List<AggregatedNode>> aggregation = new Aggregation<List<AggregatedNode>>( Aggregation<String, AggregatedNode<String>> result = new Aggregation<>(nodes, reference);
threadNodes,
reference);


input.getThreadRoots().forEach((threadId, threadNode) -> LeanProfile source = input.getSource();

input.getSource().getThreads().forEach((threadId, threadNode) ->
{ {
AggregatedNode threadAggregatedNode = getThreadNode( AggregatedNode<String> node = getThreadNode(result, source, threadId, threadNode);
aggregation, nodes.add(node);
input.getSourceProfile(), add(result, source, node, threadNode);
threadId);
threadNodes.add(threadAggregatedNode);
add(aggregation, input.getSourceProfile(), threadAggregatedNode, threadNode);
}); });


return aggregation; return result;
} }


private AggregatedNode getThreadNode(Aggregation<List<AggregatedNode>> aggregation, private AggregatedNode<String> getThreadNode(
LeanProfile profile, Long threadId) Aggregation<String, AggregatedNode<String>> aggregation, LeanProfile profile, Long threadId,
LeanNode node)
{ {
String name = profile.getThreadMap().get(threadId).getName(); AggregatedEntry<String> entry = new AggregatedEntry<>(
NumericInfo data = profile.getThreadData().values().stream().findFirst().get().getData(); profile.getThreadName(threadId),
AggregatedEntry threadEntry = new AggregatedEntry(name, data, aggregation); node.getData(),
return new AggregatedNode(threadEntry); aggregation);
return new AggregatedNode<>(entry);
} }


private void add(Aggregation<List<AggregatedNode>> aggregation, LeanProfile profile, private void add(Aggregation<String, AggregatedNode<String>> aggregation, LeanProfile profile,
AggregatedNode parentAggregation, LeanNode parent) AggregatedNode<String> parentAggregation, LeanNode parent)
{ {
Map<String, AggregatedNode> nodeMap = parent.getChildren().stream().collect( Map<String, AggregatedNode<String>> nodeMap = parent.getChildren().stream().collect(
groupingBy( groupingBy(
node -> profile.getMethodMap().get(node.getFrame().getMethodId()).getFqmn(), node -> profile.getFqmn(node),
getAggrCollector(aggregation, profile))); getAggrCollector(aggregation, profile)));
parentAggregation.getChildren().addAll(nodeMap.values()); parentAggregation.getChildren().addAll(nodeMap.values());
} }


private Collector<LeanNode, AggregatedNode, AggregatedNode> getAggrCollector( private Collector<LeanNode, AggregatedNode<String>, AggregatedNode<String>> getAggrCollector(
Aggregation<List<AggregatedNode>> aggregation, LeanProfile profile) Aggregation<String, AggregatedNode<String>> aggregation, LeanProfile profile)
{ {
// The key has to be specified in the update. I couldn't find a way to // The key has to be specified in the update. I couldn't find a way to
// easily or elegantly recuperate the String from the enclosing // easily or elegantly recuperate the String from the enclosing
// groupingBy(). // groupingBy().
return of( return of(
() -> new AggregatedNode(aggregation), () -> new AggregatedNode<>(aggregation),
(AggregatedNode entry, LeanNode node) -> (entry, node) ->
{ {
entry.add( entry.add(
profile.getFqmn(node), profile.getFqmn(node),
node.getFrame(), node.getFrame(),
node.getData()); node.getData());
add(aggregation, profile, entry, node); add(aggregation, profile, entry, node);
}, },
(AggregatedNode e1, AggregatedNode e2) -> e1.combine(e2)); (e1, e2) -> e1.combine(e2));
} }
} }
@@ -0,0 +1,50 @@
package com.insightfullogic.honest_profiler.core.aggregation.result;

import com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode;
import com.insightfullogic.honest_profiler.core.profiles.lean.NumericInfo;

public abstract class AbstractDiffAggregation<K, T extends Keyed<K>>
{
private Aggregation<K, T> baseAggregation;
private Aggregation<K, T> newAggregation;

protected void setBaseAggregation(Aggregation<K, T> baseAggregation)
{
this.baseAggregation = baseAggregation;
}

protected void setNewAggregation(Aggregation<K, T> newAggregation)
{
this.newAggregation = newAggregation;
}

public LeanNode getBaseReference()
{
return baseAggregation.getReference();
}

public NumericInfo getBaseReferenceData()
{
return baseAggregation.getReferenceData();
}

public void setBaseReference(LeanNode reference)
{
baseAggregation.setReference(reference);
}

public LeanNode getNewReference()
{
return newAggregation.getReference();
}

public NumericInfo getNewReferenceData()
{
return newAggregation.getReferenceData();
}

public void setNewReference(LeanNode reference)
{
newAggregation.setReference(reference);
}
}
Expand Up @@ -5,30 +5,55 @@
/** /**
* Provides the difference between two {@link AggregatedEntry}s. * Provides the difference between two {@link AggregatedEntry}s.
*/ */
public class AggregatedDiffEntry public class AggregatedDiffEntry<K> implements Keyed<K>
{ {
private final AggregatedEntry baseEntry; private AggregatedEntry<K> baseEntry;
private final AggregatedEntry newEntry; private AggregatedEntry<K> newEntry;


public AggregatedDiffEntry(AggregatedEntry baseEntry, AggregatedEntry newEntry) public AggregatedDiffEntry(AggregatedEntry<K> baseEntry, AggregatedEntry<K> newEntry)
{ {
this.baseEntry = baseEntry; this.baseEntry = baseEntry == null ? new AggregatedEntry<K>(newEntry.getKey(), null)
this.newEntry = newEntry; : baseEntry;
this.newEntry = newEntry == null ? new AggregatedEntry<K>(baseEntry.getKey(), null)
: newEntry;
} }


public AggregatedEntry getBaseEntry() public AggregatedDiffEntry<K> setBase(AggregatedEntry<K> entry)
{
baseEntry = entry;
return this;
}

public AggregatedDiffEntry<K> setNew(AggregatedEntry<K> entry)
{
newEntry = entry;
return this;
}

public void addBase(NumericInfo data)
{
baseEntry.getData().add(data);
}

public void addNew(NumericInfo data)
{
newEntry.getData().add(data);
}

public AggregatedEntry<K> getBaseEntry()
{ {
return baseEntry; return baseEntry;
} }


public AggregatedEntry getNewEntry() public AggregatedEntry<K> getNewEntry()
{ {
return newEntry; return newEntry;
} }


public String getKey() @Override
public K getKey()
{ {
return baseEntry.getKey(); return baseEntry == null ? newEntry.getKey() : baseEntry.getKey();
} }


public NumericInfo getBaseData() public NumericInfo getBaseData()
Expand Down

0 comments on commit 3dff989

Please sign in to comment.