OLD | NEW |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Package pprof writes runtime profiling data in the format expected | 5 // Package pprof writes runtime profiling data in the format expected |
6 // by the pprof visualization tool. | 6 // by the pprof visualization tool. |
7 // For more information about pprof, see | 7 // For more information about pprof, see |
8 // http://code.google.com/p/google-perftools/. | 8 // http://code.google.com/p/google-perftools/. |
9 package pprof | 9 package pprof |
10 | 10 |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 // but in practice operating systems cannot trigger signals | 567 // but in practice operating systems cannot trigger signals |
568 // at more than about 500 Hz, and our processing of the | 568 // at more than about 500 Hz, and our processing of the |
569 // signal is not cheap (mostly getting the stack trace). | 569 // signal is not cheap (mostly getting the stack trace). |
570 // 100 Hz is a reasonable choice: it is frequent enough to | 570 // 100 Hz is a reasonable choice: it is frequent enough to |
571 // produce useful data, rare enough not to bog down the | 571 // produce useful data, rare enough not to bog down the |
572 // system, and a nice round number to make it easy to | 572 // system, and a nice round number to make it easy to |
573 // convert sample counts to seconds. Instead of requiring | 573 // convert sample counts to seconds. Instead of requiring |
574 // each client to specify the frequency, we hard code it. | 574 // each client to specify the frequency, we hard code it. |
575 const hz = 100 | 575 const hz = 100 |
576 | 576 |
577 // Avoid queueing behind StopCPUProfile. | |
578 // Could use TryLock instead if we had it. | |
579 if cpu.profiling { | |
580 return fmt.Errorf("cpu profiling already in use") | |
581 } | |
582 | |
583 cpu.Lock() | 577 cpu.Lock() |
584 defer cpu.Unlock() | 578 defer cpu.Unlock() |
585 if cpu.done == nil { | 579 if cpu.done == nil { |
586 cpu.done = make(chan bool) | 580 cpu.done = make(chan bool) |
587 } | 581 } |
588 // Double-check. | 582 // Double-check. |
589 if cpu.profiling { | 583 if cpu.profiling { |
590 return fmt.Errorf("cpu profiling already in use") | 584 return fmt.Errorf("cpu profiling already in use") |
591 } | 585 } |
592 cpu.profiling = true | 586 cpu.profiling = true |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 } | 664 } |
671 } | 665 } |
672 | 666 |
673 if tw != nil { | 667 if tw != nil { |
674 tw.Flush() | 668 tw.Flush() |
675 } | 669 } |
676 return b.Flush() | 670 return b.Flush() |
677 } | 671 } |
678 | 672 |
679 func runtime_cyclesPerSecond() int64 | 673 func runtime_cyclesPerSecond() int64 |
OLD | NEW |