Skip to content

Commit cc8454c

Browse files
committed
Add comments and remove superfluous debug log
1 parent a8cd7d4 commit cc8454c

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/action/TransportGetStackTracesAction.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,11 @@ private void searchEventGroupedByStackTrace(
377377
)
378378
.addAggregation(new SumAggregationBuilder("total_count").field("Stacktrace.count"))
379379
.execute(handleEventsGroupedByStackTrace(submitTask, client, responseBuilder, submitListener, searchResponse -> {
380+
// The count values for events are scaled up to the highest sampling frequency.
381+
// For example, if the highest sampling frequency is 100, an event with frequency=20 and count=1
382+
// will be upscaled to count=5 (100/20 * count).
383+
// For this, we need to find the highest frequency in the result set.
380384
long maxSamplingFrequency = 0;
381-
382385
Terms samplingFrequencies = searchResponse.getAggregations().get("group_by");
383386
for (Terms.Bucket samplingFrequencyBucket : samplingFrequencies.getBuckets()) {
384387
final double samplingFrequency = samplingFrequencyBucket.getKeyAsNumber().doubleValue();
@@ -387,6 +390,7 @@ private void searchEventGroupedByStackTrace(
387390
}
388391
}
389392

393+
// Calculate a scaled-up total count (scaled up to the highest sampling frequency).
390394
long totalCount = 0;
391395
for (Terms.Bucket samplingFrequencyBucket : samplingFrequencies.getBuckets()) {
392396
InternalNumericMetricsAggregation.SingleValue count = samplingFrequencyBucket.getAggregations().get("total_count");
@@ -398,17 +402,16 @@ private void searchEventGroupedByStackTrace(
398402
Resampler resampler = new Resampler(request, responseBuilder.getSamplingRate(), totalCount);
399403

400404
// Sort items lexicographically to access Lucene's term dictionary more efficiently when issuing an mget request.
401-
// The term dictionary is lexicographically sorted and using the same order reduces the number of page faults
405+
// The term dictionary is lexicographically sorted, and using the same order reduces the number of page faults
402406
// needed to load it.
403407
long totalFinalCount = 0;
404408
Map<TraceEventID, TraceEvent> stackTraceEvents = new HashMap<>(MAX_TRACE_EVENTS_RESULT_SIZE);
405409

410+
// Walk over all nested aggregations.
411+
// The outermost aggregation is the sampling frequency.
412+
// The next level is the executable name, followed by the thread name, host ID and stacktrace ID.
413+
// the innermost aggregation contains the count of samples for each stacktrace ID.
406414
for (Terms.Bucket samplingFrequencyBucket : samplingFrequencies.getBuckets()) {
407-
log.debug(
408-
"Using sampling frequency [{}] for [{}] stacktrace events.",
409-
samplingFrequencyBucket.getKeyAsString(),
410-
totalCount
411-
);
412415
final double samplingFrequency = samplingFrequencyBucket.getKeyAsNumber().doubleValue();
413416
final double samplingFactor = maxSamplingFrequency / samplingFrequency;
414417

0 commit comments

Comments
 (0)