Skip to content

Commit bc41b25

Browse files
committed
tools/flow: add to task stats in the first initTasks call
The method calls markTaskDependencies, which in some cases like the addded test would mean more evaluator work, but those counters were not being added to the task's stats. The added test would fail before the fix: stats: task totals different from controller: [...] task totals - controller totals: Leaks: -1 Freed: -5 Reused: -3 Allocs: -3 Retain: -5 Unifications: -6 Conjuncts: -5 Disjuncts: -9 For #2559. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I0e7e441b27a3cebad2669fe729cf5805eee019f7 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1198616 Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Marcel van Lohuizen <[email protected]>
1 parent f7b7aaf commit bc41b25

File tree

5 files changed

+159
-85
lines changed

5 files changed

+159
-85
lines changed

tools/flow/flow.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ func New(cfg *Config, inst cue.InstanceOrValue, f TaskFunc) *Controller {
242242
if cfg != nil {
243243
c.cfg = *cfg
244244
}
245-
246-
c.initTasks()
245+
c.initTasks(true)
247246
return c
248247

249248
}

tools/flow/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ func (c *Controller) runLoop() {
119119
// Recompute the configuration, if necessary.
120120
if c.updateValue() {
121121
// initTasks was already called in New to catch initialization
122-
// errors earlier.
123-
c.initTasks()
122+
// errors earlier and add stats.
123+
c.initTasks(false)
124124
}
125125

126126
c.updateTaskValue(t)

tools/flow/tasks.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
// tasks. It can be run multiple times on increasingly more concrete
3030
// configurations to add more tasks, whereby the task pointers of previously
3131
// found tasks are preserved.
32-
func (c *Controller) initTasks() {
32+
func (c *Controller) initTasks(addStats bool) {
3333
// Clear previous cache.
3434
c.nodes = map[*adt.Vertex]*Task{}
3535

@@ -47,7 +47,11 @@ func (c *Controller) initTasks() {
4747
// Note that the list of tasks may grow as this loop progresses.
4848
for i := 0; i < len(c.tasks); i++ {
4949
t := c.tasks[i]
50+
start := *c.opCtx.Stats()
5051
c.markTaskDependencies(t, t.vertex())
52+
if addStats {
53+
t.stats.Add(c.opCtx.Stats().Since(start))
54+
}
5155
}
5256

5357
// Check if there are cycles in the task dependencies.

tools/flow/testdata/dep.txtar

Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ graph TD
105105
b: 3
106106
$id: "valToOut"
107107
}
108+
-- out/run/t1/stats --
109+
Leaks: 0
110+
Freed: 0
111+
Reused: 0
112+
Allocs: 0
113+
Retain: 0
114+
115+
Unifications: 0
116+
Conjuncts: 0
117+
Disjuncts: 0
108118
-- out/run/t2 --
109119
graph TD
110120
t0("root.a [Terminated]")
@@ -133,6 +143,16 @@ graph TD
133143
$id: "valToOut"
134144
index: int
135145
}
146+
-- out/run/t2/stats --
147+
Leaks: 0
148+
Freed: 0
149+
Reused: 0
150+
Allocs: 0
151+
Retain: 0
152+
153+
Unifications: 0
154+
Conjuncts: 0
155+
Disjuncts: 0
136156
-- out/run/t3 --
137157
graph TD
138158
t0("root.a [Terminated]")
@@ -161,6 +181,16 @@ graph TD
161181
//cue:path: root.concreteValueInGeneratedSubfield.index
162182
let INDEX = int
163183
}
184+
-- out/run/t3/stats --
185+
Leaks: 1
186+
Freed: 0
187+
Reused: 0
188+
Allocs: 1
189+
Retain: 1
190+
191+
Unifications: 1
192+
Conjuncts: 1
193+
Disjuncts: 1
164194
-- out/run/t4 --
165195
graph TD
166196
t0("root.a [Terminated]")
@@ -193,6 +223,16 @@ graph TD
193223
//cue:path: root.concreteValueInGeneratedSubfield.index
194224
let INDEX = int
195225
}
226+
-- out/run/t4/stats --
227+
Leaks: 0
228+
Freed: 0
229+
Reused: 0
230+
Allocs: 0
231+
Retain: 0
232+
233+
Unifications: 0
234+
Conjuncts: 0
235+
Disjuncts: 0
196236
-- out/run/t5 --
197237
graph TD
198238
t0("root.a [Terminated]")
@@ -218,6 +258,16 @@ graph TD
218258
x: 3
219259
$id: "valToOut"
220260
}
261+
-- out/run/t5/stats --
262+
Leaks: 0
263+
Freed: 0
264+
Reused: 0
265+
Allocs: 0
266+
Retain: 0
267+
268+
Unifications: 0
269+
Conjuncts: 0
270+
Disjuncts: 0
221271
-- out/run/t6 --
222272
graph TD
223273
t0("root.a [Terminated]")
@@ -247,6 +297,16 @@ graph TD
247297
$id: "valToOut"
248298
incomplete: _
249299
}
300+
-- out/run/t6/stats --
301+
Leaks: 0
302+
Freed: 0
303+
Reused: 0
304+
Allocs: 0
305+
Retain: 0
306+
307+
Unifications: 0
308+
Conjuncts: 0
309+
Disjuncts: 0
250310
-- out/run/t7 --
251311
graph TD
252312
t0("root.a [Terminated]")
@@ -277,6 +337,16 @@ graph TD
277337
//cue:path: root.indirectTaskRootReference.incomplete
278338
let INCOMPLETE = _
279339
}
340+
-- out/run/t7/stats --
341+
Leaks: 0
342+
Freed: 0
343+
Reused: 0
344+
Allocs: 0
345+
Retain: 0
346+
347+
Unifications: 0
348+
Conjuncts: 0
349+
Disjuncts: 0
280350
-- out/run/t8 --
281351
graph TD
282352
t0("root.a [Terminated]")
@@ -310,6 +380,16 @@ graph TD
310380
//cue:path: root.indirectTaskRootReference.incomplete
311381
let INCOMPLETE = _
312382
}
383+
-- out/run/t8/stats --
384+
Leaks: 0
385+
Freed: 0
386+
Reused: 0
387+
Allocs: 0
388+
Retain: 0
389+
390+
Unifications: 0
391+
Conjuncts: 0
392+
Disjuncts: 0
313393
-- out/run/t9 --
314394
graph TD
315395
t0("root.a [Terminated]")
@@ -345,86 +425,6 @@ graph TD
345425
//cue:path: root.indirectTaskRootReference.incomplete
346426
let INCOMPLETE = _
347427
}
348-
-- out/run/t1/stats --
349-
Leaks: 0
350-
Freed: 0
351-
Reused: 0
352-
Allocs: 0
353-
Retain: 0
354-
355-
Unifications: 0
356-
Conjuncts: 0
357-
Disjuncts: 0
358-
-- out/run/t2/stats --
359-
Leaks: 0
360-
Freed: 0
361-
Reused: 0
362-
Allocs: 0
363-
Retain: 0
364-
365-
Unifications: 0
366-
Conjuncts: 0
367-
Disjuncts: 0
368-
-- out/run/t3/stats --
369-
Leaks: 0
370-
Freed: 0
371-
Reused: 0
372-
Allocs: 0
373-
Retain: 0
374-
375-
Unifications: 0
376-
Conjuncts: 0
377-
Disjuncts: 0
378-
-- out/run/t4/stats --
379-
Leaks: 0
380-
Freed: 0
381-
Reused: 0
382-
Allocs: 0
383-
Retain: 0
384-
385-
Unifications: 0
386-
Conjuncts: 0
387-
Disjuncts: 0
388-
-- out/run/t5/stats --
389-
Leaks: 0
390-
Freed: 0
391-
Reused: 0
392-
Allocs: 0
393-
Retain: 0
394-
395-
Unifications: 0
396-
Conjuncts: 0
397-
Disjuncts: 0
398-
-- out/run/t6/stats --
399-
Leaks: 0
400-
Freed: 0
401-
Reused: 0
402-
Allocs: 0
403-
Retain: 0
404-
405-
Unifications: 0
406-
Conjuncts: 0
407-
Disjuncts: 0
408-
-- out/run/t7/stats --
409-
Leaks: 0
410-
Freed: 0
411-
Reused: 0
412-
Allocs: 0
413-
Retain: 0
414-
415-
Unifications: 0
416-
Conjuncts: 0
417-
Disjuncts: 0
418-
-- out/run/t8/stats --
419-
Leaks: 0
420-
Freed: 0
421-
Reused: 0
422-
Allocs: 0
423-
Retain: 0
424-
425-
Unifications: 0
426-
Conjuncts: 0
427-
Disjuncts: 0
428428
-- out/run/t9/stats --
429429
Leaks: 0
430430
Freed: 0

