In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to dump GOSSAFUNC diagrams in Go". In daily operation, I believe many people have doubts about how to dump GOSSAFUNC diagrams in Go. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to dump GOSSAFUNC diagrams in Go". Next, please follow the editor to study!
The SSA back end of the Go compiler includes a tool that generates HTML debug output at compile time. This article shows how to print SSA output for functions and methods.
Let's start with a sample program that contains functions, value methods, and pointer methods:
Package main import ("fmt") type Numbers struct {vals [] int} func (n * Numbers) Add (v int) {n.vals = append (n.vals, v)} func (n Numbers) Average () float64 {sum: = 0.0 for _ Num: = range n.vals {sum + = float64 (num)} return sum / float64 (len (n.vals))} func main () {var numbers Numbers numbers.Add (200) numbers.Add (43) numbers.Add (- 6) fmt.Println (numbers.Average ())}
SSA debug output is controlled by the GOSSAFUNC environment variable. This variable contains the name of the function to be dumped. This is not the fully qualified name of the function. For the above func main, the function name is main instead of main.main.
% env GOSSAFUNC=main go buildruntimedumped SSA to. /.. / go/src/runtime/ssa.htmltdumped SSA to. / ssa.html
In this example, GOSSAFUNC=main matches both main.main and a function named runtime.main. [1] this is a bit unlucky, but in fact it may not be a big deal, because if you want to make performance adjustments to the code, it won't appear in the huge spaghetti chunks in func main.
Your code is more likely to be in the method, and you may have read this article and looked for SSA output that can dump the method.
To print SSA debugging for the pointer method func (n * Numbers) Add, the equivalent function is called (* Numbers) .Add: [2]
% env "GOSSAFUNC= (* Numbers) .add" go buildtdumped SSA to. / ssa.html
To print SSA debugging for the value method func (n Numbers) Average, the equivalent function is named (* Numbers) .average, even if it is a value method:
% env "GOSSAFUNC= (* Numbers) .average" go buildtdumped SSA to. / ssa.html
If you do not build Go from source code, the path to the runtime package may be read-only and you may receive an error message. Please do not use sudo to resolve this problem.
Note the shell reference.
At this point, the study of "how to dump GOSSAFUNC diagrams in Go" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.