This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch collector/instrument
in repository https://gitbox.apache.org/repos/asf/incubator-skywalking.git
The following commit(s) were added to refs/heads/collector/instrument by this
push:
new ef73903 Finish the instrument
ef73903 is described below
commit ef7390349369f2ee2a4090ce940c7fadf43252d7
Author: wu-sheng <[email protected]>
AuthorDate: Wed Jan 10 11:19:13 2018 +0800
Finish the instrument
---
.../parser/provider/parser/SegmentParse.java | 9 +-
.../apm/collector/instrument/MetricTree.java | 129 +++++++--------------
.../apm/collector/instrument/ReportWriter.java | 3 -
.../apm/collector/instrument/ServiceMetric.java | 19 ++-
.../instrument/ServiceMetricBatchRecord.java | 3 +
.../collector/instrument/ServiceMetricRecord.java | 4 -
.../collector/instrument/ServiceMetricTracing.java | 14 ++-
7 files changed, 76 insertions(+), 105 deletions(-)
diff --git
a/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/parser/SegmentParse.java
b/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/parser/SegmentParse.java
index 84eb3b9..4530400 100644
---
a/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/parser/SegmentParse.java
+++
b/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/parser/SegmentParse.java
@@ -36,6 +36,7 @@ import
org.apache.skywalking.apm.collector.analysis.segment.parser.provider.pars
import
org.apache.skywalking.apm.collector.analysis.segment.parser.provider.parser.standardization.SegmentStandardization;
import
org.apache.skywalking.apm.collector.analysis.segment.parser.provider.parser.standardization.SpanIdExchanger;
import org.apache.skywalking.apm.collector.core.UnexpectedException;
+import
org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
import org.apache.skywalking.apm.collector.core.graph.Graph;
import org.apache.skywalking.apm.collector.core.graph.GraphManager;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
@@ -67,7 +68,7 @@ public class SegmentParse {
this.spanListeners = new LinkedList<>();
}
-// @GraphComputingMetric(name = "/segment/parse")
+ @GraphComputingMetric(name = "/segment/parse")
public boolean parse(UpstreamSegment segment, ISegmentParseService.Source
source) {
createSpanListeners();
@@ -96,7 +97,7 @@ public class SegmentParse {
return false;
}
-// @GraphComputingMetric(name = "/segment/parse/preBuild")
+ @GraphComputingMetric(name = "/segment/parse/preBuild")
private boolean preBuild(List<UniqueId> traceIds, SegmentDecorator
segmentDecorator) {
StringBuilder segmentIdBuilder = new StringBuilder();
@@ -163,7 +164,7 @@ public class SegmentParse {
return true;
}
-// @GraphComputingMetric(name = "/segment/parse/buildSegment")
+ @GraphComputingMetric(name = "/segment/parse/buildSegment")
private void buildSegment(String id, byte[] dataBinary) {
Segment segment = new Segment(id);
segment.setDataBinary(dataBinary);
@@ -172,7 +173,7 @@ public class SegmentParse {
graph.start(segment);
}
-// @GraphComputingMetric(name = "/segment/parse/bufferFile/write")
+ @GraphComputingMetric(name = "/segment/parse/bufferFile/write")
private void writeToBufferFile(String id, UpstreamSegment upstreamSegment)
{
logger.debug("push to segment buffer write worker, id: {}", id);
SegmentStandardization standardization = new
SegmentStandardization(id);
diff --git
a/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/MetricTree.java
b/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/MetricTree.java
index c86a7d0..b0b5a77 100644
---
a/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/MetricTree.java
+++
b/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/MetricTree.java
@@ -37,8 +37,8 @@ public enum MetricTree implements Runnable {
INSTANCE;
private final Logger logger = LoggerFactory.getLogger(MetricTree.class);
- private MetricNode root = new MetricNode("/", "/");
private ScheduledFuture<?> scheduledFuture;
+ private List<MetricNode> metrics = new LinkedList<>();
private String lineSeparator = System.getProperty("line.separator");
MetricTree() {
@@ -47,153 +47,114 @@ public enum MetricTree implements Runnable {
}
synchronized MetricNode lookup(String metricName) {
- String[] metricSections = metricName.split("/");
- MetricNode node = root;
- for (String metricSection : metricSections) {
- node = node.addChild(metricSection, metricName);
- }
+ MetricNode node = new MetricNode(metricName);
+ metrics.add(node);
return node;
}
@Override
public void run() {
- root.exchange();
-
try {
- Thread.sleep(5 * 1000);
- } catch (InterruptedException e) {
+ metrics.forEach((metric) -> {
+ metric.exchange();
+ });
- }
+ try {
+ Thread.sleep(5 * 1000);
+ } catch (InterruptedException e) {
- StringBuilder logBuffer = new StringBuilder();
- logBuffer.append(lineSeparator);
-
logBuffer.append("##################################################################################################################").append(lineSeparator);
- logBuffer.append("#
Collector Service Report
#").append(lineSeparator);
-
logBuffer.append("##################################################################################################################").append(lineSeparator);
- root.toOutput(new ReportWriter() {
- private int stackDepth = 0;
-
- @Override public void writeMetricName(String name) {
- for (int i = 0; i < stackDepth; i++) {
- logBuffer.append("\t");
- }
- logBuffer.append(name).append("").append(lineSeparator);
}
- @Override public void writeMetric(String metrics) {
- for (int i = 0; i < stackDepth; i++) {
- logBuffer.append("\t");
- }
- logBuffer.append("\t");
- logBuffer.append(metrics).append("").append(lineSeparator);
- }
+ StringBuilder logBuffer = new StringBuilder();
+ logBuffer.append(lineSeparator);
+
logBuffer.append("##################################################################################################################").append(lineSeparator);
+ logBuffer.append("#
Collector Service Report
#").append(lineSeparator);
+
logBuffer.append("##################################################################################################################").append(lineSeparator);
+ metrics.forEach((metric) -> {
+ metric.toOutput(new ReportWriter() {
- @Override public void prepare4Child() {
- stackDepth++;
- }
+ @Override public void writeMetricName(String name) {
+
logBuffer.append(name).append("").append(lineSeparator);
+ }
- @Override public void finished() {
- stackDepth--;
- }
- });
+ @Override public void writeMetric(String metrics) {
+ logBuffer.append("\t");
+
logBuffer.append(metrics).append("").append(lineSeparator);
+ }
+ });
+ });
- logger.warn(logBuffer.toString());
+ logger.warn(logBuffer.toString());
+ } catch (Throwable e) {
+ logger.error(e.getMessage(), e);
+ }
}
class MetricNode {
- private String nodeName;
private String metricName;
private volatile ServiceMetric metric;
- private List<MetricNode> childs = new LinkedList<>();
- public MetricNode(String nodeName, String metricName) {
- this.nodeName = nodeName;
+ public MetricNode(String metricName) {
this.metricName = metricName;
-
}
ServiceMetric getMetric(Method targetMethod, Object[] allArguments) {
if (metric == null) {
- synchronized (nodeName) {
+ synchronized (metricName) {
if (metric == null) {
- boolean isBatchDetected = false;
+ int detectedBatchIndex = -1;
+ String batchNodeNameSuffix = null;
if (targetMethod != null) {
Annotation[][] annotations =
targetMethod.getParameterAnnotations();
if (annotations != null) {
int index = 0;
for (Annotation[] parameterAnnotation :
annotations) {
- boolean found = false;
if (parameterAnnotation != null) {
for (Annotation annotation :
parameterAnnotation) {
if (annotation instanceof
BatchParameter) {
- isBatchDetected = true;
- found = true;
+ detectedBatchIndex = index;
break;
}
}
}
- if(found){
+ if (detectedBatchIndex > -1) {
break;
}
index++;
}
- if (isBatchDetected) {
+ if (detectedBatchIndex > -1) {
Object listArgs = allArguments[index];
if (listArgs instanceof List) {
List args = (List)listArgs;
- metricName += "/" +
args.get(0).getClass().getSimpleName();
+ batchNodeNameSuffix = "/" +
args.get(0).getClass().getSimpleName();
+ metricName += batchNodeNameSuffix;
}
}
}
}
- metric = new ServiceMetric(metricName,
isBatchDetected);
+ metric = new ServiceMetric(metricName,
detectedBatchIndex);
+ if (batchNodeNameSuffix != null) {
+ this.metricName += batchNodeNameSuffix;
+ }
}
}
}
return metric;
}
- MetricNode addChild(String nodeName, String metricName) {
- MetricNode childNode = new MetricNode(nodeName, metricName);
- this.childs.add(childNode);
- return childNode;
- }
-
void exchange() {
if (metric != null) {
metric.exchangeWindows();
}
- if (childs.size() > 0) {
- for (MetricNode child : childs) {
- child.exchange();
- }
- }
}
void toOutput(ReportWriter writer) {
- if (!nodeName.equals("/")) {
- writer.writeMetricName(nodeName);
- if (metric != null) {
- metric.toOutput(writer);
- }
- if (childs.size() > 0) {
- for (MetricNode child : childs) {
- writer.prepare4Child();
- child.toOutput(writer);
- writer.finished();
- }
- }
- } else {
- writer.writeMetricName("/");
- if (childs.size() > 0) {
- for (MetricNode child : childs) {
- child.toOutput(writer);
- }
- }
+ writer.writeMetricName(metricName);
+ if (metric != null) {
+ metric.toOutput(writer);
}
-
}
}
}
diff --git
a/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ReportWriter.java
b/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ReportWriter.java
index cb7e342..38f36eb 100644
---
a/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ReportWriter.java
+++
b/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ReportWriter.java
@@ -26,7 +26,4 @@ public interface ReportWriter {
void writeMetric(String metrics);
- void prepare4Child();
-
- void finished();
}
diff --git
a/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceMetric.java
b/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceMetric.java
index afae79d..afd970a 100644
---
a/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceMetric.java
+++
b/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceMetric.java
@@ -18,6 +18,8 @@
package org.apache.skywalking.apm.collector.instrument;
+import java.util.List;
+
/**
* @author wusheng
*/
@@ -26,17 +28,24 @@ public class ServiceMetric {
private ServiceMetricRecord winA;
private ServiceMetricRecord winB;
private volatile boolean isUsingWinA;
+ private volatile int detectedBatchIndex;
- ServiceMetric(String metricName, boolean isBatchDetected) {
+ ServiceMetric(String metricName, int detectedBatchIndex) {
this.metricName = metricName;
- winA = isBatchDetected ? new ServiceMetricBatchRecord() : new
ServiceMetricRecord();
- winB = isBatchDetected ? new ServiceMetricBatchRecord() : new
ServiceMetricRecord();
+ winA = detectedBatchIndex > -1 ? new ServiceMetricBatchRecord() : new
ServiceMetricRecord();
+ winB = detectedBatchIndex > -1 ? new ServiceMetricBatchRecord() : new
ServiceMetricRecord();
isUsingWinA = true;
+ this.detectedBatchIndex = detectedBatchIndex;
}
- public void trace(long nano, boolean occurException) {
+ public void trace(long nano, boolean occurException, Object[]
allArguments) {
ServiceMetricRecord usingRecord = isUsingWinA ? winA : winB;
- usingRecord.add(nano, occurException);
+ if (detectedBatchIndex > -1) {
+ List listArgs = (List)allArguments[detectedBatchIndex];
+ ((ServiceMetricBatchRecord)usingRecord).add(nano, occurException,
listArgs == null ? 0 : listArgs.size());
+ } else {
+ usingRecord.add(nano, occurException);
+ }
}
void exchangeWindows() {
diff --git
a/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceMetricBatchRecord.java
b/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceMetricBatchRecord.java
index 923ba72..a9a0cbd 100644
---
a/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceMetricBatchRecord.java
+++
b/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceMetricBatchRecord.java
@@ -43,6 +43,9 @@ public class ServiceMetricBatchRecord extends
ServiceMetricRecord {
@Override
public String toString() {
+ if (counter.longValue() == 0) {
+ return "Avg=N/A";
+ }
return super.toString() + " Rows per call = " + (batchRowSize.get() /
counter.get());
}
}
diff --git
a/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceMetricRecord.java
b/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceMetricRecord.java
index 3bd9b95..31ade89 100644
---
a/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceMetricRecord.java
+++
b/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceMetricRecord.java
@@ -34,10 +34,6 @@ public class ServiceMetricRecord {
errorCounter = new AtomicLong(0);
}
- private boolean isExecuted() {
- return counter.get() > 0;
- }
-
void add(long nano, boolean occurException) {
totalTimeNano.addAndGet(nano);
counter.incrementAndGet();
diff --git
a/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceMetricTracing.java
b/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceMetricTracing.java
index 9b2e59c..9462961 100644
---
a/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceMetricTracing.java
+++
b/apm-collector/apm-collector-instrument/src/main/java/org/apache/skywalking/apm/collector/instrument/ServiceMetricTracing.java
@@ -25,6 +25,7 @@ import
net.bytebuddy.implementation.bind.annotation.AllArguments;
import net.bytebuddy.implementation.bind.annotation.Origin;
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
import net.bytebuddy.implementation.bind.annotation.SuperCall;
+import net.bytebuddy.implementation.bind.annotation.This;
import
org.apache.skywalking.apm.collector.core.annotations.trace.GraphComputingMetric;
/**
@@ -38,6 +39,7 @@ public class ServiceMetricTracing {
@RuntimeType
public Object intercept(
+ @This Object inst,
@SuperCall Callable<?> zuper,
@AllArguments Object[] allArguments,
@Origin Method method
@@ -46,10 +48,12 @@ public class ServiceMetricTracing {
if (metric == null) {
GraphComputingMetric annotation =
method.getAnnotation(GraphComputingMetric.class);
String metricName = annotation.name();
- MetricTree.MetricNode metricNode =
MetricTree.INSTANCE.lookup(metricName);
- ServiceMetric serviceMetric = metricNode.getMetric(method,
allArguments);
- metrics.put(method, serviceMetric);
- metric = serviceMetric;
+ synchronized (inst) {
+ MetricTree.MetricNode metricNode =
MetricTree.INSTANCE.lookup(metricName);
+ ServiceMetric serviceMetric = metricNode.getMetric(method,
allArguments);
+ metrics.put(method, serviceMetric);
+ metric = serviceMetric;
+ }
}
boolean occurError = false;
long startNano = System.nanoTime();
@@ -62,7 +66,7 @@ public class ServiceMetricTracing {
} finally {
endNano = System.nanoTime();
- metric.trace(endNano - startNano, occurError);
+ metric.trace(endNano - startNano, occurError, allArguments);
}
}
}
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].