|
| 1 | +package com.ebay.plugins.metrics.develocity.taskduration |
| 2 | + |
| 3 | +import com.ebay.plugins.metrics.develocity.projectcost.merge |
| 4 | +import kotlinx.serialization.Serializable |
| 5 | + |
| 6 | +/** |
| 7 | + * Intermediate data model used to aggregate the total execution duration of tasks. |
| 8 | + * Stores data by both task name (across all modules) and by task type. These details |
| 9 | + * are store both in an aggregate total as well as with a daily breakdown. |
| 10 | + */ |
| 11 | +@Serializable |
| 12 | +data class TaskDurationSummary( |
| 13 | + // Map of task name to its execution data |
| 14 | + val taskNameData: Map<String, TaskExecutionSummary> = emptyMap(), |
| 15 | + // Map of fully qualified task type/class name to its execution data |
| 16 | + val taskTypeData: Map<String, TaskExecutionSummary> = emptyMap(), |
| 17 | +) { |
| 18 | + operator fun plus(other: TaskDurationSummary): TaskDurationSummary { |
| 19 | + // Note: Because we're starting with a Map instead of a MutableMap, |
| 20 | + // Map.merge creates a new map rather than actually merge into the current Maps |
| 21 | + return TaskDurationSummary( |
| 22 | + taskNameData = taskNameData.merge(other.taskNameData) { left, right -> |
| 23 | + left + right |
| 24 | + }, |
| 25 | + taskTypeData = taskTypeData.merge(other.taskTypeData) { left, right -> |
| 26 | + left + right |
| 27 | + }, |
| 28 | + ) |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * Data model representing execution summary for a task, with a by-day breakdown. |
| 34 | + */ |
| 35 | +@Serializable |
| 36 | +data class TaskExecutionSummary( |
| 37 | + val total: TaskExecutionData = TaskExecutionData(), |
| 38 | + val byDay: Map<String, TaskExecutionData> = emptyMap(), |
| 39 | +) { |
| 40 | + operator fun plus(other: TaskExecutionSummary): TaskExecutionSummary { |
| 41 | + // Note: Because we're starting with a Map instead of a MutableMap, |
| 42 | + // Map.merge creates a new map rather than actually merge into the current Maps: |
| 43 | + return TaskExecutionSummary( |
| 44 | + total = total + other.total, |
| 45 | + byDay = byDay.merge(other.byDay) { left, right -> |
| 46 | + left + right |
| 47 | + } |
| 48 | + ) |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +/** |
| 53 | + * Data for a single task's execution metrics. |
| 54 | + */ |
| 55 | +@Serializable |
| 56 | +data class TaskExecutionData( |
| 57 | + val totalDuration: Long = 0, |
| 58 | + val executionCount: Long = 0, |
| 59 | + val minDuration: Long = totalDuration, |
| 60 | + val maxDuration: Long = totalDuration, |
| 61 | +) { |
| 62 | + operator fun plus(other: TaskExecutionData): TaskExecutionData { |
| 63 | + return TaskExecutionData( |
| 64 | + totalDuration = totalDuration + other.totalDuration, |
| 65 | + executionCount = executionCount + other.executionCount, |
| 66 | + minDuration = when { |
| 67 | + executionCount != 0L && other.executionCount != 0L -> minOf(minDuration, other.minDuration) |
| 68 | + executionCount != 0L -> minDuration |
| 69 | + else -> other.minDuration |
| 70 | + }, |
| 71 | + maxDuration = when { |
| 72 | + executionCount != 0L && other.executionCount != 0L -> maxOf(maxDuration, other.maxDuration) |
| 73 | + executionCount != 0L -> maxDuration |
| 74 | + else -> other.maxDuration |
| 75 | + }, |
| 76 | + ) |
| 77 | + } |
| 78 | +} |
0 commit comments