github.com/MetalBlockchain/subnet-evm@v0.4.9/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 //go:build go1.5 28 // +build go1.5 29 30 package debug 31 32 import ( 33 "errors" 34 "os" 35 "runtime/trace" 36 37 "github.com/ethereum/go-ethereum/log" 38 ) 39 40 // StartGoTrace turns on tracing, writing to the given file. 41 func (h *HandlerT) StartGoTrace(file string) error { 42 h.mu.Lock() 43 defer h.mu.Unlock() 44 if h.traceW != nil { 45 return errors.New("trace already in progress") 46 } 47 f, err := os.Create(expandHome(file)) 48 if err != nil { 49 return err 50 } 51 if err := trace.Start(f); err != nil { 52 f.Close() 53 return err 54 } 55 h.traceW = f 56 h.traceFile = file 57 log.Info("Go tracing started", "dump", h.traceFile) 58 return nil 59 } 60 61 // StopTrace stops an ongoing trace. 62 func (h *HandlerT) StopGoTrace() error { 63 h.mu.Lock() 64 defer h.mu.Unlock() 65 trace.Stop() 66 if h.traceW == nil { 67 return errors.New("trace not in progress") 68 } 69 log.Info("Done writing Go trace", "dump", h.traceFile) 70 h.traceW.Close() 71 h.traceW = nil 72 h.traceFile = "" 73 return nil 74 }