This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
type BigStruct struct { | |
_ int64 | |
_ int64 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func MountNewNetworkNamespace(nsTarget string) (filesystem.Unmounter, error) { | |
_, err := os.OpenFile(nsTarget, syscall.O_RDONLY|syscall.O_CREAT|syscall.O_EXCL, 0644) | |
if err != nil { | |
return nil, errors.Wrap(err, "unable to create target file") | |
} | |
// store current network namespace | |
file, err = os.OpenFile("/proc/self/ns/net", os.O_RDONLY, 0) | |
if err != nil { | |
return nil, err |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (c *Container) SetupNetwork(bridge string) (filesystem.Unmounter, error) { | |
nsMountTarget := filepath.Join(netnsPath, c.Digest) | |
vethName := fmt.Sprintf("veth%.7s", c.Digest) | |
peerName := fmt.Sprintf("P%s", vethName) | |
if err := network.SetupVirtualEthernet(vethName, peerName); err != nil { | |
return nil, err | |
} | |
if err := network.LinkSetMaster(vethName, bridge); err != nil { | |
return nil, err |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
args := []string{"fork"} | |
... | |
cmd := reexec.Command(args...) | |
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr | |
cmd.SysProcAttr = &syscall.SysProcAttr{ | |
Cloneflags: syscall.CLONE_NEWUTS | | |
syscall.CLONE_NEWIPC | | |
syscall.CLONE_NEWPID | | |
syscall.CLONE_NEWNS, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"encoding/json" | |
"math/rand" | |
"net/http" | |
_ "net/http/pprof" | |
"time" | |
) | |
func main() { | |
http.HandleFunc("/log", logHandler) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CPUProfile enables cpu profiling. Note: Default is CPU | |
defer profile.Start(profile.CPUProfile).Stop() | |
// GoroutineProfile enables goroutine profiling. | |
// It returns all Goroutines alive when defer occurs. | |
defer profile.Start(profile.GoroutineProfile).Stop() | |
// BlockProfile enables block (contention) profiling. | |
defer profile.Start(profile.BlockProfile).Stop() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
defer profile.Start(profile.ProfilePath(".")).Stop() | |
// do something | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func init() { | |
go func() { | |
http.ListenAndServe(":1234", nil) | |
}() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func init() { | |
http.HandleFunc("/debug/pprof/", Index) | |
http.HandleFunc("/debug/pprof/cmdline", Cmdline) | |
http.HandleFunc("/debug/pprof/profile", Profile) | |
http.HandleFunc("/debug/pprof/symbol", Symbol) | |
http.HandleFunc("/debug/pprof/trace", Trace) | |
} |
NewerOlder