mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-31 04:30:44 +00:00
Add debugging facilities.
This commit is contained in:
@@ -2,3 +2,6 @@ package aptly
|
|||||||
|
|
||||||
// Version of aptly
|
// Version of aptly
|
||||||
const Version = "0.4~dev"
|
const Version = "0.4~dev"
|
||||||
|
|
||||||
|
// Enable debugging features?
|
||||||
|
const EnableDebug = true
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gonuts/commander"
|
"github.com/gonuts/commander"
|
||||||
"github.com/gonuts/flag"
|
"github.com/gonuts/flag"
|
||||||
|
"github.com/smira/aptly/aptly"
|
||||||
"github.com/smira/aptly/debian"
|
"github.com/smira/aptly/debian"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ListPackagesRefList shows list of packages in PackageRefList
|
// ListPackagesRefList shows list of packages in PackageRefList
|
||||||
@@ -63,5 +65,12 @@ back as Debian repositories.`,
|
|||||||
cmd.Flag.Bool("dep-follow-all-variants", false, "when processing dependencies, follow a & b if depdency is 'a|b'")
|
cmd.Flag.Bool("dep-follow-all-variants", false, "when processing dependencies, follow a & b if depdency is 'a|b'")
|
||||||
cmd.Flag.String("architectures", "", "list of architectures to consider during (comma-separated), default to all available")
|
cmd.Flag.String("architectures", "", "list of architectures to consider during (comma-separated), default to all available")
|
||||||
cmd.Flag.String("config", "", "location of configuration file (default locations are /etc/aptly.conf, ~/.aptly.conf)")
|
cmd.Flag.String("config", "", "location of configuration file (default locations are /etc/aptly.conf, ~/.aptly.conf)")
|
||||||
|
|
||||||
|
if aptly.EnableDebug {
|
||||||
|
cmd.Flag.String("cpuprofile", "", "write cpu profile to file")
|
||||||
|
cmd.Flag.String("memprofile", "", "write memory profile to this file")
|
||||||
|
cmd.Flag.String("memstats", "", "write memory stats periodically to this file")
|
||||||
|
cmd.Flag.Duration("meminterval", 100*time.Millisecond, "memory stats dump interval")
|
||||||
|
}
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,12 @@ import (
|
|||||||
"github.com/smira/aptly/files"
|
"github.com/smira/aptly/files"
|
||||||
"github.com/smira/aptly/http"
|
"github.com/smira/aptly/http"
|
||||||
"github.com/smira/aptly/utils"
|
"github.com/smira/aptly/utils"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"runtime/pprof"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Common context shared by all commands
|
// Common context shared by all commands
|
||||||
@@ -23,6 +27,10 @@ var context struct {
|
|||||||
publishedStorage aptly.PublishedStorage
|
publishedStorage aptly.PublishedStorage
|
||||||
dependencyOptions int
|
dependencyOptions int
|
||||||
architecturesList []string
|
architecturesList []string
|
||||||
|
// Debug features
|
||||||
|
fileCPUProfile *os.File
|
||||||
|
fileMemProfile *os.File
|
||||||
|
fileMemStats *os.File
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitContext initializes context with default settings
|
// InitContext initializes context with default settings
|
||||||
@@ -62,11 +70,73 @@ func InitContext(cmd *commander.Command) error {
|
|||||||
context.packagePool = files.NewPackagePool(utils.Config.RootDir)
|
context.packagePool = files.NewPackagePool(utils.Config.RootDir)
|
||||||
context.publishedStorage = files.NewPublishedStorage(utils.Config.RootDir)
|
context.publishedStorage = files.NewPublishedStorage(utils.Config.RootDir)
|
||||||
|
|
||||||
|
if aptly.EnableDebug {
|
||||||
|
cpuprofile := cmd.Flag.Lookup("cpuprofile").Value.String()
|
||||||
|
if cpuprofile != "" {
|
||||||
|
context.fileCPUProfile, err = os.Create(cpuprofile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
pprof.StartCPUProfile(context.fileCPUProfile)
|
||||||
|
}
|
||||||
|
|
||||||
|
memprofile := cmd.Flag.Lookup("memprofile").Value.String()
|
||||||
|
if memprofile != "" {
|
||||||
|
context.fileMemProfile, err = os.Create(memprofile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
memstats := cmd.Flag.Lookup("memstats").Value.String()
|
||||||
|
if memstats != "" {
|
||||||
|
interval := cmd.Flag.Lookup("meminterval").Value.Get().(time.Duration)
|
||||||
|
|
||||||
|
context.fileMemStats, err = os.Create(memstats)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
context.fileMemStats.WriteString("Time\tAlloc\tTotalAlloc\tSys\tLookups\tMallocst\tFrees\tLastGC\tNumGC\n")
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
var stats runtime.MemStats
|
||||||
|
for {
|
||||||
|
runtime.ReadMemStats(&stats)
|
||||||
|
if context.fileMemStats != nil {
|
||||||
|
context.fileMemStats.WriteString(fmt.Sprintf("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%dex\t%d\n",
|
||||||
|
time.Now().UnixNano(), stats.Alloc, stats.TotalAlloc, stats.Sys, stats.Lookups, stats.Mallocs,
|
||||||
|
stats.Frees, stats.LastGC, stats.NumGC))
|
||||||
|
time.Sleep(interval)
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShutdownContext shuts context down
|
// ShutdownContext shuts context down
|
||||||
func ShutdownContext() {
|
func ShutdownContext() {
|
||||||
|
if aptly.EnableDebug {
|
||||||
|
if context.fileMemProfile != nil {
|
||||||
|
pprof.WriteHeapProfile(context.fileMemProfile)
|
||||||
|
context.fileMemProfile.Close()
|
||||||
|
context.fileMemProfile = nil
|
||||||
|
}
|
||||||
|
if context.fileCPUProfile != nil {
|
||||||
|
pprof.StopCPUProfile()
|
||||||
|
context.fileCPUProfile.Close()
|
||||||
|
context.fileCPUProfile = nil
|
||||||
|
}
|
||||||
|
if context.fileMemProfile != nil {
|
||||||
|
context.fileMemProfile.Close()
|
||||||
|
context.fileMemProfile = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
context.database.Close()
|
context.database.Close()
|
||||||
context.downloader.Shutdown()
|
context.downloader.Shutdown()
|
||||||
context.progress.Shutdown()
|
context.progress.Shutdown()
|
||||||
|
|||||||
@@ -17,7 +17,12 @@ Use "aptly help <command>" for more information about a command.
|
|||||||
Options:
|
Options:
|
||||||
-architectures="": list of architectures to consider during (comma-separated), default to all available
|
-architectures="": list of architectures to consider during (comma-separated), default to all available
|
||||||
-config="": location of configuration file (default locations are /etc/aptly.conf, ~/.aptly.conf)
|
-config="": location of configuration file (default locations are /etc/aptly.conf, ~/.aptly.conf)
|
||||||
|
-cpuprofile="": write cpu profile to file
|
||||||
-dep-follow-all-variants=false: when processing dependencies, follow a & b if depdency is 'a|b'
|
-dep-follow-all-variants=false: when processing dependencies, follow a & b if depdency is 'a|b'
|
||||||
-dep-follow-recommends=false: when processing dependencies, follow Recommends
|
-dep-follow-recommends=false: when processing dependencies, follow Recommends
|
||||||
-dep-follow-source=false: when processing dependencies, follow from binary to Source packages
|
-dep-follow-source=false: when processing dependencies, follow from binary to Source packages
|
||||||
-dep-follow-suggests=false: when processing dependencies, follow Suggests
|
-dep-follow-suggests=false: when processing dependencies, follow Suggests
|
||||||
|
-meminterval=100ms: memory stats dump interval
|
||||||
|
-memprofile="": write memory profile to this file
|
||||||
|
-memstats="": write memory stats periodically to this file
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,12 @@ back as Debian repositories.
|
|||||||
Options:
|
Options:
|
||||||
-architectures="": list of architectures to consider during (comma-separated), default to all available
|
-architectures="": list of architectures to consider during (comma-separated), default to all available
|
||||||
-config="": location of configuration file (default locations are /etc/aptly.conf, ~/.aptly.conf)
|
-config="": location of configuration file (default locations are /etc/aptly.conf, ~/.aptly.conf)
|
||||||
|
-cpuprofile="": write cpu profile to file
|
||||||
-dep-follow-all-variants=false: when processing dependencies, follow a & b if depdency is 'a|b'
|
-dep-follow-all-variants=false: when processing dependencies, follow a & b if depdency is 'a|b'
|
||||||
-dep-follow-recommends=false: when processing dependencies, follow Recommends
|
-dep-follow-recommends=false: when processing dependencies, follow Recommends
|
||||||
-dep-follow-source=false: when processing dependencies, follow from binary to Source packages
|
-dep-follow-source=false: when processing dependencies, follow from binary to Source packages
|
||||||
-dep-follow-suggests=false: when processing dependencies, follow Suggests
|
-dep-follow-suggests=false: when processing dependencies, follow Suggests
|
||||||
|
-meminterval=100ms: memory stats dump interval
|
||||||
|
-memprofile="": write memory profile to this file
|
||||||
|
-memstats="": write memory stats periodically to this file
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,11 @@ Use "aptly help <command>" for more information about a command.
|
|||||||
Options:
|
Options:
|
||||||
-architectures="": list of architectures to consider during (comma-separated), default to all available
|
-architectures="": list of architectures to consider during (comma-separated), default to all available
|
||||||
-config="": location of configuration file (default locations are /etc/aptly.conf, ~/.aptly.conf)
|
-config="": location of configuration file (default locations are /etc/aptly.conf, ~/.aptly.conf)
|
||||||
|
-cpuprofile="": write cpu profile to file
|
||||||
-dep-follow-all-variants=false: when processing dependencies, follow a & b if depdency is 'a|b'
|
-dep-follow-all-variants=false: when processing dependencies, follow a & b if depdency is 'a|b'
|
||||||
-dep-follow-recommends=false: when processing dependencies, follow Recommends
|
-dep-follow-recommends=false: when processing dependencies, follow Recommends
|
||||||
-dep-follow-source=false: when processing dependencies, follow from binary to Source packages
|
-dep-follow-source=false: when processing dependencies, follow from binary to Source packages
|
||||||
-dep-follow-suggests=false: when processing dependencies, follow Suggests
|
-dep-follow-suggests=false: when processing dependencies, follow Suggests
|
||||||
|
-meminterval=100ms: memory stats dump interval
|
||||||
|
-memprofile="": write memory profile to this file
|
||||||
|
-memstats="": write memory stats periodically to this file
|
||||||
|
|||||||
Reference in New Issue
Block a user