mirror of https://bitbucket.org/ausocean/av.git
cmd/revid-cli: add profiling support
This commit is contained in:
parent
db6ca2922a
commit
d7525e0a47
|
@ -25,12 +25,15 @@ LICENSE
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with revid in gpl.txt. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"runtime/pprof"
|
||||
"strconv"
|
||||
"time"
|
||||
"unicode"
|
||||
|
@ -82,6 +85,9 @@ const (
|
|||
revidStopTime = 5 * time.Second
|
||||
)
|
||||
|
||||
// canProfile is set to false with revid-cli is built with "-tags profile".
|
||||
var canProfile = true
|
||||
|
||||
// Globals
|
||||
var (
|
||||
rv *revid.Revid
|
||||
|
@ -89,6 +95,8 @@ var (
|
|||
)
|
||||
|
||||
func main() {
|
||||
cpuprofile := flag.String("cpuprofile", "", "write cpu profile to `file`")
|
||||
|
||||
flagNames := [noOfConfigFlags]struct{ name, description string }{
|
||||
{"Input", "The input type"},
|
||||
{"InputCodec", "The codec of the input"},
|
||||
|
@ -126,6 +134,21 @@ func main() {
|
|||
|
||||
flag.Parse()
|
||||
|
||||
if *cpuprofile != "" {
|
||||
if canProfile {
|
||||
f, err := os.Create(*cpuprofile)
|
||||
if err != nil {
|
||||
log.Fatal("could not create CPU profile: ", err)
|
||||
}
|
||||
if err := pprof.StartCPUProfile(f); err != nil {
|
||||
log.Fatal("could not start CPU profile: ", err)
|
||||
}
|
||||
defer pprof.StopCPUProfile()
|
||||
} else {
|
||||
fmt.Fprintln(os.Stderr, "Ignoring cpuprofile flag - http/pprof built in.")
|
||||
}
|
||||
}
|
||||
|
||||
switch *configFlags[inputPtr] {
|
||||
case "Raspivid":
|
||||
config.Input = revid.Raspivid
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
NAME
|
||||
revid-cli - command line interface for Revid.
|
||||
|
||||
DESCRIPTION
|
||||
See Readme.md
|
||||
|
||||
AUTHORS
|
||||
Dan Kortschak <dan@ausocean.org>
|
||||
|
||||
LICENSE
|
||||
revid-cli is Copyright (C) 2017-2018 the Australian Ocean Lab (AusOcean)
|
||||
|
||||
It is free software: you can redistribute it and/or modify them
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
It is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with revid in gpl.txt. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
// +build profile
|
||||
|
||||
package main
|
||||
|
||||
import _ "net/http/pprof"
|
||||
|
||||
func init() {
|
||||
canProfile = false
|
||||
}
|
Loading…
Reference in New Issue