gitlab.com/flarenetwork/coreth@v0.1.1/internal/debug/trace.go (about) 1 // (c) 2019-2020, Ava Labs, Inc. 2 // 3 // This file is a derived work, based on the go-ethereum library whose original 4 // notices appear below. 5 // 6 // It is distributed under a license compatible with the licensing terms of the 7 // original code from which it is derived. 8 // 9 // Much love to the original authors for their work. 10 // ********** 11 // Copyright 2016 The go-ethereum Authors 12 // This file is part of the go-ethereum library. 13 // 14 // The go-ethereum library is free software: you can redistribute it and/or modify 15 // it under the terms of the GNU Lesser General Public License as published by 16 // the Free Software Foundation, either version 3 of the License, or 17 // (at your option) any later version. 18 // 19 // The go-ethereum library is distributed in the hope that it will be useful, 20 // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 // GNU Lesser General Public License for more details. 23 // 24 // You should have received a copy of the GNU Lesser General Public License 25 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 26 27 //+build go1.5 28 29 package debug 30 31 import ( 32 "errors" 33 "os" 34 "runtime/trace" 35 36 "github.com/ethereum/go-ethereum/log" 37 ) 38 39 // StartGoTrace turns on tracing, writing to the given file. 40 func (h *HandlerT) StartGoTrace(file string) error { 41 h.mu.Lock() 42 defer h.mu.Unlock() 43 if h.traceW != nil { 44 return errors.New("trace already in progress") 45 } 46 f, err := os.Create(expandHome(file)) 47 if err != nil { 48 return err 49 } 50 if err := trace.Start(f); err != nil { 51 f.Close() 52 return err 53 } 54 h.traceW = f 55 h.traceFile = file 56 log.Info("Go tracing started", "dump", h.traceFile) 57 return nil 58 } 59 60 // StopTrace stops an ongoing trace. 61 func (h *HandlerT) StopGoTrace() error { 62 h.mu.Lock() 63 defer h.mu.Unlock() 64 trace.Stop() 65 if h.traceW == nil { 66 return errors.New("trace not in progress") 67 } 68 log.Info("Done writing Go trace", "dump", h.traceFile) 69 h.traceW.Close() 70 h.traceW = nil 71 h.traceFile = "" 72 return nil 73 }