10/10/2023 0 Comments Golang write to fileSimilarly, we can also see a graph of CPU with command – go tool pprof -http :8080 cpu. Let’s see how our benchmark changes after removing fmt.Sprintf(). So we are going to use strconv.Itoa() instead. Here we can see our Sprintf method is using a lot of memory. Once again, remember that os.Create () will truncate the destination file if it already exists. Notice that fmt.Fprintf () can write to any io.Writer interface. This will start an HTTP server on port 8080 and open URL – which will display how memory is getting allocated. The use of the fmt.Fprintf () function for writing allows us to write formatted text to files in a way that is similar to the way the fmt.Printf () function works. Let’s use go tool pprof -http :8080 mem.out command. Not different from our previous command but the files are created. The output of this command will be like below, benchmem -cpuprofile=cpu.out -memprofile=mem.out -trace=trace.out We will look into the go tool pprof part today.įirst, let’s create the profiles, We will be creating 3 files which will contain profiles for the following -cpuprofile, -memprofile, -trace We can use pprof as a web server or with go tool pprof. Pprof is basically the profiling tool/package provided in the standard library.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |