github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/base/timings.go (about)

     1  // Copyright 2016 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 base
     6  
     7  import (
     8  	"github.com/shogo82148/std/io"
     9  )
    10  
    11  var Timer Timings
    12  
    13  // Timings collects the execution times of labeled phases
    14  // which are added through a sequence of Start/Stop calls.
    15  // Events may be associated with each phase via AddEvent.
    16  type Timings struct {
    17  	list   []timestamp
    18  	events map[int][]*event
    19  }
    20  
    21  // Start marks the beginning of a new phase and implicitly stops the previous phase.
    22  // The phase name is the colon-separated concatenation of the labels.
    23  func (t *Timings) Start(labels ...string)
    24  
    25  // Stop marks the end of a phase and implicitly starts a new phase.
    26  // The labels are added to the labels of the ended phase.
    27  func (t *Timings) Stop(labels ...string)
    28  
    29  // AddEvent associates an event, i.e., a count, or an amount of data,
    30  // with the most recently started or stopped phase; or the very first
    31  // phase if Start or Stop hasn't been called yet. The unit specifies
    32  // the unit of measurement (e.g., MB, lines, no. of funcs, etc.).
    33  func (t *Timings) AddEvent(size int64, unit string)
    34  
    35  // Write prints the phase times to w.
    36  // The prefix is printed at the start of each line.
    37  func (t *Timings) Write(w io.Writer, prefix string)