Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mattb@capdev2:~/src/golang $ time ./mongo ; time ./mongo
- 821226
- 426964
- real 0m59.357s
- user 0m54.995s
- sys 0m5.464s
- 821226
- 426964
- real 0m58.964s
- user 0m54.175s
- sys 0m5.748s
- mattb@capdev2:~/src/golang $ cat mongo.go
- package main
- import (
- "flag"
- "fmt"
- "labix.org/v2/mgo"
- "labix.org/v2/mgo/bson"
- "os"
- "runtime/pprof"
- )
- type Person struct {
- Name string
- Phone string
- }
- var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
- func main() {
- flag.Parse()
- if *cpuprofile != "" {
- f, err := os.Create(*cpuprofile)
- if err != nil {
- panic(err)
- }
- pprof.StartCPUProfile(f)
- defer pprof.StopCPUProfile()
- }
- session, err := mgo.Dial("127.0.0.1:27017")
- if err != nil {
- panic(err)
- }
- defer session.Close()
- // Optional. Switch the session to a monotonic behavior.
- // session.SetMode(mgo.Monotonic, true)
- c := session.DB("logdb").C("log")
- iter := c.Find(nil).Iter()
- var res bson.M
- var cnt = 0
- var tot = 0
- for iter.Next(&res) {
- // fmt.Println(res)
- tot++
- if val, ok := res["eventType"]; ok && val == "VIDEO" {
- cnt++
- }
- }
- if iter.Err() != nil {
- panic(iter.Err())
- }
- fmt.Println(tot)
- fmt.Println(cnt)
- }
- mattb@capdev2:~/src/golang $ go tool pprof --text ./mongo mongo.prof
- Total: 5875 samples
- 312 5.3% 5.3% 505 8.6% syscall.Syscall
- 258 4.4% 9.7% 258 4.4% runtime.futex
- 230 3.9% 13.6% 806 13.7% reflect.Value.SetMapIndex
- 227 3.9% 17.5% 1342 22.8% runtime.mallocgc
- 206 3.5% 21.0% 3656 62.2% labix.org/v2/mgo/bson.(*decoder).readDocTo
- 173 2.9% 23.9% 173 2.9% runtime.memmove
- 168 2.9% 26.8% 415 7.1% sweep
- 152 2.6% 29.4% 474 8.1% runtime.MCache_Alloc
- 135 2.3% 31.7% 135 2.3% runtime.memhash
- 131 2.2% 33.9% 131 2.2% runtime.rnd
- 110 1.9% 35.8% 1511 25.7% labix.org/v2/mgo/bson.(*decoder).readElemTo
- 109 1.9% 37.6% 109 1.9% runtime.markallocated
- 105 1.8% 39.4% 132 2.2% MCentral_Alloc
- 92 1.6% 41.0% 115 2.0% itab
- 90 1.5% 42.5% 124 2.1% MCentral_Free
- 90 1.5% 44.1% 409 7.0% reflect.Value.assignTo
- 88 1.5% 45.5% 135 2.3% reflect.ValueOf
- 87 1.5% 47.0% 253 4.3% runtime.MCache_Free
- 83 1.4% 48.4% 83 1.4% scanblock
- 63 1.1% 49.5% 79 1.3% reflect.Value.iword
- 63 1.1% 50.6% 63 1.1% runtime.markspan
- 56 1.0% 51.5% 91 1.5% hash_insert_internal
- 55 0.9% 52.5% 237 4.0% labix.org/v2/mgo/bson.(*decoder).readCStr
- 55 0.9% 53.4% 55 0.9% reflect.(*commonType).runtimeType
- 53 0.9% 54.3% 53 0.9% runtime.xchg
- 51 0.9% 55.2% 51 0.9% sync/atomic.AddUint32
- 50 0.9% 56.0% 103 1.8% copyout
- 49 0.8% 56.9% 68 1.2% reflect.Value.Elem
- 48 0.8% 57.7% 148 2.5% hash_lookup
- 48 0.8% 58.5% 4039 68.7% labix.org/v2/mgo.(*Iter).Next
- 46 0.8% 59.3% 46 0.8% hash_next
- 46 0.8% 60.1% 46 0.8% runtime.memclr
- 45 0.8% 60.8% 107 1.8% assertE2Tret
- 44 0.7% 61.6% 399 6.8% reflect.Value.Set
- 43 0.7% 62.3% 57 1.0% reflect.directlyAssignable
- 42 0.7% 63.0% 163 2.8% hash_remove
- 42 0.7% 63.7% 76 1.3% hash_remove_n
- 42 0.7% 64.5% 55 0.9% ifaceeq1
- 42 0.7% 65.2% 223 3.8% runtime.convT2I
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement