Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use Go language Program View and Diagnostic tools

Shulou Source: shulou.com Published: 2022-05-31 13:36:34 09月10日 Update

Most people do not understand the knowledge points of this article "how to use Go language programs and diagnostic tools", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this article "how to use Go language procedures and diagnostic tools".

There must be no Java developers who don't know or use the jps command, which is used to see which Java programs are running on the host.

I was also very upset when I first used the Go language program. I deployed the Go program on the company server, and other colleagues often couldn't find it because I didn't know.

Is there a tool like jps in the Go language? Of course, not only, but also produced by Google itself, official certification (this kind of problem Google can not think of). The name is also very similar to jps, called gops.

Installation

Gops is not included in the official installation package and is not a standard tool. It needs to be obtained manually.

Go get-u github.com/google/gops

Easy to use

The use of goes is very simple, let's just take a look at the help documentation.

The simplest use is gops, which directly lists the running Go programs

The PID,PPID, program name, Go version number used for compilation, and program path are listed in turn. The information is more detailed than jps, which is good.

Not only that, gops can also diagnose programs.

Diagnosis

Someone may have noticed that there is a * sign behind my memory-test program above. This is because I added the diagnostic support code for gops to the program:

If err: = agent.Listen (agent.Options {ShutdownCleanup:true}); err! = nil {log.Fatalln (err)}

For such a program, we can execute commands such as gops pprof-cpu and gops pprof-heap. (stack, gc, setgc, memstats, version, stats, trace and other commands also need to be added to the above code).

The use is very simple, just paste a little picture directly, don't talk about it.

Because the go pprof command helps us analyze the program, it is relatively more commonly used. But in the past, it was relatively troublesome to use. Now that you have gops, it's convenient to analyze cpu and memory usage.

Gops not only supports local use, but also supports remote. View agent.Options:

You can set Addr to host:port form. My side is set to ": 9779". Deploy it to a remote server and run the command gops pprof-heap 192.168.199.210 9779, and you can see:

It's totally feasible. (note that not only all pprof-heap,gops commands support remote)

Add diagnostic code to our program, and it is also very convenient to analyze the program when deployed to a remote server.

The above is about the content of this article on "how to use Go language program viewing and diagnostic tools". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more related knowledge, please pay attention to the industry information channel.

Tags: Program command tool language content language program support run code server analysis service name official that is article knowledge article yes feasible Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info macOS MySQL MariaDB Apple