OLD | NEW |
1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package profiling | 5 package profiling |
6 | 6 |
7 import ( | 7 import ( |
8 "flag" | 8 "flag" |
9 "fmt" | 9 "fmt" |
10 "net" | 10 "net" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 p.getLogger().Warningf("Failed to stop profile HTTP serv
er: %s", err) | 108 p.getLogger().Warningf("Failed to stop profile HTTP serv
er: %s", err) |
109 } | 109 } |
110 p.listener = nil | 110 p.listener = nil |
111 } | 111 } |
112 | 112 |
113 // Take one final snapshot. | 113 // Take one final snapshot. |
114 p.DumpSnapshot() | 114 p.DumpSnapshot() |
115 } | 115 } |
116 | 116 |
117 // DumpSnapshot dumps a profile snapshot to the configured output directory. If | 117 // DumpSnapshot dumps a profile snapshot to the configured output directory. If |
118 // no output directory is configured, nothing wil happen. | 118 // no output directory is configured, nothing will happen. |
119 func (p *Profiler) DumpSnapshot() error { | 119 func (p *Profiler) DumpSnapshot() error { |
120 if p.Dir == "" { | 120 if p.Dir == "" { |
121 return nil | 121 return nil |
122 } | 122 } |
123 | 123 |
124 if err := p.dumpHeapProfile(); err != nil { | 124 if err := p.dumpHeapProfile(); err != nil { |
125 return errors.Annotate(err).Reason("failed to dump heap profile"
).Err() | 125 return errors.Annotate(err).Reason("failed to dump heap profile"
).Err() |
126 } | 126 } |
127 return nil | 127 return nil |
128 } | 128 } |
(...skipping 22 matching lines...) Expand all Loading... |
151 counter := atomic.AddUint32(&p.pathCounter, 1) - 1 | 151 counter := atomic.AddUint32(&p.pathCounter, 1) - 1 |
152 return filepath.Join(p.Dir, fmt.Sprintf("%s_%d_%d.prof", base, now.Unix(
), counter)) | 152 return filepath.Join(p.Dir, fmt.Sprintf("%s_%d_%d.prof", base, now.Unix(
), counter)) |
153 } | 153 } |
154 | 154 |
155 func (p *Profiler) getLogger() logging.Logger { | 155 func (p *Profiler) getLogger() logging.Logger { |
156 if p.Logger != nil { | 156 if p.Logger != nil { |
157 return p.Logger | 157 return p.Logger |
158 } | 158 } |
159 return logging.Null | 159 return logging.Null |
160 } | 160 } |
OLD | NEW |