Golang Graphviz and Pprof

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

sudo port install Graphviz

fuyundemacbook-pro:~ fuyun$ sudo port install Graphviz

Warning:the Xcode Command Line Tools don ' t appear to be installed; Most ports would likely fail to build.

Warning:install them by running ' xcode-select--install '.

---> Computing dependencies for Graphviz

---> Fetching archive for Graphviz

---> Attempting to fetch GRAPHVIZ-2.38.0_0+PANGOCAIRO+X11.DARWIN_14.X86_64.TBZ2 from/HTTP Mse.uk.packages.macports.org/sites/packages.macports.org/graphviz

---> Attempting to fetch GRAPHVIZ-2.38.0_0+PANGOCAIRO+X11.DARWIN_14.X86_64.TBZ2 from http://packages.macports.org /graphviz

---> Attempting to fetch GRAPHVIZ-2.38.0_0+PANGOCAIRO+X11.DARWIN_14.X86_64.TBZ2 from/HTTP Lil.fr.packages.macports.org/graphviz

---> Fetching distfiles for Graphviz

---> Verifying checksums for Graphviz

---> Extracting graphviz

---> Configuring Graphviz

---> Building graphviz

---> Staging graphviz into DestRoot

---> Installing Graphviz @2.38.0_0+pangocairo+x11

---> Activating graphviz @2.38.0_0+pangocairo+x11

---> Cleaning graphviz

---> Updating database of binaries

---> Scanning binaries for linking errors

---> No broken files found.


Terminal Run installation Xcode-select to completion

Xcode-select--install


Clear Graphviz not installed successfully before

sudo port uninstall Graphviz


Reinstall Graphviz

fuyundemacbook-pro:~ fuyun$ sudo port install Graphviz

---> Computing dependencies for Graphviz

---> Fetching archive for Graphviz

---> Attempting to fetch GRAPHVIZ-2.38.0_0+PANGOCAIRO+X11.DARWIN_14.X86_64.TBZ2 from/HTTP Mse.uk.packages.macports.org/sites/packages.macports.org/graphviz

---> Attempting to fetch GRAPHVIZ-2.38.0_0+PANGOCAIRO+X11.DARWIN_14.X86_64.TBZ2 from http://packages.macports.org /graphviz

---> Attempting to fetch GRAPHVIZ-2.38.0_0+PANGOCAIRO+X11.DARWIN_14.X86_64.TBZ2 from/HTTP Lil.fr.packages.macports.org/graphviz

---> Fetching distfiles for Graphviz

---> Verifying checksums for Graphviz

---> Extracting graphviz

---> Configuring Graphviz

---> Building graphviz

---> Staging graphviz into DestRoot

---> Installing Graphviz @2.38.0_0+pangocairo+x11

---> Activating graphviz @2.38.0_0+pangocairo+x11

---> Cleaning graphviz

---> Updating database of binaries

---> Scanning binaries for linking errors

---> No broken files found.


Run the Go tool pprof 30 seconds wait

fuyundemacbook-pro:~ fuyun$ Go tool pprof Http://localhost:8080/debug/pprof/profile

Fetching profile from Http://localhost:8080/debug/pprof/profile

Please wait ... (30s)

Saved Profile in/users/fuyun/pprof/pprof.localhost:8080.samples.cpu.002.pb.gz

Entering interactive mode (type ' help ' for commands)


In this 30 seconds the new terminal is tested concurrently

Ab-n 10000-c http://localhost:8080/storemanager/goods?telphone=18200566251


This is apachebench, Version 2.3 < $Revision: 1554214 $>

Copyright 1996 Adam Twiss, Zeus technology LTD, http://www.zeustech.net/

Licensed to the Apache software Foundation, http://www.apache.org/


Benchmarking localhost (Be patient)

Completed requests

Completed requests

Completed requests

Completed 4000 requests

Completed requests

Completed 6000 requests

Completed 7000 Requests

Completed 8000 requests

Completed 9000 requests

Completed 10000 requests

Finished 10000 requests

Server Software:

Server Hostname:localhost

Server port:8080


Document Path:/storemanager/goods?telphone=18200566251

Document length:0 bytes


Concurrency level:200

Time taken for tests:9.711 seconds

Complete requests:10000

Failed requests:9793

(connect:0, receive:0, length:9793, exceptions:0)

Total transferred:21197939 bytes

HTML transferred:19960000 bytes

Requests per second:1029.74 [#/sec] (mean)

Time per request:194.223 [MS] (mean)

Time per request:0.971 [MS] (mean, across all concurrent requests)

Transfer rate:2131.68 [Kbytes/sec] Received


Connection Times (MS)

Min MEAN[+/-SD] Median max

connect:0 0 0.8 0 9

PROCESSING:90 192 24.7 191 264

Waiting:2 192 24.7 191 264

TOTAL:99 192 24.6 191 268


Percentage of the requests served within a certain time (MS)

50% 191

66% 203

75% 210

80% 214

90% 226

95% 233

98% 246

99% 255

100% 268 (Longest request)


When a sample is obtained, a Web command can be built at the pprof command prompt, and if no browser is opened by default, select the SVG file command+i Select Open mode to pick a browser, click Change All.

(pprof) Web

(PPROF)


Note that the way in the Web, if you use the standard Servermux only need to include import _ "Net/http/pprof" on the line, if the custom route needs to use pprof corresponding function to output and attach debug parameters, This way the browser does not display the byte.

The debug parameter is used to turn on additional output. If debug=0, only the hexadecimal address required for pprof will be printed, and if debug=1, the address will be translated into a function name and line number and annotated to allow programmers to read the analysis report without tools.

Predefined profiles give meaning to other debug values. For example, when you print a "Go" analysis report, debug=2: When you are on the verge of collapse due to an unrecoverable panic, use the same format as the Go program to print the stack information for the go process.


Then use the Pprof tool-to-look at the heap profile:

http://localhost:8080/debug/pprof/heap

Or to the look in a 30-second CPU profile:

http://localhost:8080/Debug/pprof/profile

Or to look at the Goroutine blocking profile:

http://localhost:8080/Debug/pprof/block

For specific reference: Http://blog.golang.org/profiling-go-programs   https://github.com/hyper-carrot/go_command_ Tutorial/blob/master/0.12.md

Application

If your go program is just an application, such as calculating the Fabonacci sequence, then you cannot use the NET/HTTP/PPROF package and you need to use Runtime/pprof. The specific approach is to use the pprof. Startcpuprofile and Pprof.stopcpuprofile. For example, the following:

var cpuprofile = flag. String ("Cpuprofile", "", "Write CPU profile to file") Func main () {    flag. Parse ()    if *cpuprofile! = "" {        F, err: = OS. Create (*cpuprofile)        if err! = Nil {            log. Fatal (Err)        }        pprof. Startcpuprofile (f)        defer pprof. Stopcpuprofile ()    }

...

Add a--cpuprofile parameter when running the program, such as Fabonacci--cpuprofile=fabonacci.prof

The CPU information will be recorded in the xxx.prof when the program is running.

The next step is to use this prof information to make a performance analysis diagram (need to install Graphviz).

Use Go tool pprof (application) (application's Prof file)

When you enter Pprof, the SVG file is generated in/tmp using the Web command, which can be viewed under the browser. Look like this:

If your program is very simple, such as only println a statement, you use Pprof. Startcpuprofile doesn't print anything.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.