I can't figure out how to correctly use the profiler

968 views
Skip to first unread message

zachary...@gmail.com

unread,
Nov 7, 2015, 11:28:19 PM11/7/15
to golang-nuts
Hi, I'm working on a server for a game and I'm encountering a lot of lag on the server. I wanted to set up the profiler to see which functions were causing the most lag but I can't seem to figure out how to set it up:( Here's some of my code, I'm not really sure what code is relevant to this issue so just ask if you want to see more.

import (
)


var cfg = profile.Config{
MemProfile:     true,
ProfilePath:    ".",  // store profiles in current directory
NoShutdownHook: true, // do not hook SIGINT
}

var p = profile.Start(&cfg)

func main() {

rand.Seed(time.Now().Unix())

spawnNPCs()
loadAllItemData()

        //I'm sharing this code because I'm not sure if the fact that all the functions are on separate threads might be the problem.
go listenOn843()
go getConsoleInput()
go moveBullets()
go updatePlayers()
go updateNPCs()
go sendData()
listenForPlayers()
}

//I then stop the profile later on in the program via a command entered in the console

and I'll attach the pdf it generates. It doesn't show much info:( 

any help or information at all would be appreciated! I'm also not sure how to read the pdf, if anyone could explain the numbers I would be SUPER grateful!

Thanks!
callgraph.pdf

Shawn Milochik

unread,
Nov 7, 2015, 11:42:14 PM11/7/15
to golang-nuts
Have you read this?

What does "newm" do? Is it creating a new item in memory when you could possibly re-use an existing one, possibly using the method described here?

(watch from 1:01:55 to 1:07:55).


Matthew Zimmerman

unread,
Nov 7, 2015, 11:42:17 PM11/7/15
to zachary...@gmail.com, golang-nuts

Do everything in the overview, it's fantastic.

go build && ./binarytorun

then in another terminal:
go tool pprof binarytorun http://localhost:6060/debug/pprof/profile

The pprof page doesn't show in the examples to include your binary on the go tool line.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

zachary...@gmail.com

unread,
Nov 8, 2015, 12:47:01 AM11/8/15
to golang-nuts, Sh...@milochik.com
I've read that and tried it and it produces basically the same thing:/
Message has been deleted

zachary...@gmail.com

unread,
Nov 8, 2015, 12:52:00 AM11/8/15
to golang-nuts, zachary...@gmail.com
I tried that and I just get a web page that says "Could not enable CPU profiling: cpu profiling already in use"
Do you know what that means?

It also downloads a profile, here is what is shows when exported to a pdf.
callgraph.pdf

Giulio Iotti

unread,
Nov 8, 2015, 4:48:36 AM11/8/15
to golang-nuts, zachary...@gmail.com
On Sunday, November 8, 2015 at 7:52:00 AM UTC+2, zachary...@gmail.com wrote:
I tried that and I just get a web page that says "Could not enable CPU profiling: cpu profiling already in use"
Do you know what that means?

Please try putting the "profile.Start(&cfg)" line in main, like it's describe in the documentation. Also, stop it with defer:

defer profile.Start(&cfg).Stop()

-- 
Giulio Iotti

Matthew Zimmerman

unread,
Nov 8, 2015, 7:47:31 AM11/8/15
to Giulio Iotti, golang-nuts, zachary...@gmail.com

The issue is you're now using different methods.  The net/pprof import enables almost everything and you can fetch it on the fly.  Dave Cheney's package is more explicit and only enables certain profiles, but it's more powerful on which ones it helps you enable.  Enabling both will cause the error you're seeing.

My recommendation would be to remove all of your profiling specific code with exception to what you see in the net/pprof documentation which is the import and the http listener (if you didn't have one already)


--

zachary...@gmail.com

unread,
Nov 8, 2015, 11:31:40 AM11/8/15
to golang-nuts, dullg...@gmail.com, zachary...@gmail.com
I commented out everything that has to do with Dave Cheney's package and I still get that error when I go to the web page:(
Message has been deleted

zachary...@gmail.com

unread,
Nov 8, 2015, 11:51:22 AM11/8/15
to golang-nuts, zachary...@gmail.com
Okay, I did that. Here is my code now:

var cfg = profile.Config{
MemProfile:     true,
ProfilePath:    ".",  // store profiles in current directory
NoShutdownHook: true, // do not hook SIGINT
}

func main() {

p := profile.Start(&cfg)

rand.Seed(time.Now().Unix())

spawnNPCs()
loadAllItemData()

go listenOn843()
go getConsoleInput()
go moveBullets()
go updatePlayers()
go updateNPCs()
go sendData()
listenForPlayers()

p.Stop()
}

The program runs until I enter the command "stop", so it has enough time to collect data. 

But it still doesn't give as much information I feel like it should:( I'll attach the new pdf.
callgraph.pdf

Jochen Voss

unread,
Nov 8, 2015, 1:15:47 PM11/8/15
to golang-nuts, zachary...@gmail.com
Hi Zacharym


On Sunday, 8 November 2015 16:51:22 UTC, zachary...@gmail.com wrote:
The program runs until I enter the command "stop", so it has enough time to collect data. 

But it still doesn't give as much information I feel like it should:( I'll attach the new pdf.

Are you on MacOSX?  I think the profiler does not work on MacOSX (something to do with samples being counted towards the wrong thread, if I remember correctly).

All the best,
Jochen

andrey mirtchovski

unread,
Nov 8, 2015, 3:05:09 PM11/8/15
to Jochen Voss, golang-nuts, zachary...@gmail.com
> Are you on MacOSX? I think the profiler does not work on MacOSX (something
> to do with samples being counted towards the wrong thread, if I remember
> correctly).

here's a reference for profiling on OSX: http://research.swtch.com/macpprof

Carlos Castillo

unread,
Nov 8, 2015, 6:47:36 PM11/8/15
to golang-nuts, zachary...@gmail.com
Actually, as of OSX 10.11 (El Capitan) CPU profiling works "out of the box" for go programs. As far as I can tell from the original example, it was attempting to do memory profiling, which always worked on OSX, but may not have been the profile the poster was interested in (it looks like he wants a CPU Profile).

zachary...@gmail.com

unread,
Nov 8, 2015, 8:19:51 PM11/8/15
to golang-nuts, zachary...@gmail.com
Shoot okay, I'm running 10.10, maybe updating will fix the issue. I'll update then see what happens, and if that doesn't work I'll check out what Andrey posted and if that also doesn't work I'll post here:)
Reply all
Reply to author
Forward
0 new messages