@@ -8,10 +8,11 @@ import {
8
8
import {computed , onMounted , Ref , ref } from " vue" ;
9
9
import Tooltip from " ../../tooltip.vue" ;
10
10
import {ArtifactDescription } from " ../../types" ;
11
- import {getDateInPast } from " ./utils" ;
12
- import {renderPlots } from " ../../../../graph/render" ;
11
+ import {daysBetweenDates , getFutureDate , getPastDate } from " ./utils" ;
12
+ import {GraphRenderOpts , renderPlots } from " ../../../../graph/render" ;
13
13
import {GRAPH_RESOLVER } from " ../../../../graph/resolver" ;
14
14
import {GraphKind } from " ../../../../graph/data" ;
15
+ import uPlot from " uplot" ;
15
16
16
17
const props = defineProps <{
17
18
testCase: CompileTestCase ;
@@ -20,23 +21,116 @@ const props = defineProps<{
20
21
benchmarkMap: CompileBenchmarkMap ;
21
22
}>();
22
23
24
+ type GraphRange = {
25
+ start: string ;
26
+ end: string ;
27
+ date: Date | null ;
28
+ };
29
+
30
+ // How many days are shown in the graph
31
+ const DAY_RANGE = 30 ;
32
+
33
+ /**
34
+ * Calculates the start and end range for a history graph for this benchmark
35
+ * and artifact.
36
+ */
37
+ function getGraphRange(artifact : ArtifactDescription ): GraphRange {
38
+ const date = new Date (artifact .date );
39
+
40
+ // If this is a try commit, we don't know its future, so always we just display
41
+ // the last `DAY_RANGE` days.
42
+ if (artifact .type === " try" ) {
43
+ return {
44
+ start: getPastDate (date , DAY_RANGE ),
45
+ end: artifact .commit ,
46
+ date: null ,
47
+ };
48
+ } else {
49
+ // If this is a master commit, then we try to display `dayRange` days
50
+ // "centered" around the commit date.
51
+
52
+ // Calculate the end of the range, which is commit date + half of the
53
+ // amount of days we want to show. If this date is in the future,
54
+ // the server will clip the result at the current date.
55
+ const end = getFutureDate (date , DAY_RANGE / 2 );
56
+
57
+ // Calculate how many days there have been from the commit date
58
+ const daysInFuture = Math .min (
59
+ DAY_RANGE / 2 ,
60
+ daysBetweenDates (date , new Date ())
61
+ );
62
+
63
+ // Calculate how many days we should go into the past, taking into account
64
+ // the days that will be clipped by the server.
65
+ const daysInPast = DAY_RANGE - daysInFuture ;
66
+
67
+ const start = getPastDate (date , daysInPast );
68
+ return {
69
+ start ,
70
+ end ,
71
+ date ,
72
+ };
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Hook into the uPlot drawing machinery to draw a vertical line at the
78
+ * position of the given `date`.
79
+ */
80
+ function drawCurrentDate(opts : GraphRenderOpts , date : Date ) {
81
+ opts .hooks = {
82
+ drawSeries : (u : uPlot ) => {
83
+ let ctx = u .ctx ;
84
+ ctx .save ();
85
+
86
+ const y0 = u .bbox .top ;
87
+ const y1 = y0 + u .bbox .height ;
88
+ const x = u .valToPos (date .getTime () / 1000 , " x" , true );
89
+
90
+ ctx .beginPath ();
91
+ ctx .moveTo (x , y0 );
92
+ ctx .strokeStyle = " red" ;
93
+ ctx .setLineDash ([5 , 5 ]);
94
+ ctx .lineTo (x , y1 );
95
+ ctx .stroke ();
96
+
97
+ ctx .restore ();
98
+ },
99
+ };
100
+ }
101
+
23
102
async function renderGraph() {
103
+ const {start, end, date} = graphRange .value ;
24
104
const selector = {
25
105
benchmark: props .testCase .benchmark ,
26
106
profile: props .testCase .profile ,
27
107
scenario: props .testCase .scenario ,
28
108
stat: props .metric ,
29
- start: getDateInPast ( props . artifact ) ,
30
- end: props . artifact . commit ,
109
+ start ,
110
+ end ,
31
111
// We want to be able to see noise "blips" vs. a previous artifact.
32
112
// The "percent relative from previous commit" graph should be the best to
33
113
// see these kinds of changes.
34
114
kind: " percentrelative" as GraphKind ,
35
115
};
36
116
const graphData = await GRAPH_RESOLVER .loadGraph (selector );
37
- renderPlots ( graphData , selector , chartElement . value , {
117
+ const opts : GraphRenderOpts = {
38
118
renderTitle: false ,
39
- });
119
+ };
120
+ if (date !== null ) {
121
+ drawCurrentDate (opts , date );
122
+ }
123
+ renderPlots (graphData , selector , chartElement .value , opts );
124
+ }
125
+
126
+ function getGraphTitle() {
127
+ const {start, end, date} = graphRange .value ;
128
+ const msg = ` ${DAY_RANGE } day history ` ;
129
+ if (date !== null ) {
130
+ return ` ${msg } (${start } - ${end }) ` ;
131
+ } else {
132
+ return ` ${msg } (up to benchmarked commit) ` ;
133
+ }
40
134
}
41
135
42
136
const metadata = computed (
@@ -58,6 +152,7 @@ const cargoProfile = computed((): CargoProfileMetadata => {
58
152
});
59
153
60
154
const chartElement: Ref <HTMLElement | null > = ref (null );
155
+ const graphRange = computed (() => getGraphRange (props .artifact ));
61
156
62
157
onMounted (() => renderGraph ());
63
158
</script >
@@ -113,7 +208,7 @@ onMounted(() => renderGraph());
113
208
</div >
114
209
<div >
115
210
<div class =" title" >
116
- <div class =" bold" >30 day history (up to benchmarked commit) </div >
211
+ <div class =" bold" >{{ getGraphTitle() }} </div >
117
212
<div style =" font-size : 0.8em " >
118
213
Each plotted value is relative to its previous commit
119
214
</div >
0 commit comments