diff options
author | Bhasker Hariharan <bhaskerh@google.com> | 2019-05-29 11:30:59 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-05-30 12:07:11 -0700 |
commit | 035a8fa38ed21da2e06db22d3dfd6122610fb856 (patch) | |
tree | 3650d76b5519f5a3e8efdd0c5df039cacc1502ec /runsc/sandbox/sandbox.go | |
parent | b52e571a6188ce90b5a13b002753230780119db9 (diff) |
Add support for collecting execution trace to runsc.
Updates #220
PiperOrigin-RevId: 250532302
Diffstat (limited to 'runsc/sandbox/sandbox.go')
-rw-r--r-- | runsc/sandbox/sandbox.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/runsc/sandbox/sandbox.go b/runsc/sandbox/sandbox.go index bc69a9d61..47a66afb2 100644 --- a/runsc/sandbox/sandbox.go +++ b/runsc/sandbox/sandbox.go @@ -883,6 +883,41 @@ func (s *Sandbox) StopCPUProfile() error { return nil } +// StartTrace start trace writing to the given file. +func (s *Sandbox) StartTrace(f *os.File) error { + log.Debugf("Trace start %q", s.ID) + conn, err := s.sandboxConnect() + if err != nil { + return err + } + defer conn.Close() + + opts := control.ProfileOpts{ + FilePayload: urpc.FilePayload{ + Files: []*os.File{f}, + }, + } + if err := conn.Call(boot.StartTrace, &opts, nil); err != nil { + return fmt.Errorf("starting sandbox %q trace: %v", s.ID, err) + } + return nil +} + +// StopTrace stops a previously started trace.. +func (s *Sandbox) StopTrace() error { + log.Debugf("Trace stop %q", s.ID) + conn, err := s.sandboxConnect() + if err != nil { + return err + } + defer conn.Close() + + if err := conn.Call(boot.StopTrace, nil, nil); err != nil { + return fmt.Errorf("stopping sandbox %q trace: %v", s.ID, err) + } + return nil +} + // DestroyContainer destroys the given container. If it is the root container, // then the entire sandbox is destroyed. func (s *Sandbox) DestroyContainer(cid string) error { |