Gonetp

14 views
Skip to first unread message

Kevin Klues

unread,
Sep 4, 2015, 6:25:40 PM9/4/15
to akaros
I finally got around to open sourcing Andrew Gallatin's gonetp code.
For lack of a better place, I've currently put it under my github at
https://github.com/klueska/gonetp/

If/when we ever set up an Akaros organization on github to host our
various Akaros related repos (I know there is some opposition to this
for some reason), I'll move it there. I have 2 or three other repos
that would fit nicely there as well.

--
~Kevin

Andrew Gallatin

unread,
Sep 5, 2015, 10:08:42 AM9/5/15
to akaros
Kevin,

Thanks again for doing this.  I'm sorry it fell to you; I should have pushed harder to get it done before I left Google.

Drew

Andrew Gallatin

unread,
Sep 12, 2015, 9:42:49 AM9/12/15
to akaros
I'm a total go noob, and I'm having trouble with some of the magic.

The first thing that I'd like to do is to add FreeBSD support to the cpu utilization code.   When I do the magic "go get github.com/klueska/gonetp/gonetp-server" it checks things out and builds them, which is super cool.   I seem to have a clone of the git repo.

But how do I get it to re-build things?  Before doing any changes, I tried ' go build github.com/klueska/gonetp/gonetp-server' but it gives me an err:

go install github.com/klueska/gonetp/gonetp-server: build output "gonetp-server" already exists and is a directory

(same thing happens after go clean)

Sorry for the noob question,

Thanks,

Drew


On Fri, Sep 4, 2015 at 6:25 PM, Kevin Klues <klu...@gmail.com> wrote:

Kevin Klues

unread,
Sep 12, 2015, 1:12:55 PM9/12/15
to akaros
Yeah, it's a little weird, I'll try and explain...

In general, 'go build' will try and build whatever package you tell it
to, and if that package builds an executable (i.e. it has a package
'main'), then it will drop a copy of that executable in the current
directory with the same name as the package you are building. In your
case, I'm assuming you are sitting in the
$GOPATH/src/github.com/klueska/gonetp directory and trying to run this
command. As such, it will try and place an executable at this
location named 'gonetp-server'. Since you already have a folder there
by that name, it's throwing errors. What you really want is 'go
install', which will do the same thing as 'go build', except install
the executable into the 'bin' directory of the GOPATH, rather than the
current directory.

In general, 'go build' and 'go install' will recognize ANY path you
pass it as a path relative to the 'src' directory in GOPATH. The name
'github.com' is not necessarily special (it's just the convention used
by 'go get' when installing packages). You could just as easily
create your own project directly under $GOPATH/src/ and everything
would work the same.

That being said, you probably don't want to have to specify the whole
'github.com/klueska/gonetp/gonetp-server' path every time you want to
build and install your package. The go tools allow you to have a
(somewhat) normal workflow to modify the code, build it, and have it
installed -- you just have to know the right incantations. You have
to be explicit about the fact that you want go to build/install things
from somewhere other than the GOPATH.

For example, the following should work:
cd $GOPATH/src/github.com/klueska/gonetp/gonetp-server
... hack away ...
go install

This says build the package in the current directory and install it
into the GOPATH. By not passing any path at all, go know to run 'go
install' over all of the files from the current directory instead of
something relative to the GOPATH. 'go build' would actually work here
as well, but (as before), it would create a local executable (called
'main' this time because the file is called 'main.go'), instead of
installing it into the GOPATH. Probably not what you want.

The following should work as well:
cd $GOPATH/src/github.com/klueska/gonetp/
go install ./gonetp-server

The './' is important so that go recognizes the thing you are trying
to build is in a folder relative to the current directory, rather
relative to the GOPATH.

To rebuild all of the code bundled in this repo, would require the following:
cd $GOPATH/src/github.com/klueska/gonetp/
go install ./gonetp-server
go install ./gonetp-client
go install ./utilization

As a side note, 'go install' and 'go build' are identical for the
'utilization' package because it doesn't have a 'main' package (i.e.
no executable will result from building it). No matter which command
you run, it will be installed in $GOPATH/pkg

--
~Kevin

Kevin Klues

unread,
Sep 12, 2015, 5:12:04 PM9/12/15
to akaros
Also, I was just glancing through the code, and another trick worth
noting is that any file named as *_GOOS.go will only be built for that
GOOS. That is, you could move all linux specific stuff under
utilization/ into a file called cpu_linux.go, all akaros specific
stuff into cpu_akaros.go, and your new bsd stuff could go into
cpu_bsd.go. Only the file for the particular GOOS will be built, so
you don't need the hacky branching your doing in Calc_cpu() and
Read_cpu()

--
~Kevin

Andrew Gallatin

unread,
Sep 12, 2015, 8:52:34 PM9/12/15
to akaros
Ah, very cool.  I did not realize that!

Thanks,

Drew

Andrew Gallatin

unread,
Sep 12, 2015, 9:13:45 PM9/12/15
to akaros

Wait a sec.. what version of go recognizes akaros? I'm running go 1.5, and it seems like its trying to build the akaros version on freebsd, which causes conflicts on the names:

<9:08pm>viserion/gallatin:gonetp>go build ./gonetp-server
/home/gallatin/go/src/github.com/klueska/gonetp/utilization/cpu_freebsd.go:23: Read_cpu redeclared in this block
        previous declaration at /home/gallatin/go/src/github.com/klueska/gonetp/utilization/cpu_akaros.go:75

I may need to keep the hacks just because akaros seems to get compiled unconditionally 

Or did I name things incorrectly?
<9:13pm>viserion/gallatin:utilization>ls -l 
total 14
-rw-r--r--  1 gallatin  gallatin  2316 Sep 12 21:06 cpu_akaros.go
-rw-r--r--  1 gallatin  gallatin   834 Sep 12 21:09 cpu_freebsd.go
-rw-r--r--  1 gallatin  gallatin  3351 Sep 12 21:05 cpu_linux.go

Thanks,

Drew

Kevin Klues

unread,
Sep 12, 2015, 9:25:28 PM9/12/15
to akaros
Ah, yeah, that trick will only work if it the go you are using knows
about that os. Otherwise, it doesn't recognize the name as special
and treats it as a file common to all OSs. We still haven't gotten
the Go port pushed upstream, so this will only work if using my
go-akaros version of go. A workaround is to add an explicit

// +build akaros

directive at the top of the file. That should do the trick.

--
~Kevin

Kevin Klues

unread,
Sep 13, 2015, 12:17:49 AM9/13/15
to akaros
> ---------- Forwarded message ----------
> From: Andrew Gallatin <gall...@gmail.com>
> Date: Sat, Sep 12, 2015 at 6:52 PM
> Subject: Re: Gonetp
> To: Kevin Klues <klu...@google.com>
>
>
> Woot! That works! Thanks so much.
>
> Oddly, it needs to be stuck above the copyright comment. That threw
> me for a loop at first..

It's actually because I mistakenly put the copyright notice in c-style
comments /* */. The copyright should be in go style comments //. If
the copyright was in go style comments (which it actually should be),
then the build directive could go below it. The c-style comments are
valid because that is where you typically put Cgo variables and
functions. As such, the build directive needs to come before it.

I was thinking of changing the copyright notices anyway. It's better
practice to have a short 3 liner with the copyright line, the author,
and a pointer to a LICENSE file. The LICENSE file can then hold all
the info currently below the author line in the notice.

Kevin

--
~Kevin

Reply all
Reply to author
Forward
0 new messages