pgolib

command module
v0.0.0-...-0b90c35 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2024 License: MPL-2.0 Imports: 6 Imported by: 0

README

pgolib

pgolib is a golang library for profile guided optimization.

Usage

Install
go get github.com/snowmerak/pgolib
Profile
package main

import (
	"context"
	"log"
	"time"

	"github.com/snowmerak/pgolib/profile"
	"github.com/snowmerak/pgolib/storage/minio"

	"signal"
	"os"
)

func main() {
	ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
	defer cancel()

	strg, err := minio.NewClient(ctx, "practice-app", 10, "profile", &minio.Config{
		Endpoint: "localhost:9000",
	})
	if err != nil {
		panic(err)
	}

	prof := profile.New(strg, 30*time.Minute, 5*time.Minute) // 30 minutes for delay, 5 minutes for collect interval

	errCh, err := prof.Run(ctx)
	if err != nil {
		panic(err)
	}

	done := ctx.Done()
loop:
	for {
		select {
		case err := <-errCh:
			log.Printf("error: %v", err)
		case <-done:
			break loop
		}
	}
	
	log.Println("done")
}
Download and Merge

Refer to pgolib-sample.go

Build
go run sample.go # download and merge profiles to profile.pprof
docker build -t sample:latest -f Sample.Dockerfile --build-arg PGO=profile.pprof . # build with profile.pprof

Recommendation

Use appropriate lifetime management tools to prevent profiles from increasing indefinitely.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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