tools/flow/testdata/statsfail.txtar

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#IgnoreConcrete: true
2+
#InferTasks: true
3+
-- in.cue --
4+
package p
5+
6+
import "tool/cli"
7+
8+
root: test: cli.Print & { text: data.str }
9+
10+
data: {
11+
str: ({in: 3, out: "0\(in)"}).out
12+
}
13+
-- out/run/errors --
14+
-- out/run/t0 --
15+
graph TD
16+
t0("root.test [Ready]")
17+
18+
-- out/run/t1 --
19+
graph TD
20+
t0("root.test [Terminated]")
21+
22+
-- out/run/t1/value --
23+
{
24+
$id: "tool/cli.Print"
25+
stdout: "foo"
26+
text: "03"
27+
}
28+
-- out/run/t1/stats --
29+
Leaks: 8
30+
Freed: 20
31+
Reused: 16
32+
Allocs: 12
33+
Retain: 24
34+
35+
Unifications: 26
36+
Conjuncts: 33
37+
Disjuncts: 38
38+
-- out/run/stats/totals --
39+
Leaks: 8
40+
Freed: 20
41+
Reused: 16
42+
Allocs: 12
43+
Retain: 24
44+
45+
Unifications: 26
46+
Conjuncts: 33
47+
Disjuncts: 38
48+
-- out/run/t2 --
49+
graph TD
50+
t0("root.prepare [Terminated]")
51+
t1("root.run [Terminated]")
52+
t1-->t0
53+
54+
-- out/run/t2/value --
55+
{
56+
$id: "run"
57+
stdout: "foo"
58+
env: {
59+
input: "foo"
60+
}
61+
}
62+
-- out/run/t2/stats --
63+
Leaks: 0
64+
Freed: 12
65+
Reused: 12
66+
Allocs: 0
67+
Retain: 0
68+
69+
Unifications: 12
70+
Conjuncts: 20
71+
Disjuncts: 12

0 commit comments

Comments
 (0)