-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor sampler node export process
- Loading branch information
Showing
19 changed files
with
490 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
spark-common/src/main/java/me/lucko/spark/common/sampler/async/AsyncNodeExporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* This file is part of spark. | ||
* | ||
* Copyright (c) lucko (Luck) <[email protected]> | ||
* Copyright (c) contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package me.lucko.spark.common.sampler.async; | ||
|
||
import me.lucko.spark.common.sampler.node.StackTraceNode; | ||
import me.lucko.spark.common.sampler.node.exporter.AbstractNodeExporter; | ||
import me.lucko.spark.common.sampler.window.ProtoTimeEncoder; | ||
import me.lucko.spark.proto.SparkSamplerProtos; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Node exporter for the {@link AsyncSampler}. | ||
*/ | ||
public class AsyncNodeExporter extends AbstractNodeExporter { | ||
public AsyncNodeExporter(ProtoTimeEncoder timeEncoder) { | ||
super(timeEncoder); | ||
} | ||
|
||
@Override | ||
protected SparkSamplerProtos.StackTraceNode export(StackTraceNode stackTraceNode, Iterable<Integer> childrenRefs) { | ||
SparkSamplerProtos.StackTraceNode.Builder proto = SparkSamplerProtos.StackTraceNode.newBuilder() | ||
.setClassName(stackTraceNode.getClassName()) | ||
.setMethodName(stackTraceNode.getMethodName()); | ||
|
||
double[] times = stackTraceNode.encodeTimesForProto(this.timeEncoder); | ||
for (double time : times) { | ||
proto.addTimes(time); | ||
} | ||
|
||
String methodDescription = stackTraceNode.getMethodDescription(); | ||
if (methodDescription != null) { | ||
proto.setMethodDesc(methodDescription); | ||
} | ||
|
||
proto.addAllChildrenRefs(childrenRefs); | ||
|
||
return proto.build(); | ||
} | ||
|
||
@Override | ||
protected Collection<StackTraceNode> exportChildren(Collection<StackTraceNode> children) { | ||
return children; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
spark-common/src/main/java/me/lucko/spark/common/sampler/java/JavaNodeExporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* This file is part of spark. | ||
* | ||
* Copyright (c) lucko (Luck) <[email protected]> | ||
* Copyright (c) contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package me.lucko.spark.common.sampler.java; | ||
|
||
import me.lucko.spark.common.sampler.node.StackTraceNode; | ||
import me.lucko.spark.common.sampler.node.exporter.AbstractNodeExporter; | ||
import me.lucko.spark.common.sampler.window.ProtoTimeEncoder; | ||
import me.lucko.spark.common.util.MethodDisambiguator; | ||
import me.lucko.spark.proto.SparkSamplerProtos; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* Node exporter for the {@link JavaSampler}. | ||
*/ | ||
public class JavaNodeExporter extends AbstractNodeExporter { | ||
private final MergeStrategy mergeStrategy; | ||
private final MethodDisambiguator methodDisambiguator; | ||
|
||
public JavaNodeExporter(ProtoTimeEncoder timeEncoder, MergeStrategy mergeStrategy, MethodDisambiguator methodDisambiguator) { | ||
super(timeEncoder); | ||
this.mergeStrategy = mergeStrategy; | ||
this.methodDisambiguator = methodDisambiguator; | ||
} | ||
|
||
protected SparkSamplerProtos.StackTraceNode export(StackTraceNode stackTraceNode, Iterable<Integer> childrenRefs) { | ||
SparkSamplerProtos.StackTraceNode.Builder proto = SparkSamplerProtos.StackTraceNode.newBuilder() | ||
.setClassName(stackTraceNode.getClassName()) | ||
.setMethodName(stackTraceNode.getMethodName()); | ||
|
||
double[] times = stackTraceNode.encodeTimesForProto(this.timeEncoder); | ||
for (double time : times) { | ||
proto.addTimes(time); | ||
} | ||
|
||
int lineNumber = stackTraceNode.getLineNumber(); | ||
if (lineNumber >= 0) { | ||
proto.setLineNumber(lineNumber); | ||
} | ||
|
||
if (this.mergeStrategy.separateParentCalls()) { | ||
int parentLineNumber = stackTraceNode.getParentLineNumber(); | ||
if (parentLineNumber >= 0) { | ||
proto.setParentLineNumber(parentLineNumber); | ||
} | ||
} | ||
|
||
this.methodDisambiguator.disambiguate(stackTraceNode) | ||
.map(MethodDisambiguator.MethodDescription::getDescription) | ||
.ifPresent(proto::setMethodDesc); | ||
|
||
proto.addAllChildrenRefs(childrenRefs); | ||
|
||
return proto.build(); | ||
} | ||
|
||
@Override | ||
protected Collection<StackTraceNode> exportChildren(Collection<StackTraceNode> children) { | ||
if (children.isEmpty()) { | ||
return children; | ||
} | ||
|
||
List<StackTraceNode> list = new ArrayList<>(children.size()); | ||
|
||
outer: | ||
for (StackTraceNode child : children) { | ||
for (StackTraceNode other : list) { | ||
if (this.mergeStrategy.shouldMerge(this.methodDisambiguator, other, child)) { | ||
other.merge(child); | ||
continue outer; | ||
} | ||
} | ||
list.add(child); | ||
} | ||
return list; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.