@@ -46,6 +46,7 @@ type configuration struct {
4646 colorScale string // -scale
4747 fast time.Duration // -scale-fast
4848 slow time.Duration // -scale-slow
49+ buffer bool // -buffer
4950 version string
5051}
5152
@@ -86,14 +87,15 @@ var templates = map[string]string{
8687}
8788
8889var colorScales = map [string ]string {
89- "GreenToRed" : "#0F0 -> #F00" ,
90- "BlueToRed" : "#00F -> #F00" ,
91- "CyanToRed" : "#0FF -> #F00" ,
92- "WhiteToRed" : "#FFF -> #F00" ,
93- "WhiteToPurple" : "#FFF -> #F700FF" ,
94- "BlackToRed" : "#000 -> #F00" ,
95- "BlackToPurple" : "#000 -> #F700FF" ,
96- "WhiteToBlueToRed" : "#FFF -> #00F -> #F00" ,
90+ "GreenToRed" : "#0F0 -> #F00" ,
91+ "GreenToGreenToRed" : "#0F0 -> #0F0 -> #F00" ,
92+ "BlueToRed" : "#00F -> #F00" ,
93+ "CyanToRed" : "#0FF -> #F00" ,
94+ "WhiteToRed" : "#FFF -> #F00" ,
95+ "WhiteToPurple" : "#FFF -> #F700FF" ,
96+ "BlackToRed" : "#000 -> #F00" ,
97+ "BlackToPurple" : "#000 -> #F700FF" ,
98+ "WhiteToBlueToRed" : "#FFF -> #00F -> #F00" ,
9799}
98100
99101var templateFuncs = template.FuncMap {
@@ -159,6 +161,7 @@ func init() {
159161 flag .StringVar (& config .colorScale , "scale" , "BlueToRed" , colorScalesHelp ())
160162 flag .DurationVar (& config .fast , "scale-fast" , 100 * time .Millisecond , "the lower bound for the color scale" )
161163 flag .DurationVar (& config .slow , "scale-slow" , 2 * time .Second , "the upper bound for the color scale" )
164+ flag .BoolVar (& config .buffer , "delta-buffer" , false , "buffer lines between -start matches, copy delta values from final line to buffered lines" )
162165 flag .Parse ()
163166 if knownFormat , ok := timeFormats [config .timeFormat ]; ok {
164167 config .timeFormat = knownFormat
@@ -186,8 +189,22 @@ func init() {
186189 }
187190}
188191
192+ func flushLineBuffer (buffer * []* line , line * line ) {
193+ for _ , oldLine := range * buffer {
194+ oldLine .DeltaSecs = line .DeltaSecs
195+ oldLine .DeltaNanos = line .DeltaNanos
196+ oldLine .DeltaString = line .DeltaString
197+ oldLine .Delta = line .Delta
198+ if err := printer (oldLine ); err != nil {
199+ fmt .Fprintln (os .Stderr , "output error:" , err )
200+ }
201+ }
202+ * buffer = (* buffer )[:0 ]
203+ }
204+
189205func main () {
190206 scanner := bufio .NewScanner (os .Stdin )
207+ lineBuffer := []* line {}
191208 line := line {Time : time .Now ()}
192209 first := line .Time
193210 last := line .Time
@@ -226,21 +243,34 @@ func main() {
226243 match = line .JSONText
227244 }
228245 }
229- if err := printer (& line ); err != nil {
230- fmt .Fprintln (os .Stderr , "output error:" , err )
246+ if ! config .buffer {
247+ if err := printer (& line ); err != nil {
248+ fmt .Fprintln (os .Stderr , "output error:" , err )
249+ }
231250 }
232251 if start != nil {
233252 if start .MatchString (match ) {
253+ if config .buffer {
254+ flushLineBuffer (& lineBuffer , & line )
255+ }
234256 last = now
235257 line .StartText = line .Text
236258 line .StartObject = line .Object
237259 }
260+ if config .buffer {
261+ lineCopy := line
262+ lineBuffer = append (lineBuffer , & lineCopy )
263+ }
238264 } else {
239265 last = now
240266 }
241267 i ++
242268 }
243269
270+ if config .buffer {
271+ flushLineBuffer (& lineBuffer , & line )
272+ }
273+
244274 if err := scanner .Err (); err != nil {
245275 fmt .Fprintln (os .Stderr , "input error:" , err )
246276 os .Exit (1 )
0 commit comments