本文整理汇总了Golang中github.com/davecheney/profile.Start函数的典型用法代码示例。如果您正苦于以下问题:Golang Start函数的具体用法?Golang Start怎么用?Golang Start使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Start函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
defer profile.Start(&profile.Config{CPUProfile: true, ProfilePath: "/tmp/"}).Stop()
// nCPU := runtime.NumCPU()
nCPU := 2
runtime.GOMAXPROCS(nCPU)
log.Printf("running on %d CPUs", nCPU)
server := network.NewServer("8081")
server.Start()
world = NewWorld(entityManager, server)
go world.worldTick()
go world.networkTick()
// wait for signal
signalChan := make(chan os.Signal, 1)
cleanupDone := make(chan bool)
signal.Notify(signalChan, os.Interrupt)
go func() {
for _ = range signalChan {
log.Printf("Received an interrupt, stopping services...\n")
server.Stop()
cleanupDone <- true
}
}()
<-cleanupDone
}
示例2: main
func main() {
password := flag.String("password", "", "Password for all redis instances")
db := flag.Int("db", 0, "DB number")
socket := flag.String("socket", "/tmp/redis-monitor.sock", "Socket to provide metrics over")
flag.Parse()
if len(flag.Args()) < 1 {
flag.Usage()
os.Exit(1)
}
s := &http.Server{
Handler: &Addresses{
Addr: flag.Args(),
Password: *password,
DB: int64(*db),
},
}
l, err := util.CreateSocket(*socket)
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
defer profile.Start(profile.MemProfile).Stop()
if err != nil {
panic(err)
}
if err := s.Serve(l); err != nil {
panic(err)
}
}
示例3: start
func start(ctx *cli.Context) {
if ctx.Bool("profile") {
pcfg := profile.Config{
CPUProfile: true,
MemProfile: true,
BlockProfile: true,
ProfilePath: ".",
}
p := profile.Start(&pcfg)
defer p.Stop()
}
initLogrus(ctx)
log.Info("Starting fullerite...")
c, err := config.ReadConfig(ctx.String("config"))
if err != nil {
return
}
collectors := startCollectors(c)
handlers := startHandlers(c)
metrics := make(chan metric.Metric)
readFromCollectors(collectors, metrics)
for metric := range metrics {
// Writing to handlers' channels. Sending metrics is
// handled asynchronously in handlers' Run functions.
writeToHandlers(handlers, metric)
}
}
示例4: main
func main() {
cfg := profile.Config{
MemProfile: true,
CPUProfile: true,
BlockProfile: true,
ProfilePath: ".",
NoShutdownHook: true,
}
defer profile.Start(&cfg).Stop()
c := make(chan int)
go func() {
//http.ListenAndServe("0.0.0.0:6060", nil)
}()
//<-c
for i := 0; i < 1000; i++ {
go func(i int) {
//fmt.Println(test())
test()
c <- i
}(i)
}
//<-c //for http
for i := 0; i < 1000; i++ {
<-c
}
//println(http.ListenAndServe("localhost:6062", nil))
}
示例5: main
func main() {
defer profile.Start(profile.CPUProfile).Stop()
flag.Parse()
dm := docmap.NewDocMap()
err := dm.DocReader()
if err != nil {
println(err)
return
}
qm := querrymap.NewQuerryMap()
qm.QuerryReader()
im := invertmap.NewInvertMap()
err = im.DocMToInM(dm)
if err != nil {
println(err)
}
if *startQuerry {
qproc.QuerriesProc(dm, qm, im)
} else {
println("No webservice")
}
}
示例6: main
func main() {
// Set up a done channel, that's shared by the whole pipeline.
// Closing this channel will kill all pipeline goroutines
//done := make(chan struct{})
//defer close(done)
// Set up logging
initializeLogging()
// Flush the log before we shutdown
defer log.Flush()
// Parse the command line flags
config := parseCommandLineFlags()
gamq.SetConfig(&config)
if config.ProfilingEnabled {
defer profile.Start(profile.CPUProfile).Stop()
}
log.Infof("Broker started on port: %d", gamq.Configuration.Port)
log.Infof("Executing on: %d threads", runtime.GOMAXPROCS(-1))
connectionManager := gamq.NewConnectionManager()
connectionManager.Start()
}
示例7: TestPerft
func TestPerft(t *testing.T) {
t.SkipNow()
cfg := profile.Config{
CPUProfile: false,
MemProfile: false,
ProfilePath: ".", // store profiles in current directory
NoShutdownHook: true, // do not hook SIGINT
}
p := profile.Start(&cfg)
//t.SkipNow()
loadPerft(t)
for _, depth := range depths {
setupBoard()
res := perft(depth, t, g)
excepted := sharperPerftLookup(depth, t)
if res == excepted {
t.Log("okPerft("+strconv.Itoa(depth)+") Result:", res, " Expected:", excepted)
} else {
t.Log("X Perft("+strconv.Itoa(depth)+") Result:", res, " Expected:", excepted)
t.Fail()
}
}
p.Stop()
}
示例8: start
func start(ctx *cli.Context) {
if ctx.Bool("profile") {
pcfg := profile.Config{
CPUProfile: true,
MemProfile: true,
BlockProfile: true,
ProfilePath: ".",
}
p := profile.Start(&pcfg)
defer p.Stop()
}
initLogrus(ctx)
log.Info("Starting fullerite...")
c, err := config.ReadConfig(ctx.String("config"))
if err != nil {
return
}
collectors := startCollectors(c)
handlers := startHandlers(c)
internalServer := internalserver.New(c, &handlers)
go internalServer.Run()
metrics := make(chan metric.Metric)
readFromCollectors(collectors, metrics)
hook := NewLogErrorHook(metrics)
log.Logger.Hooks.Add(hook)
relayMetricsToHandlers(handlers, metrics)
}
示例9: main
func main() {
port := flag.Int("port", 8080, "port")
backends := flag.Int("workers", 3, "number of workers")
strategy := flag.String("strategy", "majority", "balancing strategy ['one', 'two', 'majority', 'all']")
flag.Parse()
cfg := profile.Config{
CPUProfile: true,
MemProfile: true,
ProfilePath: ".",
}
p := profile.Start(&cfg)
defer p.Stop()
balancer := newBalancer(backends, strategy)
a := gin.Default()
a.GET("/", func(c *gin.Context) {
timeouted := make(chan bool)
result := processFirstResponse(timeouted, balancer)
select {
case data := <-result:
c.JSON(200, data)
case <-time.After(globalTimeout):
c.JSON(500, nil)
timeouted <- true
}
})
a.Run(fmt.Sprintf(":%d", *port))
}
示例10: main
func main() {
/* # # # # # ENABLING PROFILING # # # # # */
defer profile.Start(profile.CPUProfile).Stop()
/*
profileConfig := profile.Config{
CPUProfile: true,
MemProfile: true,
ProfilePath: ".", // store profiles in current directory
NoShutdownHook: true, // do not hook SIGINT
}
p := profile.Start(&profileConfig)
defer p.Stop()
*/
/* # # # # # ENABLING PROFILING # # # # # */
ts.Cache("index.html", "home.html", "404.html")
mux := MuxInstance()
mux.Handle("GET", "/index", index)
mux.Handle("GET", "/home", home)
mux.Handle("GET", "/404", err404)
mux.Handle("GET", "/user", user)
mux.Handle("GET", "/user/add", userAdd)
mux.Handle("GET", "/user/:id", userId)
mux.Handle("GET", "/:slug", landing)
mux.Handle("GET", "/login/:slug", multiLogin)
mux.Handle("GET", "/logout/:slug", logout)
mux.Handle("GET", "/protected/:slug", protected)
http.ListenAndServe(":8080", mux)
}
示例11: main
func main() {
address := flag.String("s", "127.0.0.1", "Bind Address")
port := flag.String("p", "11211", "Bind Port")
filename := flag.String("f", "./memcached.db", "path and file for database")
pf := flag.Bool("q", false, "Enable profiling")
flag.Usage = func() {
fmt.Println("Usage: beano [-s ip] [-p port] [-f /path/to/db/file -q]")
fmt.Println("default ip: 127.0.0.1")
fmt.Println("default port: 11211")
fmt.Println("default file: ./memcached.db")
fmt.Println("-q enables profiling to /tmp/*.prof")
os.Exit(1)
}
flag.Parse()
if *pf == true {
c := profile.Config{BlockProfile: true, CPUProfile: true, ProfilePath: "/tmp", MemProfile: true, Quiet: false}
defer profile.Start(&c).Stop()
}
var cpuinfo string
if n := runtime.NumCPU(); n > 1 {
runtime.GOMAXPROCS(n)
cpuinfo = fmt.Sprintf("%d CPUs", n)
} else {
cpuinfo = "1 CPU"
}
log.Info("beano (%s)", cpuinfo)
initializeMetrics(*filename)
serve(*address, *port, *filename)
}
示例12: main
func main() {
fmt.Println("Server Starting on port:8080")
defer profile.Start(profile.CPUProfile).Stop()
pc := controller.NewProjectController(getDbSession())
uc := controller.NewUserController(getDbSession())
sc := controller.NewSensorController(getDbSession())
vc := controller.NewVirtSensorController(getDbSession())
router := httprouter.New()
//Project Management Routings
router.Handle("GET", "/projects", pc.Project)
router.Handle("POST", "/addproject", pc.AddProject)
router.Handle("GET", "/projects/:projectName/selectsensors", pc.SelectSensors)
router.Handle("POST", "/projects/:projectName/addvirtualsensors", pc.AddSensorToProject)
router.Handle("GET", "/projects/:projectName/dashboard", pc.Dashboard)
router.Handle("GET", "/projects/:projectName/terminate", pc.TerminateProject)
/*router.Handle("GET", "/sendvirtualsensordetails/", handle)
router.Handle("POST", "/projects/:projectName/addvirtualsensors", handle)
router.Handle("GET", "/projects/:projectName/startvirtsensor/:vsensorid", handle)
router.Handle("GET", "/projects/:projectName/stopvirtsensor/:vsensorid", handle)
router.Handle("GET", "/projects/:projectName/terminatevirtsensor/:vsensorid", handle)*/
// User Management Routings
router.Handle("GET", "/", uc.Index)
router.Handle("GET", "/logout", uc.Logout)
router.Handle("POST", "/users/login", uc.Login)
router.Handle("POST", "/users/signup", uc.Signup)
router.Handle("PUT", "/users/updateuser/:username", uc.UpdateUser)
router.Handle("DELETE", "/users/deleteuser/:username", uc.DeleteUser)
router.Handle("GET", "/time", uc.Datahandler)
router.Handle("GET", "/gettime", uc.HandlerGetData)
//Physical Sensor Management Routings
router.Handle("POST", "/sensors", sc.AddSensor)
router.Handle("PUT", "/sensors/updatesensor/:sensorName", sc.UpdateSensor)
router.Handle("DELETE", "/sensors/deletesensor/:sensorName", sc.DeleteSensor)
router.Handle("GET", "/sensors/getsensor/:sensorName", sc.GetSensorByName)
router.Handle("POST", "/authenticatesenor", sc.AuthenticateSensor)
router.Handle("GET", "/getsensorbyowner/:ownerId", sc.GetSensorByOwner)
router.Handle("GET", "/getallsharedsensors", sc.GetAllSharedSensors)
//router.Handle("POST", "/getsensordata",sc.GetSensorData)
//router.Handle("PUT", "/sensors/togglesensor/:sensorName", ToggelSensor)
/*router.Handle("GET", "/getsensorbyowner/:ownerId", GetSensorById)*/
// Virtual Sensor Management Routings
router.Handle("POST", "/virtsensors", vc.AddVirtSensor)
router.Handle("PUT", "/removevirtsensors/:vSensorName", vc.RemoveVirtSensor)
router.Handle("GET", "/stopvirtsensors/:vSensorName", vc.StopVirtSensor)
router.Handle("GET", "/resumevirtsensors/:vSensorName", vc.ResumeVirtSensor)
router.Handle(("GET"), "/projects/:projectName/sensors/:vSensorName", vc.GetVSensorDetails)
//fileServer := http.StripPrefix("/static/", http.FileServer(http.Dir("static")))
router.NotFound = http.StripPrefix("/static/", http.FileServer(http.Dir("static")))
log.Fatal(http.ListenAndServe(":8081", router))
}
示例13: main
func main() {
profileKind := os.Args[1]
switch profileKind {
case "cpu":
defer profile.Start(profile.CPUProfile).Stop()
case "mem":
defer profile.Start(profile.MemProfile).Stop()
case "block":
defer profile.Start(profile.BlockProfile).Stop()
default:
fmt.Println("only cpu, mem and block are valid profile arguments")
return
}
for i := 0; i < 1000000; i++ {
user := &User{
Name: "Emil Sjölander",
Repos: []Repo{
Repo{
Name: "goson",
URL: "https://github.com/emilsjolander/goson",
Stars: 0,
Forks: 0,
},
Repo{
Name: "StickyListHeaders",
URL: "https://github.com/emilsjolander/StickyListHeaders",
Stars: 722,
Forks: 197,
},
Repo{
Name: "android-FlipView",
URL: "https://github.com/emilsjolander/android-FlipView",
Stars: 157,
Forks: 47,
},
},
}
goson.Render("user", goson.Args{"User": user})
}
}
示例14: main
func main() {
defer profile.Start(profile.CPUProfile).Stop()
flag.Parse()
for _, path := range flag.Args() {
err := flac2wav(path)
if err != nil {
log.Fatalln(err)
}
}
}
示例15: initProfiler
func initProfiler() {
cfg := profile.Config{
MemProfile: true,
CPUProfile: true,
ProfilePath: ".", // store profiles in current directory
}
// p.Stop() must be called before the program exits to
// ensure profiling information is written to disk.
profiler = profile.Start(&cfg)
}