在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:divan/gotrace开源软件地址:https://github.com/divan/gotrace开源编程语言:JavaScript 96.7%开源软件介绍:GoTrace - Go Concurrency 3D TracerGoTrace is a 3D WebGL visualizer of Go concurrency. It analyzes trace produced by Original article: https://divan.github.io/posts/go_concurrency_visualize/ Slides from GopherCon'16: http://divan.github.io/talks/2016/gophercon/ IntroThis tool generates 3D visualization of Go concurrency flow by analyzing its execution trace. To view the visualization you need a modern browser with WebGL support (pretty much any browser nowadays). Its primary goal is to be an educational tool for Go concurrency. It works well with small programs that produce short traces (see Scale issues below). UsageFirst, install gotrace:
Second, use patched Go runtime to produce trace and binary. There are two ways to do it - use a docker container or apply the patch locally. Quick example using pre-made docker image (jump to detailed instructions):
Or, using local patched Go installation (jump to detailed instructions):
Prepare your programNow, please learn some important things before trying your own code. Feel free to play first with code in examples/ folder. Theoretically, gotrace should do all the magic itself and be able to handle any Go program. That's the goal, but at the present moment, if you want to get good/meaningful visualization, you should follow some rules and suggestions. Make it shortThe height of program visualization currently is a fixed value, so any trace fits into the screen height. This means, that example running 1 minute will be visualized at different scale from program running 1 second. Depending on what you try to see, but rule of thumb is - the shorter execution time, the better. See Insert runtime/trace yourselfIn order to produce the trace, your program should be instrumented with special code. package main
import (
"os"
"runtime/trace"
)
func main() {
trace.Start(os.Stderr)
...
trace.Stop()
} Currently it's important to write trace into os.Stderr. See issue #X if your example uses stderr for other needs. Consider inserting very short time.Sleep() callsIf you are trying to visualize some things that happen at nanosecond/microsecond level, it could be wise to insert For example, if your code runs 100 goroutines in a loop, their IDs and their start order probably would be different, resulting in slightly messed picture. So, changing: for i := 0; i < 100; i++ {
go player(table)
} to for i := 0; i < 100; i++ {
time.Sleep(1 * time.Millisecond)
go player(table)
} will help to make better visualization. Try to keep number of goroutines/events smallThe fewer objects that will be rendered, the better. If you have many things to render, WebGL will just hang your browser. Also, keep in mind, that point of visualization is to express something. So running 1024 workers will result in a heavy visualization where you will not see separate goroutines. Setting this value to, say, 36 will produce much more clear picture. Detailed instructionsThe next step is to build your program. You will need to build using the patched Go runtime. So if you patched it yourself (see Appendix A), you just have to run Using DockerYou will need Docker installed and running. Then pull the image from Docker Hub:
or build it yourself:
If everything went ok, you should have Now, use this command to produce the binary: MacOS X
Linux
Windows
3. Run it and save the trace.Once you have the binary, you can run it and save the trace:
4. Run |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论