|
6 | 6 | package org.opensearch.sql.monitor.profile; |
7 | 7 |
|
8 | 8 | import com.google.gson.annotations.SerializedName; |
| 9 | +import java.util.LinkedHashMap; |
9 | 10 | import java.util.Locale; |
10 | 11 | import java.util.Map; |
11 | 12 | import java.util.Objects; |
|
15 | 16 | @Getter |
16 | 17 | public final class QueryProfile { |
17 | 18 |
|
18 | | - /** Total elapsed milliseconds for the profiled query (rounded to two decimals). */ |
19 | | - @SerializedName("total_ms") |
20 | | - private final double totalMillis; |
| 19 | + private final Summary summary; |
21 | 20 |
|
22 | | - /** Immutable metric values keyed by metric name in milliseconds (rounded to two decimals). */ |
23 | | - private final Map<String, Double> metrics; |
| 21 | + private final Map<String, Phase> phases; |
24 | 22 |
|
25 | 23 | /** |
26 | 24 | * Create a new query profile snapshot. |
27 | 25 | * |
28 | | - * @param totalMillis total elapsed milliseconds for the query (rounded to two decimals) |
29 | | - * @param metrics metric values keyed by {@link MetricName} |
| 26 | + * @param totalTimeMillis total elapsed milliseconds for the query (rounded to two decimals) |
| 27 | + * @param phases metric values keyed by {@link MetricName} |
30 | 28 | */ |
31 | | - public QueryProfile(double totalMillis, Map<MetricName, Double> metrics) { |
32 | | - this.totalMillis = totalMillis; |
33 | | - this.metrics = buildMetrics(metrics); |
| 29 | + public QueryProfile(double totalTimeMillis, Map<MetricName, Double> phases) { |
| 30 | + this.summary = new Summary(totalTimeMillis); |
| 31 | + this.phases = buildPhases(phases); |
34 | 32 | } |
35 | 33 |
|
36 | | - private Map<String, Double> buildMetrics(Map<MetricName, Double> metrics) { |
37 | | - Objects.requireNonNull(metrics, "metrics"); |
38 | | - Map<String, Double> ordered = new java.util.LinkedHashMap<>(metrics.size()); |
| 34 | + private Map<String, Phase> buildPhases(Map<MetricName, Double> phases) { |
| 35 | + Objects.requireNonNull(phases, "phases"); |
| 36 | + Map<String, Phase> ordered = new LinkedHashMap<>(MetricName.values().length); |
39 | 37 | for (MetricName metricName : MetricName.values()) { |
40 | | - Double value = metrics.getOrDefault(metricName, 0d); |
41 | | - ordered.put(metricName.name().toLowerCase(Locale.ROOT) + "_ms", value); |
| 38 | + Double value = phases.getOrDefault(metricName, 0d); |
| 39 | + ordered.put(metricName.name().toLowerCase(Locale.ROOT), new Phase(value)); |
42 | 40 | } |
43 | 41 | return ordered; |
44 | 42 | } |
| 43 | + |
| 44 | + @Getter |
| 45 | + public static final class Summary { |
| 46 | + |
| 47 | + @SerializedName("total_time_ms") |
| 48 | + private final double totalTimeMillis; |
| 49 | + |
| 50 | + private Summary(double totalTimeMillis) { |
| 51 | + this.totalTimeMillis = totalTimeMillis; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + @Getter |
| 56 | + public static final class Phase { |
| 57 | + |
| 58 | + @SerializedName("time_ms") |
| 59 | + private final double timeMillis; |
| 60 | + |
| 61 | + private Phase(double timeMillis) { |
| 62 | + this.timeMillis = timeMillis; |
| 63 | + } |
| 64 | + } |
45 | 65 | } |
0 commit comments