func (procs MPSlice) Ordered(para *params.Params) *PStable { uids := map[uint]string{} pslen := uint(len(procs)) limitPS := para.LIMIT["psn"].Value notdec := limitPS <= 1 notexp := limitPS >= pslen if limitPS >= pslen { // notexp limitPS = pslen // NB modified limitPS } pst := &PStable{} pst.PSnotDecreasable = new(operating.Bool) *pst.PSnotDecreasable = operating.Bool(notdec) pst.PSnotExpandable = new(operating.Bool) *pst.PSnotExpandable = operating.Bool(notexp) pst.PSplusText = new(string) *pst.PSplusText = fmt.Sprintf("%d+", limitPS) if para.BOOL["hideps"].Value { return pst } operating.MetricProcSlice(procs).SortSortBy(LessProcFunc(uids, *para.ENUM["ps"])) // not .StableSortBy if !notexp { procs = procs[:limitPS] } for _, proc := range procs { pst.List = append(pst.List, operating.ProcData{ PID: operating.Field(fmt.Sprintf("%d", proc.PID)), UID: proc.UID, Priority: proc.Priority, Nice: proc.Nice, Time: format.FormatTime(proc.Time), Name: proc.Name, User: username(uids, proc.UID), Size: format.HumanB(proc.Size), Resident: format.HumanB(proc.Resident), }) } return pst }
func _getmem(kind string, in sigar.Swap) operating.Memory { total, approxtotal, _ := format.HumanBandback(in.Total) used, approxused, _ := format.HumanBandback(in.Used) return operating.Memory{ Kind: operating.Field(kind), Total: total, Used: used, Free: format.HumanB(in.Free), UsePercent: format.FormatPercent(approxused, approxtotal), } }
func FormatDFinodes(md operating.MetricDF) operating.DiskInodes { var ( diskInodes = md.Inodes.Snapshot().Value() diskIused = md.Iused.Snapshot().Value() diskIfree = md.Ifree.Snapshot().Value() ) itotal, approxitotal, _ := format.HumanBandback(uint64(diskInodes)) iused, approxiused, _ := format.HumanBandback(uint64(diskIused)) return operating.DiskInodes{ DiskMeta: diskMeta(md), Inodes: itotal, Iused: iused, Ifree: format.HumanB(uint64(diskIfree)), IusePercent: format.FormatPercent(approxiused, approxitotal), } }
func FormatDFbytes(md operating.MetricDF) operating.DiskBytes { var ( diskTotal = md.Total.Snapshot().Value() diskUsed = md.Used.Snapshot().Value() diskAvail = md.Avail.Snapshot().Value() ) total, approxtotal, _ := format.HumanBandback(uint64(diskTotal)) used, approxused, _ := format.HumanBandback(uint64(diskUsed)) return operating.DiskBytes{ DiskMeta: diskMeta(md), Total: total, Used: used, Avail: format.HumanB(uint64(diskAvail)), UsePercent: format.FormatPercent(approxused, approxtotal), } }