Skip to content

Commit

Permalink
feat: adjust log level
Browse files Browse the repository at this point in the history
  • Loading branch information
jayantxie committed Sep 14, 2024
1 parent 87e374c commit 98df3a6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
16 changes: 13 additions & 3 deletions cmd/grf/cmds/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ var (
conf *config.Config
loadConfErr error
outFile string

// verbose is whether to log verbose info, like debug logs.
verbose bool
)

// New returns an initialized command tree.
Expand Down Expand Up @@ -89,21 +92,21 @@ You'll have to wait for goref until it outputs 'successfully output to ...', or
coreCommand.Flags().StringVarP(&outFile, "out", "o", "grf.out", "output file name")
rootCommand.AddCommand(coreCommand)

versionVerbose := false
versionCommand := &cobra.Command{
Use: "version",
Short: "Prints version.",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Goref Tool\n%s\n", version.DelveVersion)
if versionVerbose {
if verbose {
fmt.Printf("Build Details: %s\n", version.BuildInfo())
}
},
ValidArgsFunction: cobra.NoFileCompletions,
}
versionCommand.Flags().BoolVarP(&versionVerbose, "verbose", "v", false, "print verbose version info")
rootCommand.AddCommand(versionCommand)

rootCommand.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "print verbose info or enable debug logger")

return rootCommand
}

Expand All @@ -129,6 +132,13 @@ func coreCmd(_ *cobra.Command, args []string) {
}

func execute(attachPid int, exeFile, coreFile, outFile string, conf *config.Config) int {
if verbose {
if err := logflags.Setup(verbose, "", ""); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
return 1
}
defer logflags.Close()
}
if loadConfErr != nil {
logflags.DebuggerLogger().Errorf("%v", loadConfErr)
}
Expand Down
Binary file added cmd/grf/grf
Binary file not shown.
2 changes: 1 addition & 1 deletion pkg/proc/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func extractVarInfoFromEntry(bi *proc.BinaryInfo, image *proc.Image, regs op.Dwa
t, err = resolveParametricType(bi, mem, t, dictAddr, mds)
if err != nil {
// Log the error, keep going with t, which will be the shape type
logflags.DebuggerLogger().Errorf("could not resolve parametric type of %s: %v", n, err)
logflags.DebuggerLogger().Warnf("could not resolve parametric type of %s: %v", n, err)
}

addr, pieces, _, _ := bi.Location(entry, dwarf.AttrLocation, regs.PC(), regs, mem)
Expand Down
1 change: 0 additions & 1 deletion pkg/proc/gcmask.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type gcMaskBitIterator struct {
maskBase Address
mask []uint64

// for iterator
addr Address // iterator address
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/proc/heap.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func (s *HeapScope) readType(sp *spanInfo, typeAddr, addr, end Address) {
}
mask, err := readUintRaw(mem, uint64(gcDataAddr.Add(addr.Sub(elem)/64)), 8)
if err != nil {
logflags.DebuggerLogger().Errorf("read gc data addr error: %v", err)
logflags.DebuggerLogger().Warnf("read gc data addr error: %v", err)
break
}
var headBits int64
Expand Down
8 changes: 7 additions & 1 deletion pkg/proc/mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import (
"github.com/go-delve/delve/pkg/proc"
)

const cacheEnabled = true
const (
cacheEnabled = true
cacheThreshold = 1024 * 1024 * 1024 // 1GB
)

type memCache struct {
loaded bool
Expand Down Expand Up @@ -68,6 +71,9 @@ func cacheMemory(mem proc.MemoryReadWriter, addr uint64, size int) proc.MemoryRe
// overflow
return mem
}
if size > cacheThreshold {
return mem
}
switch cacheMem := mem.(type) {
case *memCache:
if cacheMem.contains(addr, size) {
Expand Down

0 comments on commit 98df3a6

Please sign in to comment.