From 3bede7750e3758dbbd8b268fbc0f2410ca5bac03 Mon Sep 17 00:00:00 2001 From: Daniel Mitterdorfer Date: Thu, 1 Feb 2024 11:11:26 +0100 Subject: [PATCH] More tracing --- .../profiling/GetFlamegraphResponse.java | 50 +++++++++++++++++++ .../TransportGetFlamegraphAction.java | 3 ++ 2 files changed, 53 insertions(+) diff --git a/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/GetFlamegraphResponse.java b/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/GetFlamegraphResponse.java index 0b815283e549a..5b671e7177528 100644 --- a/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/GetFlamegraphResponse.java +++ b/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/GetFlamegraphResponse.java @@ -241,6 +241,7 @@ public Iterator toXContentChunked(ToXContent.Params params @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); + traceStart("Edges"); builder.startArray("Edges"); for (Map edge : edges) { builder.startArray(); @@ -250,26 +251,67 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.endArray(); } builder.endArray(); + traceStop("Edges"); + traceStart("FileID"); builder.field("FileID", fileIds); + traceStop("FileID"); + traceStart("FrameType"); builder.field("FrameType", frameTypes); + traceStop("FrameType"); + traceStart("Inline"); builder.field("Inline", inlineFrames); + traceStop("Inline"); + traceStart("ExeFilename"); builder.field("ExeFilename", fileNames); + traceStop("ExeFilename"); + traceStart("AddressOrLine"); builder.field("AddressOrLine", addressOrLines); + traceStop("AddressOrLine"); + traceStart("FunctionName"); builder.field("FunctionName", functionNames); + traceStop("FunctionName"); + traceStart("FunctionOffset"); builder.field("FunctionOffset", functionOffsets); + traceStop("FunctionOffset"); + traceStart("SourceFilename"); builder.field("SourceFilename", sourceFileNames); + traceStop("SourceFilename"); + traceStart("SourceLine"); builder.field("SourceLine", sourceLines); + traceStop("SourceLine"); + traceStart("CountInclusive"); builder.field("CountInclusive", countInclusive); + traceStop("CountInclusive"); + traceStart("CountExclusive"); builder.field("CountExclusive", countExclusive); + traceStop("CountExclusive"); + traceStart("AnnualCO2TonsInclusive"); builder.field("AnnualCO2TonsInclusive", annualCO2TonsInclusive); + traceStop("AnnualCO2TonsInclusive"); + traceStart("AnnualCO2TonsExclusive"); builder.field("AnnualCO2TonsExclusive", annualCO2TonsExclusive); + traceStop("AnnualCO2TonsExclusive"); + traceStart("AnnualCostsUSDInclusive"); builder.field("AnnualCostsUSDInclusive", annualCostsUSDInclusive); + traceStop("AnnualCostsUSDInclusive"); + traceStart("AnnualCostsUSDExclusive"); builder.field("AnnualCostsUSDExclusive", annualCostsUSDExclusive); + traceStop("AnnualCostsUSDExclusive"); + traceStart("Size"); builder.field("Size", size); + traceStop("Size"); + traceStart("SamplingRate"); builder.field("SamplingRate", samplingRate); + traceStop("SamplingRate"); + traceStart("SelfCPU"); builder.field("SelfCPU", selfCPU); + traceStop("SelfCPU"); + traceStart("TotalCPU"); builder.field("TotalCPU", totalCPU); + traceStop("TotalCPU"); + traceStart("TotalSamples"); builder.field("TotalSamples", totalSamples); + traceStop("TotalSamples"); builder.endObject(); return builder; @@ -345,4 +387,12 @@ public ToXContent next() { } }; } + + private static void traceStart(String name) { + TraceLogger.start(null, "toXContent[" + name + "]"); + } + + private static void traceStop(String name) { + TraceLogger.stop(null, "toXContent[" + name + "]"); + } } diff --git a/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/TransportGetFlamegraphAction.java b/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/TransportGetFlamegraphAction.java index dd78d6f1815f5..0e6976504e0c0 100644 --- a/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/TransportGetFlamegraphAction.java +++ b/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/TransportGetFlamegraphAction.java @@ -17,6 +17,7 @@ import org.elasticsearch.client.internal.node.NodeClient; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.tasks.Task; +import org.elasticsearch.telemetry.tracing.TraceLogger; import org.elasticsearch.transport.TransportService; import java.util.ArrayList; @@ -65,6 +66,7 @@ public void onFailure(Exception e) { } static GetFlamegraphResponse buildFlamegraph(GetStackTracesResponse response) { + TraceLogger.start(null, "buildFlamegraph"); FlamegraphBuilder builder = new FlamegraphBuilder( response.getTotalSamples(), response.getTotalFrames(), @@ -137,6 +139,7 @@ static GetFlamegraphResponse buildFlamegraph(GetStackTracesResponse response) { }); } } + TraceLogger.stop(null, "buildFlamegraph"); return builder.build(); }