github.com/jgbaldwinbrown/perf@v0.1.1/benchproc/syntax/doc.go (about) 1 // Copyright 2022 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package syntax documents the syntax used by benchmark filter and 6 // projection expressions. 7 // 8 // These expressions work with benchmark data in the Go benchmark 9 // format (https://golang.org/design/14313-benchmark-format). Each 10 // benchmark result (a line beginning with "Benchmark") consists of 11 // several field, including a name, name-based configuration, and 12 // file configuration pairs ("key: value" lines). 13 // 14 // # Keys 15 // 16 // Filters and projections share a common set of keys for referring to 17 // these fields of a benchmark result: 18 // 19 // - ".name" refers to the benchmark name, excluding per-benchmark 20 // configuration. For example, the ".name" of the 21 // "BenchmarkCopy/size=4k-16" benchmark is "Copy". 22 // 23 // - ".fullname" refers to the full benchmark name, including 24 // per-benchmark configuration, but excluding the "Benchmark" prefix. 25 // For example, the ".fullname" of "BenchmarkCopy/size=4k-16" is 26 // "Copy/size=4k-16". 27 // 28 // - "/{key}" refers to value of {key} from the benchmark name 29 // configuration. For example, the "/size" of 30 // "BenchmarkCopy/size=4k-16", is "4k". As a special case, 31 // "/gomaxprocs" recognizes both a literal "/gomaxprocs=" in the name, 32 // and the "-N" convention. For the above example, "/gomaxprocs" is 33 // "16". 34 // 35 // - Any name NOT prefixed with "/" or "." refers to the value of a 36 // file configuration key. For example, the "testing" package 37 // automatically emits a few file configuration keys, including "pkg", 38 // "goos", and "goarch", so the projection "pkg" extracts the package 39 // path of a benchmark. 40 // 41 // - ".config" (only in projections) refers to the all file 42 // configuration keys of a benchmark. The value of .config isn't a 43 // string like the other fields, but rather a tuple. .config is useful 44 // for grouping results by all file configuration keys to avoid grouping 45 // together incomparable results. For example, benchstat separates 46 // results with different .config into different tables. 47 // 48 // - ".unit" (only in filters) refers to individual measurements in a 49 // result, such as the "ns/op" measurement. The filter ".unit:ns/op" 50 // extracts just the ns/op measurement of a result. This will match 51 // both original units (e.g., "ns/op") and tidied units (e.g., 52 // "sec/op"). 53 // 54 // - ".file" refers to the input file provided on the command line 55 // (for command-line tools that use benchfmt.Files). 56 // 57 // # Filters 58 // 59 // Filters are boolean expressions that match or exclude benchmark 60 // results or individual measurements. 61 // 62 // Filters are built from key-value terms: 63 // 64 // key:value - Match if key's value is exactly "value". 65 // key:"value" - Same, but value is a double-quoted Go string that 66 // may contain spaces or other special characters. 67 // "key":value - Keys may also be double-quoted. 68 // key:/regexp/ - Match if key's value matches a regular expression. 69 // key:(val1 OR val2 OR ...) 70 // - Short-hand for key:val1 OR key:val2. Values may be 71 // double-quoted strings or regexps. 72 // * - Match everything. 73 // 74 // These terms can be combined into larger expressions as follows: 75 // 76 // x y ... - Match if x, y, etc. all match. 77 // x AND y - Same as x y. 78 // x OR y - Match if x or y match. 79 // -x - Match if x does not match. 80 // (...) - Subexpression. 81 // 82 // Precise syntax: 83 // 84 // expr = andExpr {"OR" andExpr} 85 // andExpr = match {"AND"? match} 86 // match = "(" expr ")" 87 // | "-" match 88 // | "*" 89 // | key ":" value 90 // | key ":" "(" value {"OR" value} ")" 91 // key = word 92 // value = word 93 // | "/" regexp "/" 94 // 95 // # Projections 96 // 97 // A projection expresses how to extract a tuple of data from a 98 // benchmark result, as well as a sort order for projected tuples. 99 // 100 // A projection is a comma- or space-separated list of fields. 101 // Each field specifies a key and optionally a sort order and a 102 // filter as follows: 103 // 104 // - "key" extracts the named field and orders it using the order 105 // values of this key are first observed in the data. 106 // 107 // - "key@order" specifies one of the built-in named sort orders. This 108 // can be "alpha" or "num" for alphabetic or numeric sorting. "num" 109 // understands basic use of metric and IEC prefixes like "2k" and 110 // "1Mi". 111 // 112 // - "key@(value value ...)" specifies a fixed value order for key. 113 // It also specifies a filter: if key has a value that isn't any of 114 // the specified values, the result is filtered out. 115 // 116 // Precise syntax: 117 // 118 // expr = part {","? part} 119 // part = key 120 // | key "@" order 121 // | key "@" "(" word {word} ")" 122 // key = word 123 // order = word 124 // 125 // # Common syntax 126 // 127 // Filters and projections share the following common base syntax: 128 // 129 // word = bareWord 130 // | double-quoted Go string 131 // bareWord = [^-*"():@,][^ ():@,]* 132 package syntax