Skip to content

Commit 163982e

Browse files
committed
<gops><案例><丰富>
1 parent a159594 commit 163982e

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

demo/gops/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,27 @@
33
[![Build status](https://circleci.com/gh/google/gops/tree/master.svg?style=shield&circle-token=2637dc1e57d5407ae250480a86a2e553a7d20482)](https://circleci.com/gh/google/gops)
44
[![GoDoc](https://godoc.org/github.com/google/gops?status.svg)](https://godoc.org/github.com/google/gops)
55

6+
7+
测试案例效果:
8+
```sh
9+
╭─iceinto@iceinto ~
10+
╰─$ gops
11+
49371 49352 main* go1.11.2 /private/var/folders/9x/c1cwb3n9005_v5lr25jx0dtm0000gp/T/go-build216332130/b001/exe/main
12+
49412 47968 gops go1.11.2 /Users/iceinto/Documents/go/bin/gops
13+
49352 48729 go go1.11.2 /usr/local/go/bin/go
14+
╭─iceinto@iceinto ~
15+
╰─$ gops 49371
16+
parent PID: 49352
17+
threads: 6
18+
memory usage: 0.062%
19+
cpu usage: 0.093%
20+
username: iceinto
21+
cmd+args: /var/folders/9x/c1cwb3n9005_v5lr25jx0dtm0000gp/T/go-build216332130/b001/exe/main
22+
local/remote: 127.0.0.1:61338 <-> :0 (LISTEN)
23+
local/remote: *:8080 <-> :0 (LISTEN)
24+
```
25+
26+
627
gops is a command to list and diagnose Go processes currently running on your system.
728

829
```sh

demo/gops/main.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@ package main
22

33
import (
44
"log"
5-
"time"
65

6+
"github.com/astaxie/beego"
77
"github.com/google/gops/agent"
88
)
99

10+
type MainController struct {
11+
beego.Controller
12+
}
13+
14+
func (this *MainController) Get() {
15+
this.Ctx.WriteString("hello world")
16+
}
17+
1018
func main() {
11-
if err := agent.Listen(nil); err != nil {
19+
if err := agent.Listen(agent.Options{}); err != nil {
1220
log.Fatal(err)
1321
}
14-
time.Sleep(time.Hour)
22+
beego.SetLevel(beego.LevelDebug)
23+
beego.Router("/", &MainController{})
24+
beego.Run()
1525
}

demo/uber/atomic/main.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"go.uber.org/atomic"
7+
)
8+
9+
func main() {
10+
// Uint32 is a thin wrapper around the primitive uint32 type.
11+
var atom atomic.Uint32
12+
13+
// The wrapper ensures that all operations are atomic.
14+
atom.Store(42)
15+
fmt.Println(atom.Inc())
16+
fmt.Println(atom.CAS(43, 0))
17+
fmt.Println(atom.Load())
18+
}

0 commit comments

Comments
 (0)