Skip to content

Instantly share code, notes, and snippets.

@awreece
awreece / Simplest Possible Makefile
Created March 2, 2012 07:32
Simplest Possible Makefile
# Comments in makefiles follow the same form as comments in bash.
# Makefiles need to be named "Makefile" or "makefile".
# In makefiles, variables are declared in the following manner (the entire
# string after the equals and up to but excluding the newline is the
# content of the variable)
#
# Note: there are other ways to declare variables that are not explored in this
# tutorial.
TARGET = my_cc
@awreece
awreece / Build output
Created April 3, 2012 06:27
Strange go build output
$ go build thingy
# thingy
src/thingy/main.go:6: imported and not used: "mypkg"
src/thingy/main.go:14: undefined: mypkg
@awreece
awreece / mallocparallel_test.go
Created April 10, 2012 05:03
Parallel Malloc Test for Go
// +build ignore
// malloc test for false sharing
package main
import (
"flag"
"runtime"
@awreece
awreece / gist:2364910
Created April 12, 2012 06:09
Go HTTP server
package main
import "http"
func main() {
http.Handle("/", http.FileServer(http.Dir("/tmp")))
http.ListenAndServe(":8080", nil)
}
@awreece
awreece / Commit message
Created April 14, 2012 21:52
Go source is unreadable
$ hg blame runtime.c | grep runtime·rnd
6707: runtime·rnd(uint32 n, uint32 m)
$ hg log -r 6707
changeset: 6707:629c065d3679
user: Russ Cox <rsc@golang.org>
date: Thu Nov 04 14:00:19 2010 -0400
summary: runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
@awreece
awreece / silly.go
Created April 15, 2012 18:58
go test
package main
import (
"fmt"
)
func main() {
done := false
go func() {
for !done {
@awreece
awreece / errors
Created April 15, 2012 20:30
go tool pprof error
$ ./malloctest --proc=2 --iters=100 --prof 2>out2.prof
$ go tool pprof malloctest out2.prof
out2.prof: header size >= 2**16
go tool pprof: exit status 1
func ptr2uintptr(ptr []byte) uintptr {
return uintptr(unsafe.Pointer(ptr)) // cannot convert ptr (type []byte) to type unsafe.Pointer
/*
if bp, e := strconv.ParseInt(fmt.Sprintf("%p", ptr), 0, 32); e != nil {
log.Fatal(e)
} else {
return uintptr(bp)
}
panic("unreachable")
@awreece
awreece / Check cache
Created April 15, 2012 22:20
Check Malloc for False Sharing
areece@areece-laptop:~/coding/gomalloc$ ./malloccheck --checkcache=true --procs=1
Malloc check ran with 1 procs for 1000000 iters of size 16
Cache line shared 0 (0.00%) times
Cache was reused 993536 (99.35%) times
areece@areece-laptop:~/coding/gomalloc$ ./malloccheck --checkcache=true --procs=2
Malloc check ran with 2 procs for 1000000 iters of size 16
Cache line shared 128186 (12.82%) times
Cache was reused 859014 (85.90%) times
areece@areece-laptop:~/coding/gomalloc$ ./malloccheck --checkcache=true --procs=3
Malloc check ran with 3 procs for 1000000 iters of size 16
--- a/src/pkg/runtime/malloc.goc Mon Apr 09 15:39:59 2012 -0400
+++ b/src/pkg/runtime/malloc.goc Mon Apr 23 17:37:10 2012 -0400
@@ -25,7 +25,7 @@
// Small objects are allocated from the per-thread cache's free lists.
// Large objects (> 32 kB) are allocated straight from the heap.
void*
-runtime·mallocgc(uintptr size, uint32 flag, int32 dogc, int32 zeroed)
+INVALID_FUNC_DECLruntime·mallocgc(uintptr size, uint32 flag, int32 dogc, int32 zeroed)
{
int32 sizeclass, rate;