Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Unified Diff: perf/go/parser/funcs.go

Issue 610793003: Add ratio calculation to take the ratio of two calculations. (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: ... Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | perf/go/parser/parser.go » ('j') | perf/go/parser/parser_test.go » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: perf/go/parser/funcs.go
diff --git a/perf/go/parser/funcs.go b/perf/go/parser/funcs.go
index bca448e00a1770f894ff72a174e725aca02fff43..f3487ceadc033d86e8cc89125ba8e544bbfa6b80 100644
--- a/perf/go/parser/funcs.go
+++ b/perf/go/parser/funcs.go
@@ -175,3 +175,35 @@ func (AveFunc) Describe() string {
}
var aveFunc = AveFunc{}
+
+type RatioFunc struct{}
+
+func (RatioFunc) Eval(ctx *Context, node *Node) ([]*types.PerfTrace, error) {
+ if len(node.Args) != 2 {
+ return nil, fmt.Errorf("ratio() takes two arguments")
+ }
+
+ traces, err := node.Args[0].Eval(ctx)
jcgregorio 2014/10/17 11:43:55 tracesA, err :=
tfarina 2014/10/17 21:14:23 Done.
tfarina 2014/10/17 21:14:23 Done.
+ if err != nil {
+ return nil, fmt.Errorf("ratio() argument failed to evaluate: %s", err)
+ }
+
+ traces, err = node.Args[1].Eval(ctx)
tfarina 2014/10/17 00:35:47 why I'm getting zero traces here? len(traces) == 0
jcgregorio 2014/10/17 11:43:55 tracesB, err :=
jcgregorio 2014/10/17 11:43:55 The filtering in the test is too narrow and coming
tfarina 2014/10/17 21:14:23 Done.
+ if err != nil {
+ return nil, fmt.Errorf("ratio() argument failed to evaluate: %s", err)
+ }
+
+ ret := types.NewPerfTraceN(len(traces[0].Values))
jcgregorio 2014/10/17 11:43:55 ret := types.NewPerfTraceN(len(tracesA[0].Values))
tfarina 2014/10/17 21:14:23 Done.
+ for i, _ := range ret.Values {
+ ret.Values[i] = traces[0].Values[i] / traces[1].Values[i]
jcgregorio 2014/10/17 11:43:55 ret.Values[i] = tracesA[0].Values[i] / tracesB[1].
tfarina 2014/10/17 21:14:23 Done.
+ fmt.Println(ret.Values[i])
+ }
+ return []*types.PerfTrace{ret}, nil
+}
+
+func (RatioFunc) Describe() string {
+ return `ratio(a, b) returns the point by point ratio of two traces.
+ That is, it returns a trace with a[i]/b[i] for every point in a and b.`
+}
+
+var ratioFunc = RatioFunc{}
« no previous file with comments | « no previous file | perf/go/parser/parser.go » ('j') | perf/go/parser/parser_test.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698