Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syz-manager: periodically fetch the heap profile #4983

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions syz-manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
"runtime/pprof"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -50,9 +51,10 @@ import (
)

var (
flagConfig = flag.String("config", "", "configuration file")
flagDebug = flag.Bool("debug", false, "dump all VM output to console")
flagBench = flag.String("bench", "", "write execution statistics into this file periodically")
flagConfig = flag.String("config", "", "configuration file")
flagDebug = flag.Bool("debug", false, "dump all VM output to console")
flagBench = flag.String("bench", "", "write execution statistics into this file periodically")
flagHeapProfile = flag.String("heap_profile", "", "periodically write pprof heap profile into this file")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this either to pkg/tool, or to testbed? manager.go is huge and this is quite generic low-level functionality.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By "move to testbed" -- you mean, make http requests to /debug/pprof/heap?

pkg/tool might be problematic. We don't use it in syz-manager and in its current form it doesn't add much value to it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By "move to testbed" -- you mean, make http requests to /debug/pprof/heap?

Yes.

pkg/tool might be problematic. We don't use it in syz-manager and in its current form it doesn't add much value to it.

it can be a separate function in pkg/tool that does just it.


flagMode = flag.String("mode", "fuzzing", "mode of operation, one of:\n"+
" - fuzzing: the default continuous fuzzing mode\n"+
Expand Down Expand Up @@ -282,6 +284,10 @@ func RunManager(cfg *mgrconfig.Config) {
mgr.initBench()
}

if *flagHeapProfile != "" {
go mgr.heapProfileLoop()
}

go mgr.heartbeatLoop()
if mgr.mode != ModeSmokeTest {
osutil.HandleInterrupts(vm.Shutdown)
Expand Down Expand Up @@ -322,6 +328,28 @@ func (mgr *Manager) heartbeatLoop() {
}
}

func (mgr *Manager) heapProfileLoop() {
for range time.NewTicker(time.Minute).C {
tmpFile := *flagHeapProfile + ".tmp"
f, err := os.Create(tmpFile)
if err != nil {
log.Errorf("failed to craete to %s: %v", tmpFile, err)
continue
}
if err := pprof.WriteHeapProfile(f); err != nil {
f.Close()
log.Errorf("failed to write heap profile to %s: %v", tmpFile, err)
continue
}
f.Close()
err = os.Rename(tmpFile, *flagHeapProfile)
if err != nil {
log.Errorf("failed to rename the heap profile file %v", err)
continue
}
}
}

func (mgr *Manager) initBench() {
f, err := os.OpenFile(*flagBench, os.O_WRONLY|os.O_CREATE|os.O_EXCL, osutil.DefaultFilePerm)
if err != nil {
Expand Down
Loading