perf

package
v0.0.0-...-c5cf874 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package perf provides a means of capturing performance metrics

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Diff

type Diff struct {
	Time    time.Duration
	Bytes   int64
	Objects int64
}

Diff represents the difference between two snapshots

Example
package main

import (
	"fmt"
	"time"

	"github.com/tkw1536/pkglib/perf"
)

func main() {
	// Diff holds both the amount of time an operation took,
	// the number of bytes consumed, and the total number of allocated objects.
	diff := perf.Diff{
		Time:    15 * time.Second,
		Bytes:   100,
		Objects: 100,
	}
	fmt.Println(diff)
}
Output:

15s, 100 B, 100 objects

func Since

func Since(start Snapshot) (diff Diff)

Since returns changes in metrics since start. It is a shortcut for start.Sub(perf.Now())

func (Diff) BytesString

func (diff Diff) BytesString() string

BytesString returns a human-readable string representing the bytes

func (Diff) ObjectsString

func (diff Diff) ObjectsString() string

ObjectsString returns a human-readable string representing the number of objects

func (Diff) String

func (diff Diff) String() string

type Snapshot

type Snapshot struct {
	// Time the snapshot was captured
	Time time.Time

	// memory in use
	Bytes int64

	// number of objects on the heap
	Objects int64
}

Snapshot holds metrics at a specific instance

func Now

func Now() (s Snapshot)

Now returns a snapshot for the current time

func (Snapshot) BytesString

func (snapshot Snapshot) BytesString() string

BytesString returns a human-readable string representing the bytes

func (Snapshot) ObjectsString

func (snapshot Snapshot) ObjectsString() string

ObjectsString returns a human-readable string representing the number of objects

func (Snapshot) String

func (snapshot Snapshot) String() string

func (Snapshot) Sub

func (s Snapshot) Sub(other Snapshot) Diff

Sub subtracts the other snapshot from this snapshot.

Jump to

Keyboard shortcuts

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