mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Add an option --pprof
Former-commit-id: 3ca1280e8daddbf1075e3189f9851211ce8882ae
This commit is contained in:
@ -2,8 +2,10 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
|
||||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter"
|
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obiiter"
|
||||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obioptions"
|
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obioptions"
|
||||||
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obitools/obiconvert"
|
"git.metabarcoding.org/lecasofts/go/obitools/pkg/obitools/obiconvert"
|
||||||
@ -12,13 +14,9 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
// go tool pprof -http=":8000" ./obipairing ./cpu.pprof
|
// go tool pprof -nodefraction=0 -http=:8081 http://localhost:8080/debug/pprof/allocs
|
||||||
// f, err := os.Create("cpu.pprof")
|
// look at http://localhost:8080/debug/pprof for havng the possibilities
|
||||||
// if err != nil {
|
//go http.ListenAndServe("localhost:8080", nil)
|
||||||
// log.Fatal(err)
|
|
||||||
// }
|
|
||||||
// pprof.StartCPUProfile(f)
|
|
||||||
// defer pprof.StopCPUProfile()
|
|
||||||
|
|
||||||
// go tool trace cpu.trace
|
// go tool trace cpu.trace
|
||||||
// ftrace, err := os.Create("cpu.trace")
|
// ftrace, err := os.Create("cpu.trace")
|
||||||
@ -35,7 +33,7 @@ func main() {
|
|||||||
sequences, err := obiconvert.CLIReadBioSequences(args...)
|
sequences, err := obiconvert.CLIReadBioSequences(args...)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Cannot open file (%v)",err)
|
log.Errorf("Cannot open file (%v)", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,12 +8,17 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/DavidGamba/go-getoptions"
|
"github.com/DavidGamba/go-getoptions"
|
||||||
|
|
||||||
|
"net/http"
|
||||||
|
_ "net/http/pprof"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _Debug = false
|
var _Debug = false
|
||||||
var _ParallelWorkers = runtime.NumCPU()*2 - 1
|
var _ParallelWorkers = runtime.NumCPU()*2 - 1
|
||||||
var _MaxAllowedCPU = runtime.NumCPU()
|
var _MaxAllowedCPU = runtime.NumCPU()
|
||||||
var _BatchSize = 5000
|
var _BatchSize = 5000
|
||||||
|
var _Pprof = false
|
||||||
|
|
||||||
type ArgumentParser func([]string) (*getoptions.GetOpt, []string)
|
type ArgumentParser func([]string) (*getoptions.GetOpt, []string)
|
||||||
|
|
||||||
@ -24,6 +29,7 @@ func GenerateOptionParser(optionset ...func(*getoptions.GetOpt)) ArgumentParser
|
|||||||
options.SetUnknownMode(getoptions.Fail)
|
options.SetUnknownMode(getoptions.Fail)
|
||||||
options.Bool("help", false, options.Alias("h", "?"))
|
options.Bool("help", false, options.Alias("h", "?"))
|
||||||
options.BoolVar(&_Debug, "debug", false)
|
options.BoolVar(&_Debug, "debug", false)
|
||||||
|
options.BoolVar(&_Pprof, "pprof", false)
|
||||||
|
|
||||||
options.IntVar(&_ParallelWorkers, "workers", _ParallelWorkers,
|
options.IntVar(&_ParallelWorkers, "workers", _ParallelWorkers,
|
||||||
options.Alias("w"),
|
options.Alias("w"),
|
||||||
@ -52,6 +58,11 @@ func GenerateOptionParser(optionset ...func(*getoptions.GetOpt)) ArgumentParser
|
|||||||
log.Debugln("Switch to debug level logging")
|
log.Debugln("Switch to debug level logging")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if options.Called("pprof") {
|
||||||
|
go http.ListenAndServe("localhost:8080", nil)
|
||||||
|
log.Infoln("Start a pprof server at address http://localhost:8080/debug/pprof")
|
||||||
|
}
|
||||||
|
|
||||||
// Handle user errors
|
// Handle user errors
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "ERROR: %s\n\n", err)
|
fmt.Fprintf(os.Stderr, "ERROR: %s\n\n", err)
|
||||||
|
@ -45,7 +45,13 @@ func GetSlice(capacity int) []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CopySlice(src []byte) []byte {
|
func CopySlice(src []byte) []byte {
|
||||||
sl := GetSlice(len(src))[0:len(src)]
|
sl := GetSlice(len(src))
|
||||||
|
|
||||||
|
if cap(sl) < len(src) {
|
||||||
|
log.Panicln("Bizarre... j'aurai pourtant cru")
|
||||||
|
}
|
||||||
|
|
||||||
|
sl = sl[0:len(src)]
|
||||||
|
|
||||||
copy(sl, src)
|
copy(sl, src)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user