utils

package
v1.1.10 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2024 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package utils includes several library routines for ps-top

Index

Constants

View Source
const (
	// Copyright provide a copyright notice
	Copyright = "Copyright (C) 2014-2024 Simon J Mudd <sjmudd@pobox.com>"
)

Variables

View Source
var ProgName string

ProgName returns the program's name based on a cleaned version of os.Args[0]. Given this might be used a lot ensure we generate the value once and then cache the result.

Functions

func Divide

func Divide(a uint64, b uint64) float64

Divide divides a by b except if b is 0 in which case we return 0.

func DuplicateSlice added in v1.1.10

func DuplicateSlice[T any](src []T) []T

DuplicateSlice is a slice duplicator using Go generics

func FormatAmount

func FormatAmount(amount uint64) string

FormatAmount converts numbers to k = 1024 , M = 1024 x 1024, G = 1024 x 1024 x 1024, P = 1024x1024x1024x1024 and then formats them. For values = 0 return an empty string. For values < 1000 show 6,2 decimal places. For values >= 1000 show 6,1 decimal place.

func FormatCounter

func FormatCounter(counter int, width int) string

FormatCounter formats a counter like an Amount but is tighter in space

func FormatPct

func FormatPct(pct float64) string

FormatPct formats a floating point number as a percentage including the trailing % sign. Print the value as a %5.1f with a % suffix if there's a value. If the value is 0 print as 6 spaces. if the value is > 999.9 then show +++.+% to indicate an overflow.

func FormatTime

func FormatTime(picoseconds uint64) string

FormatTime is based on sys.format_time. It formats to 10 characters including space and suffix. All values have 2 decimal places. Zero is returned as an empty string.

func QualifiedTableName

func QualifiedTableName(schema, table string) string

QualifiedTableName returns the anonymised qualified table name from the columns as '<schema>.<table>'

func SignedDivide

func SignedDivide(a int64, b int64) float64

SignedDivide divides a by b except if b is 0 in which case we return 0.

func SignedFormatAmount

func SignedFormatAmount(amount int64) string

SignedFormatAmount formats a signed integer as per FormatAmount()

Types

This section is empty.

Jump to

Keyboard shortcuts

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