gocpuload

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2023 License: MIT Imports: 3 Imported by: 0

README

gocpuload

Go Reference

Usage:

as CLI

example 01: run 30% of all CPU cores for 10 seconds

gocpuload -p 30 -t 10

example 02: run 30% of all CPU cores forver

gocpuload -p 30

example 03: run 30% of 2 of CPU cores for 10 seconds

gocpuload -p 30 -c 2 -t 10
  • all CPU load = (num of para c _ num of p) / (all cores count of CPU _ 100)
  • may not specify cores run the load only, it just promise the all CPU load, and not promise each cores run the same load
CLI Parameters
--coresCount value, -c value   how many cores (optional, default: 8)

--timeSeconds value, -t value  how long (optional, default: 2147483647)

--percentage value, -p value   percentage of each specify cores (required)

--help, -h                     show help
as Liblary

import (
	"context"
	"github.com/0Delta/gocpuload"
)

func main(){
    ctx := context.Background()
    // RunCPULoad(ctx context.Context, coresCount int, timeSeconds int, percentage int)
    //
    // This function return control immediately.
    loadCtx, loadCancel := gocpuload.RunCPULoad(ctx, runtime.NumCPU()/2, 3, 80)

AdvancedUseage:
    // If you want wait loading, use below.
    <-loadCtx.Done()

    // You can cancel loading before appoint time.
    loadCancel()

}

See GoDoc

Requirements:

  • go

for test in Windows

  • cgo

Install:

  • go1.6 or higher
go install github.com/0Delta/gocpuload@latest
  • go1.5 or lower
go get -u github.com/0Delta/gocpuload

How it runs:

  • Giving a range of time(e.g. 100ms)
  • Want to run 30% of all CPU cores
    • 30ms: run (CPU 100%)
    • 70ms: sleep(CPU 0%)

license:

MIT

Author:

0Δ(0deltast@gmail.com)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunCPULoad

func RunCPULoad(ctx context.Context, coresCount int, timeSeconds int, percentage int) (context.Context, context.CancelFunc)

RunCPULoad run CPU load in specify cores count and percentage

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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