github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/internal/trace/gc.go (about)

     1  // Copyright 2017 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 trace
     6  
     7  import (
     8  	"github.com/shogo82148/std/time"
     9  )
    10  
    11  // MutatorUtil is a change in mutator utilization at a particular
    12  // time. Mutator utilization functions are represented as a
    13  // time-ordered []MutatorUtil.
    14  type MutatorUtil struct {
    15  	Time int64
    16  	// Util is the mean mutator utilization starting at Time. This
    17  	// is in the range [0, 1].
    18  	Util float64
    19  }
    20  
    21  // UtilFlags controls the behavior of MutatorUtilization.
    22  type UtilFlags int
    23  
    24  const (
    25  	// UtilSTW means utilization should account for STW events.
    26  	// This includes non-GC STW events, which are typically user-requested.
    27  	UtilSTW UtilFlags = 1 << iota
    28  	// UtilBackground means utilization should account for
    29  	// background mark workers.
    30  	UtilBackground
    31  	// UtilAssist means utilization should account for mark
    32  	// assists.
    33  	UtilAssist
    34  	// UtilSweep means utilization should account for sweeping.
    35  	UtilSweep
    36  
    37  	// UtilPerProc means each P should be given a separate
    38  	// utilization function. Otherwise, there is a single function
    39  	// and each P is given a fraction of the utilization.
    40  	UtilPerProc
    41  )
    42  
    43  // MutatorUtilization returns a set of mutator utilization functions
    44  // for the given trace. Each function will always end with 0
    45  // utilization. The bounds of each function are implicit in the first
    46  // and last event; outside of these bounds each function is undefined.
    47  //
    48  // If the UtilPerProc flag is not given, this always returns a single
    49  // utilization function. Otherwise, it returns one function per P.
    50  func MutatorUtilization(events []*Event, flags UtilFlags) [][]MutatorUtil
    51  
    52  // MutatorUtilizationV2 returns a set of mutator utilization functions
    53  // for the given v2 trace, passed as an io.Reader. Each function will
    54  // always end with 0 utilization. The bounds of each function are implicit
    55  // in the first and last event; outside of these bounds each function is
    56  // undefined.
    57  //
    58  // If the UtilPerProc flag is not given, this always returns a single
    59  // utilization function. Otherwise, it returns one function per P.
    60  func MutatorUtilizationV2(events []tracev2.Event, flags UtilFlags) [][]MutatorUtil
    61  
    62  // An MMUCurve is the minimum mutator utilization curve across
    63  // multiple window sizes.
    64  type MMUCurve struct {
    65  	series []mmuSeries
    66  }
    67  
    68  // NewMMUCurve returns an MMU curve for the given mutator utilization
    69  // function.
    70  func NewMMUCurve(utils [][]MutatorUtil) *MMUCurve
    71  
    72  // UtilWindow is a specific window at Time.
    73  type UtilWindow struct {
    74  	Time int64
    75  	// MutatorUtil is the mean mutator utilization in this window.
    76  	MutatorUtil float64
    77  }
    78  
    79  // MMU returns the minimum mutator utilization for the given time
    80  // window. This is the minimum utilization for all windows of this
    81  // duration across the execution. The returned value is in the range
    82  // [0, 1].
    83  func (c *MMUCurve) MMU(window time.Duration) (mmu float64)
    84  
    85  // Examples returns n specific examples of the lowest mutator
    86  // utilization for the given window size. The returned windows will be
    87  // disjoint (otherwise there would be a huge number of
    88  // mostly-overlapping windows at the single lowest point). There are
    89  // no guarantees on which set of disjoint windows this returns.
    90  func (c *MMUCurve) Examples(window time.Duration, n int) (worst []UtilWindow)
    91  
    92  // MUD returns mutator utilization distribution quantiles for the
    93  // given window size.
    94  //
    95  // The mutator utilization distribution is the distribution of mean
    96  // mutator utilization across all windows of the given window size in
    97  // the trace.
    98  //
    99  // The minimum mutator utilization is the minimum (0th percentile) of
   100  // this distribution. (However, if only the minimum is desired, it's
   101  // more efficient to use the MMU method.)
   102  func (c *MMUCurve) MUD(window time.Duration, quantiles []float64) []float64