Index: perf/go/parser/funcs.go |
diff --git a/perf/go/parser/funcs.go b/perf/go/parser/funcs.go |
index bca448e00a1770f894ff72a174e725aca02fff43..1f6b896c9ee1fd8ca92886190257c15b46f56bb0 100644 |
--- a/perf/go/parser/funcs.go |
+++ b/perf/go/parser/funcs.go |
@@ -175,3 +175,29 @@ 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/09/29 15:09:22
Yes, you'll need to call Eval on both Args[0] and
tfarina
2014/10/01 02:30:16
Done.
|
+ if err != nil { |
+ return nil, fmt.Errorf("ratio() argument failed to evaluate: %s", err) |
+ } |
+ |
+ if len(traces) == 0 { |
+ return traces, nil |
+ } |
+ |
+ ret := types.NewPerfTraceN(len(traces[0].Values)) |
tfarina
2014/09/30 13:35:14
Where the calc will go here?
You said in the e-ma
jcgregorio
2014/09/30 14:59:03
Yes, look at
for i, _ := range ret.Values
in A
tfarina
2014/10/01 02:30:16
I'm not sure yet how to proceed. Now I have traces
jcgregorio
2014/10/01 03:48:58
Yes, they will always have the same length.
On 20
|
+ return []*types.PerfTrace{ret}, nil |
+} |
+ |
+func (RatioFunc) Describe() string { |
+ return `ratio() .` |
tfarina
2014/09/30 13:35:14
could the description be something like:
"ratio()
jcgregorio
2014/09/30 14:59:03
`ratio(a, b) returns the point by point ratio of t
tfarina
2014/10/01 02:30:16
Done.
|
+} |
+ |
+var ratioFunc = RatioFunc{} |