Created
August 8, 2013 10:21
-
-
Save samuell/6183503 to your computer and use it in GitHub Desktop.
pprof not working
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "github.com/samuell/blow" | |
| "github.com/trustmaster/goflow" | |
| "runtime" | |
| "runtime/pprof" | |
| "flag" | |
| "os" | |
| "log" | |
| ) | |
| const ( | |
| NUMTHREADS = 4 | |
| ) | |
| // --------------------------------------------------------- | |
| // BaseComplementer network | |
| // --------------------------------------------------------- | |
| type BaseComplementerApp struct { | |
| flow.Graph | |
| } | |
| func NewBaseCompelenterApp() *BaseComplementerApp { | |
| network := new(BaseComplementerApp) | |
| network.InitGraphState() | |
| // Add components | |
| network.Add(new(blow.FileReader), "filereader") | |
| network.Add(new(blow.BaseComplementer), "bc1") | |
| network.Add(new(blow.BaseComplementer), "bc2") | |
| network.Add(new(blow.BaseComplementer), "bc3") | |
| network.Add(new(blow.BaseComplementer), "bc4") | |
| network.Add(new(blow.Printer), "printer") | |
| // Connect components | |
| network.MapInPort("In", "filereader", "FileName") | |
| network.Connect("filereader", "Line", "bc1", "Sequence", make(chan []byte)) | |
| network.Connect("bc1", "BaseComplementedSequence", "bc2", "Sequence", make(chan []byte)) | |
| network.Connect("bc2", "BaseComplementedSequence", "bc3", "Sequence", make(chan []byte)) | |
| network.Connect("bc3", "BaseComplementedSequence", "bc4", "Sequence", make(chan []byte)) | |
| network.Connect("bc4", "BaseComplementedSequence", "printer", "Line", make(chan []byte)) | |
| return network | |
| } | |
| // --------------------------------------------------------- | |
| // Main method | |
| // --------------------------------------------------------- | |
| var finish chan bool | |
| // Use this handler to let main() know when the network terminates | |
| func (a *BaseComplementerApp) Finish() { | |
| finish <- true | |
| } | |
| // Profiling stuff ... from http://blog.golang.org/profiling-go-programs | |
| var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") | |
| func main() { | |
| flag.Parse() | |
| if *cpuprofile != "" { | |
| f, err := os.Create(*cpuprofile) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| pprof.StartCPUProfile(f) | |
| defer pprof.StopCPUProfile() | |
| } | |
| // Set the number of Operating System-threads to use | |
| runtime.GOMAXPROCS(NUMTHREADS) | |
| // Termination signal channel | |
| finish = make(chan bool) | |
| // Create network | |
| net := NewBaseCompelenterApp() | |
| // Create the "In" channel | |
| in := make(chan string) | |
| net.SetInPort("In", in) | |
| // Run net | |
| flow.RunNet(net) | |
| // Give the Filename to read | |
| in <- "Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa" | |
| close(in) | |
| <-finish | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works now, when putting pprof.StopCPUProfile() at end of main(), without defer ... like so: