perflib

package
v0.0.0-...-b6f583f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2024 License: MIT, MIT Imports: 12 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	PERF_COUNTER_COUNTER       = 0x10410400
	PERF_100NSEC_TIMER         = 0x20510500
	PERF_PRECISION_100NS_TIMER = 0x20570500
	PERF_ELAPSED_TIME          = 0x30240500
)
View Source
const (
	TicksToSecondScaleFactor = 1 / 1e7
	WindowsEpoch             = 116444736000000000
)

Conversion factors

Variables

View Source
var CounterNameTable = *QueryNameTable("Counter 009")

Functions

func GetPerflibSnapshot

func GetPerflibSnapshot(objNames string) (map[string]*PerfObject, error)

func MapCounterToIndex

func MapCounterToIndex(name string) string

func UnmarshalObject

func UnmarshalObject(obj *PerfObject, vs interface{}, logger log.Logger) error

Types

type NameTable

type NameTable struct {
	// contains filtered or unexported fields
}

func QueryNameTable

func QueryNameTable(tableName string) *NameTable

QueryNameTable Query a perflib name table from the registry. Specify the type and the language code (i.e. "Counter 009" or "Help 009") for English language.

func (*NameTable) LookupIndex

func (t *NameTable) LookupIndex(str string) uint32

func (*NameTable) LookupString

func (t *NameTable) LookupString(index uint32) string

type PerfCounter

type PerfCounter struct {
	Value       int64
	Def         *PerfCounterDef
	SecondValue int64
}

type PerfCounterDef

type PerfCounterDef struct {
	Name      string
	NameIndex uint

	// For debugging - subject to removal. CounterType is a perflib
	// implementation detail (see perflib.h) and should not be used outside
	// of this package. We export it so we can show it on /dump.
	CounterType uint32

	// PERF_TYPE_COUNTER (otherwise, it's a gauge)
	IsCounter bool
	// PERF_COUNTER_BASE (base value of a multi-value fraction)
	IsBaseValue bool
	// PERF_TIMER_100NS
	IsNanosecondCounter bool
	HasSecondValue      bool
	// contains filtered or unexported fields
}

type PerfInstance

type PerfInstance struct {
	// *not* resolved using a name table
	Name     string
	Counters []*PerfCounter
	// contains filtered or unexported fields
}

PerfInstance Each object can have multiple instances. For example, In case the object has no instances, we return one single PerfInstance with an empty name.

type PerfObject

type PerfObject struct {
	Name string
	// NameIndex Same index you pass to QueryPerformanceData
	NameIndex   uint
	Instances   []*PerfInstance
	CounterDefs []*PerfCounterDef

	Frequency int64
	// contains filtered or unexported fields
}

PerfObject Top-level performance object (like "Process").

func QueryPerformanceData

func QueryPerformanceData(query string) ([]*PerfObject, error)

QueryPerformanceData Query all performance counters that match a given query.

The query can be any of the following:

- "Global" (all performance counters except those Windows marked as costly)

- "Costly" (only the costly ones)

- One or more object indices, separated by spaces ("238 2 5")

Many objects have dependencies - if you query one of them, you often get back more than you asked for.

Example
objects, err := QueryPerformanceData("2")

if err != nil {
	panic(err)
}

for _, object := range objects {
	fmt.Printf("%d %s [%d counters, %d instances]\n",
		object.NameIndex, object.Name, len(object.CounterDefs), len(object.Instances))

	for _, instance := range object.Instances {
		if !((instance.Name == "_Total") || (instance.Name == "")) {
			continue
		}

		if instance.Name == "" {
			fmt.Println("No instance.", instance.Name)
		} else {
			fmt.Println("Instance:", instance.Name)
		}

		for _, counter := range instance.Counters {
			fmt.Printf("  -> %s %d\n", counter.Def.Name, counter.Def.NameIndex)
		}
	}
}
Output:

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL