// PageStats get pages related stats // Go equivalent to sg_get_page_stats_diff func (s *Stat) PageStats() *PageStats { s.Lock() defer s.Unlock() page_stats := C.sg_get_page_stats_diff(nil) p := &PageStats{ PageIn: int(page_stats.pages_pagein), PageOut: int(page_stats.pages_pageout), } return p }
// PageStats get pages related stats // Go equivalent to sg_get_page_stats_diff func (s *Stat) PageStats() *PageStats { s.Lock() defer s.Unlock() var p *PageStats do(func() { page_stats := C.sg_get_page_stats_diff(nil) p = &PageStats{ PageIn: int(page_stats.pages_pagein), PageOut: int(page_stats.pages_pageout), Period: time.Duration(int(page_stats.systime)), TimeTaken: time.Now(), } }) return p }
// NewStat return a new Stat handle func NewStat() *Stat { s := &Stat{} runtime.SetFinalizer(s, (*Stat).free) initDone := make(chan bool) s.exitMessage = make(chan bool) C.sg_init(1) go func() { // We need some function calls to be performed on the same thread // Those for which statgrab is using a thread local runtime.LockOSThread() defer runtime.UnlockOSThread() // Throw away the first reading as thats averaged over the machines uptime C.sg_get_cpu_stats_diff(nil) C.sg_get_network_io_stats_diff(nil) C.sg_get_page_stats_diff(nil) C.sg_get_disk_io_stats_diff(nil) initDone <- true for { select { case <-s.exitMessage: break case f := <-mainfunc: f() } } }() <-initDone return s }