Advertisement
Guest User

Untitled

a guest
Mar 28th, 2013
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.89 KB | None | 0 0
  1. mattb@capdev2:~/src/golang $ time ./mongo ; time ./mongo
  2. 821226
  3. 426964
  4.  
  5. real    0m59.357s
  6. user    0m54.995s
  7. sys     0m5.464s
  8. 821226
  9. 426964
  10.  
  11. real    0m58.964s
  12. user    0m54.175s
  13. sys     0m5.748s
  14.  
  15. mattb@capdev2:~/src/golang $ cat mongo.go
  16. package main
  17.  
  18. import (
  19.         "flag"
  20.         "fmt"
  21.         "labix.org/v2/mgo"
  22.         "labix.org/v2/mgo/bson"
  23.         "os"
  24.         "runtime/pprof"
  25. )
  26.  
  27. type Person struct {
  28.         Name  string
  29.         Phone string
  30. }
  31.  
  32.  
  33. var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
  34.  
  35. func main() {
  36.     flag.Parse()
  37.     if *cpuprofile != "" {
  38.         f, err := os.Create(*cpuprofile)
  39.         if err != nil {
  40.                         panic(err)
  41.         }
  42.         pprof.StartCPUProfile(f)
  43.         defer pprof.StopCPUProfile()
  44.     }
  45.  
  46.         session, err := mgo.Dial("127.0.0.1:27017")
  47.         if err != nil {
  48.                 panic(err)
  49.         }
  50.         defer session.Close()
  51.  
  52.         // Optional. Switch the session to a monotonic behavior.
  53.         //        session.SetMode(mgo.Monotonic, true)
  54.  
  55.         c := session.DB("logdb").C("log")
  56.  
  57.         iter := c.Find(nil).Iter()
  58.         var res bson.M
  59.         var cnt = 0
  60.         var tot = 0
  61.         for iter.Next(&res) {
  62. //              fmt.Println(res)
  63.                 tot++
  64.                 if val, ok := res["eventType"]; ok && val == "VIDEO" {
  65.                         cnt++
  66.                 }
  67.         }
  68.         if iter.Err() != nil {
  69.                 panic(iter.Err())
  70.         }
  71.  
  72.         fmt.Println(tot)
  73.         fmt.Println(cnt)
  74. }
  75.  
  76.  
  77.  
  78. mattb@capdev2:~/src/golang $ go tool pprof --text ./mongo mongo.prof
  79. Total: 5875 samples
  80.      312   5.3%   5.3%      505   8.6% syscall.Syscall
  81.      258   4.4%   9.7%      258   4.4% runtime.futex
  82.      230   3.9%  13.6%      806  13.7% reflect.Value.SetMapIndex
  83.      227   3.9%  17.5%     1342  22.8% runtime.mallocgc
  84.      206   3.5%  21.0%     3656  62.2% labix.org/v2/mgo/bson.(*decoder).readDocTo
  85.      173   2.9%  23.9%      173   2.9% runtime.memmove
  86.      168   2.9%  26.8%      415   7.1% sweep
  87.      152   2.6%  29.4%      474   8.1% runtime.MCache_Alloc
  88.      135   2.3%  31.7%      135   2.3% runtime.memhash
  89.      131   2.2%  33.9%      131   2.2% runtime.rnd
  90.      110   1.9%  35.8%     1511  25.7% labix.org/v2/mgo/bson.(*decoder).readElemTo
  91.      109   1.9%  37.6%      109   1.9% runtime.markallocated
  92.      105   1.8%  39.4%      132   2.2% MCentral_Alloc
  93.       92   1.6%  41.0%      115   2.0% itab
  94.       90   1.5%  42.5%      124   2.1% MCentral_Free
  95.       90   1.5%  44.1%      409   7.0% reflect.Value.assignTo
  96.       88   1.5%  45.5%      135   2.3% reflect.ValueOf
  97.       87   1.5%  47.0%      253   4.3% runtime.MCache_Free
  98.       83   1.4%  48.4%       83   1.4% scanblock
  99.       63   1.1%  49.5%       79   1.3% reflect.Value.iword
  100.       63   1.1%  50.6%       63   1.1% runtime.markspan
  101.       56   1.0%  51.5%       91   1.5% hash_insert_internal
  102.       55   0.9%  52.5%      237   4.0% labix.org/v2/mgo/bson.(*decoder).readCStr
  103.       55   0.9%  53.4%       55   0.9% reflect.(*commonType).runtimeType
  104.       53   0.9%  54.3%       53   0.9% runtime.xchg
  105.       51   0.9%  55.2%       51   0.9% sync/atomic.AddUint32
  106.       50   0.9%  56.0%      103   1.8% copyout
  107.       49   0.8%  56.9%       68   1.2% reflect.Value.Elem
  108.       48   0.8%  57.7%      148   2.5% hash_lookup
  109.       48   0.8%  58.5%     4039  68.7% labix.org/v2/mgo.(*Iter).Next
  110.       46   0.8%  59.3%       46   0.8% hash_next
  111.       46   0.8%  60.1%       46   0.8% runtime.memclr
  112.       45   0.8%  60.8%      107   1.8% assertE2Tret
  113.       44   0.7%  61.6%      399   6.8% reflect.Value.Set
  114.       43   0.7%  62.3%       57   1.0% reflect.directlyAssignable
  115.       42   0.7%  63.0%      163   2.8% hash_remove
  116.       42   0.7%  63.7%       76   1.3% hash_remove_n
  117.       42   0.7%  64.5%       55   0.9% ifaceeq1
  118.       42   0.7%  65.2%      223   3.8% runtime.convT2I
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement