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 bb5980b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
10 changes: 10 additions & 0 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

// logFlag is whether to log debug statements.
logFlag bool
)

// New returns an initialized command tree.
Expand Down Expand Up @@ -104,6 +107,8 @@ You'll have to wait for goref until it outputs 'successfully output to ...', or
versionCommand.Flags().BoolVarP(&versionVerbose, "verbose", "v", false, "print verbose version info")
rootCommand.AddCommand(versionCommand)

rootCommand.PersistentFlags().BoolVarP(&logFlag, "log", "", false, "Enable goref logging.")

return rootCommand
}

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

func execute(attachPid int, exeFile, coreFile, outFile string, conf *config.Config) int {
if err := logflags.Setup(logFlag, "", ""); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
return 1
}
defer logflags.Close()
if loadConfErr != nil {
logflags.DebuggerLogger().Errorf("%v", loadConfErr)
}
Expand Down
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 bb5980b

Please sign in to comment.