mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-26 13:48:59 +08:00
Rename idents to gofmt-specs
This commit is contained in:
parent
fdf48b0e4a
commit
0d21129dc7
@ -10,17 +10,17 @@ import (
|
||||
|
||||
// sys/resource.h
|
||||
const (
|
||||
CP_USER = 0
|
||||
CP_NICE = 1
|
||||
CP_SYS = 2
|
||||
CP_INTR = 3
|
||||
CP_IDLE = 4
|
||||
CPUSTATES = 5
|
||||
CPUser = 0
|
||||
CPNice = 1
|
||||
CPSys = 2
|
||||
CPIntr = 3
|
||||
CPIdle = 4
|
||||
CPUStates = 5
|
||||
)
|
||||
|
||||
// time.h
|
||||
const (
|
||||
CLOCKS_PER_SEC = 128
|
||||
ClocksPerSec = 128
|
||||
)
|
||||
|
||||
// TODO: get per cpus
|
||||
@ -32,18 +32,18 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
user, _ := strconv.ParseFloat(cpuTime[CP_USER], 32)
|
||||
nice, _ := strconv.ParseFloat(cpuTime[CP_NICE], 32)
|
||||
sys, _ := strconv.ParseFloat(cpuTime[CP_SYS], 32)
|
||||
idle, _ := strconv.ParseFloat(cpuTime[CP_IDLE], 32)
|
||||
intr, _ := strconv.ParseFloat(cpuTime[CP_INTR], 32)
|
||||
user, _ := strconv.ParseFloat(cpuTime[CPUser], 32)
|
||||
nice, _ := strconv.ParseFloat(cpuTime[CPNice], 32)
|
||||
sys, _ := strconv.ParseFloat(cpuTime[CPSys], 32)
|
||||
idle, _ := strconv.ParseFloat(cpuTime[CPIdle], 32)
|
||||
intr, _ := strconv.ParseFloat(cpuTime[CPIntr], 32)
|
||||
|
||||
c := CPUTimesStat{
|
||||
User: float32(user / CLOCKS_PER_SEC),
|
||||
Nice: float32(nice / CLOCKS_PER_SEC),
|
||||
System: float32(sys / CLOCKS_PER_SEC),
|
||||
Idle: float32(idle / CLOCKS_PER_SEC),
|
||||
Irq: float32(intr / CLOCKS_PER_SEC), // FIXME: correct?
|
||||
User: float32(user / ClocksPerSec),
|
||||
Nice: float32(nice / ClocksPerSec),
|
||||
System: float32(sys / ClocksPerSec),
|
||||
Idle: float32(idle / ClocksPerSec),
|
||||
Irq: float32(intr / ClocksPerSec),
|
||||
}
|
||||
|
||||
ret = append(ret, c)
|
||||
|
@ -10,17 +10,17 @@ import (
|
||||
|
||||
// sys/resource.h
|
||||
const (
|
||||
CP_USER = 0
|
||||
CP_NICE = 1
|
||||
CP_SYS = 2
|
||||
CP_INTR = 3
|
||||
CP_IDLE = 4
|
||||
CPUSTATES = 5
|
||||
CPUser = 0
|
||||
CPNice = 1
|
||||
CPSys = 2
|
||||
CPIntr = 3
|
||||
CPIdle = 4
|
||||
CPUStates = 5
|
||||
)
|
||||
|
||||
// time.h
|
||||
const (
|
||||
CLOCKS_PER_SEC = 128
|
||||
ClocksPerSec = 128
|
||||
)
|
||||
|
||||
// TODO: get per cpus
|
||||
@ -32,18 +32,18 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
user, _ := strconv.ParseFloat(cpuTime[CP_USER], 32)
|
||||
nice, _ := strconv.ParseFloat(cpuTime[CP_NICE], 32)
|
||||
sys, _ := strconv.ParseFloat(cpuTime[CP_SYS], 32)
|
||||
idle, _ := strconv.ParseFloat(cpuTime[CP_IDLE], 32)
|
||||
intr, _ := strconv.ParseFloat(cpuTime[CP_INTR], 32)
|
||||
user, _ := strconv.ParseFloat(cpuTime[CPUser], 32)
|
||||
nice, _ := strconv.ParseFloat(cpuTime[CPNice], 32)
|
||||
sys, _ := strconv.ParseFloat(cpuTime[CPSys], 32)
|
||||
idle, _ := strconv.ParseFloat(cpuTime[CPIdle], 32)
|
||||
intr, _ := strconv.ParseFloat(cpuTime[CPIntr], 32)
|
||||
|
||||
c := CPUTimesStat{
|
||||
User: float32(user / CLOCKS_PER_SEC),
|
||||
Nice: float32(nice / CLOCKS_PER_SEC),
|
||||
System: float32(sys / CLOCKS_PER_SEC),
|
||||
Idle: float32(idle / CLOCKS_PER_SEC),
|
||||
Irq: float32(intr / CLOCKS_PER_SEC), // FIXME: correct?
|
||||
User: float32(user / ClocksPerSec),
|
||||
Nice: float32(nice / ClocksPerSec),
|
||||
System: float32(sys / ClocksPerSec),
|
||||
Idle: float32(idle / ClocksPerSec),
|
||||
Irq: float32(intr / ClocksPerSec),
|
||||
}
|
||||
|
||||
ret = append(ret, c)
|
||||
|
@ -11,62 +11,62 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
|
||||
var ret []DiskPartitionStat
|
||||
|
||||
// get length
|
||||
count, err := syscall.Getfsstat(nil, MNT_WAIT)
|
||||
count, err := syscall.Getfsstat(nil, MntWait)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
fs := make([]Statfs, count)
|
||||
_, err = Getfsstat(fs, MNT_WAIT)
|
||||
_, err = Getfsstat(fs, MntWait)
|
||||
|
||||
for _, stat := range fs {
|
||||
opts := "rw"
|
||||
if stat.FFlags&MNT_RDONLY != 0 {
|
||||
if stat.FFlags&MntReadOnly != 0 {
|
||||
opts = "ro"
|
||||
}
|
||||
if stat.FFlags&MNT_SYNCHRONOUS != 0 {
|
||||
if stat.FFlags&MntSynchronous != 0 {
|
||||
opts += ",sync"
|
||||
}
|
||||
if stat.FFlags&MNT_NOEXEC != 0 {
|
||||
if stat.FFlags&MntNoExec != 0 {
|
||||
opts += ",noexec"
|
||||
}
|
||||
if stat.FFlags&MNT_NOSUID != 0 {
|
||||
if stat.FFlags&MntNoSuid != 0 {
|
||||
opts += ",nosuid"
|
||||
}
|
||||
if stat.FFlags&MNT_UNION != 0 {
|
||||
if stat.FFlags&MntUnion != 0 {
|
||||
opts += ",union"
|
||||
}
|
||||
if stat.FFlags&MNT_ASYNC != 0 {
|
||||
if stat.FFlags&MntAsync != 0 {
|
||||
opts += ",async"
|
||||
}
|
||||
if stat.FFlags&MNT_SUIDDIR != 0 {
|
||||
if stat.FFlags&MntSuidDir != 0 {
|
||||
opts += ",suiddir"
|
||||
}
|
||||
if stat.FFlags&MNT_SOFTDEP != 0 {
|
||||
if stat.FFlags&MntSoftDep != 0 {
|
||||
opts += ",softdep"
|
||||
}
|
||||
if stat.FFlags&MNT_NOSYMFOLLOW != 0 {
|
||||
if stat.FFlags&MntNoSymFollow != 0 {
|
||||
opts += ",nosymfollow"
|
||||
}
|
||||
if stat.FFlags&MNT_GJOURNAL != 0 {
|
||||
if stat.FFlags&MntGEOMJournal != 0 {
|
||||
opts += ",gjounalc"
|
||||
}
|
||||
if stat.FFlags&MNT_MULTILABEL != 0 {
|
||||
if stat.FFlags&MntMultilabel != 0 {
|
||||
opts += ",multilabel"
|
||||
}
|
||||
if stat.FFlags&MNT_ACLS != 0 {
|
||||
if stat.FFlags&MntACLs != 0 {
|
||||
opts += ",acls"
|
||||
}
|
||||
if stat.FFlags&MNT_NOATIME != 0 {
|
||||
if stat.FFlags&MntNoATime != 0 {
|
||||
opts += ",noattime"
|
||||
}
|
||||
if stat.FFlags&MNT_NOCLUSTERR != 0 {
|
||||
if stat.FFlags&MntClusterRead != 0 {
|
||||
opts += ",nocluster"
|
||||
}
|
||||
if stat.FFlags&MNT_NOCLUSTERW != 0 {
|
||||
if stat.FFlags&MntClusterWrite != 0 {
|
||||
opts += ",noclusterw"
|
||||
}
|
||||
if stat.FFlags&MNT_NFS4ACLS != 0 {
|
||||
if stat.FFlags&MntNFS4ACLs != 0 {
|
||||
opts += ",nfs4acls"
|
||||
}
|
||||
|
||||
@ -88,13 +88,13 @@ func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
|
||||
// /usr/include/devinfo.h
|
||||
|
||||
// get length
|
||||
count, err := Getfsstat(nil, MNT_WAIT)
|
||||
count, err := Getfsstat(nil, MntWait)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fs := make([]Statfs, count)
|
||||
_, err = Getfsstat(fs, MNT_WAIT)
|
||||
_, err = Getfsstat(fs, MntWait)
|
||||
|
||||
ret := make(map[string]DiskIOCountersStat, 0)
|
||||
for _, stat := range fs {
|
||||
|
@ -4,29 +4,29 @@
|
||||
package gopsutil
|
||||
|
||||
const (
|
||||
MNT_WAIT = 1
|
||||
MFSNAMELEN = 16 /* length of type name including null */
|
||||
MNAMELEN = 88 /* size of on/from name bufs */
|
||||
MntWait = 1
|
||||
MfsNameLen = 16 /* length of type name including null */
|
||||
MNameLen = 88 /* size of on/from name bufs */
|
||||
)
|
||||
|
||||
// sys/mount.h
|
||||
const (
|
||||
MNT_RDONLY = 0x00000001 /* read only filesystem */
|
||||
MNT_SYNCHRONOUS = 0x00000002 /* filesystem written synchronously */
|
||||
MNT_NOEXEC = 0x00000004 /* can't exec from filesystem */
|
||||
MNT_NOSUID = 0x00000008 /* don't honor setuid bits on fs */
|
||||
MNT_UNION = 0x00000020 /* union with underlying filesystem */
|
||||
MNT_ASYNC = 0x00000040 /* filesystem written asynchronously */
|
||||
MNT_SUIDDIR = 0x00100000 /* special handling of SUID on dirs */
|
||||
MNT_SOFTDEP = 0x00200000 /* soft updates being done */
|
||||
MNT_NOSYMFOLLOW = 0x00400000 /* do not follow symlinks */
|
||||
MNT_GJOURNAL = 0x02000000 /* GEOM journal support enabled */
|
||||
MNT_MULTILABEL = 0x04000000 /* MAC support for individual objects */
|
||||
MNT_ACLS = 0x08000000 /* ACL support enabled */
|
||||
MNT_NOATIME = 0x10000000 /* disable update of file access time */
|
||||
MNT_NOCLUSTERR = 0x40000000 /* disable cluster read */
|
||||
MNT_NOCLUSTERW = 0x80000000 /* disable cluster write */
|
||||
MNT_NFS4ACLS = 0x00000010
|
||||
MntReadOnly = 0x00000001 /* read only filesystem */
|
||||
MntSynchronous = 0x00000002 /* filesystem written synchronously */
|
||||
MntNoExec = 0x00000004 /* can't exec from filesystem */
|
||||
MntNoSuid = 0x00000008 /* don't honor setuid bits on fs */
|
||||
MntUnion = 0x00000020 /* union with underlying filesystem */
|
||||
MntAsync = 0x00000040 /* filesystem written asynchronously */
|
||||
MntSuidDir = 0x00100000 /* special handling of SUID on dirs */
|
||||
MntSoftDep = 0x00200000 /* soft updates being done */
|
||||
MntNoSymFollow = 0x00400000 /* do not follow symlinks */
|
||||
MntGEOMJournal = 0x02000000 /* GEOM journal support enabled */
|
||||
MntMultilabel = 0x04000000 /* MAC support for individual objects */
|
||||
MntACLs = 0x08000000 /* ACL support enabled */
|
||||
MntNoATime = 0x10000000 /* disable update of file access time */
|
||||
MntClusterRead = 0x40000000 /* disable cluster read */
|
||||
MntClusterWrite = 0x80000000 /* disable cluster write */
|
||||
MntNFS4ACLs = 0x00000010
|
||||
)
|
||||
|
||||
type Statfs struct {
|
||||
@ -49,9 +49,9 @@ type Statfs struct {
|
||||
FOwner uint32 /* user that mounted the filesystem */
|
||||
FFsid int32 /* filesystem id */
|
||||
FCharspare [80]byte /* spare string space */
|
||||
FFstypename [MFSNAMELEN]byte /* filesystem type name */
|
||||
FMntfromname [MNAMELEN]byte /* mounted filesystem */
|
||||
FMntonname [MNAMELEN]byte /* directory on which mounted */
|
||||
FFstypename [MfsNameLen]byte /* filesystem type name */
|
||||
FMntfromname [MNameLen]byte /* mounted filesystem */
|
||||
FMntonname [MNameLen]byte /* directory on which mounted */
|
||||
}
|
||||
|
||||
// /usr/include/devstat.h
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
SECTOR_SIZE = 512
|
||||
SectorSize = 512
|
||||
)
|
||||
|
||||
// Get disk partitions.
|
||||
@ -54,8 +54,8 @@ func DiskIOCounters() (map[string]DiskIOCountersStat, error) {
|
||||
wbytes := mustParseUint64(fields[9])
|
||||
wtime := mustParseUint64(fields[10])
|
||||
d := DiskIOCountersStat{
|
||||
ReadBytes: rbytes * SECTOR_SIZE,
|
||||
WriteBytes: wbytes * SECTOR_SIZE,
|
||||
ReadBytes: rbytes * SectorSize,
|
||||
WriteBytes: wbytes * SectorSize,
|
||||
ReadCount: reads,
|
||||
WriteCount: writes,
|
||||
ReadTime: rtime,
|
||||
|
@ -16,8 +16,8 @@ var (
|
||||
)
|
||||
|
||||
var (
|
||||
FILE_FILE_COMPRESSION = int64(16) // 0x00000010
|
||||
FILE_READ_ONLY_VOLUME = int64(524288) // 0x00080000
|
||||
FileFileCompression = int64(16) // 0x00000010
|
||||
FileReadOnlyVolume = int64(524288) // 0x00080000
|
||||
)
|
||||
|
||||
func DiskUsage(path string) (DiskUsageStat, error) {
|
||||
@ -86,10 +86,10 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
|
||||
return ret, err
|
||||
}
|
||||
opts := "rw"
|
||||
if lpFileSystemFlags&FILE_READ_ONLY_VOLUME != 0 {
|
||||
if lpFileSystemFlags&FileReadOnlyVolume != 0 {
|
||||
opts = "ro"
|
||||
}
|
||||
if lpFileSystemFlags&FILE_FILE_COMPRESSION != 0 {
|
||||
if lpFileSystemFlags&FileFileCompression != 0 {
|
||||
opts += ".compress"
|
||||
}
|
||||
|
||||
|
@ -14,31 +14,31 @@ type CgroupMemStat struct {
|
||||
ContainerID string `json:"containerid"`
|
||||
Cache uint64 `json:"cache"`
|
||||
RSS uint64 `json:"rss"`
|
||||
Rss_huge uint64 `json:"rss_huge"`
|
||||
Mapped_file uint64 `json:"mapped_file"`
|
||||
RSSHuge uint64 `json:"rss_huge"`
|
||||
MappedFile uint64 `json:"mapped_file"`
|
||||
Pgpgin uint64 `json:"pgpgin"`
|
||||
Pgpgout uint64 `json:"pgpgout"`
|
||||
Pgfault uint64 `json:"pgfault"`
|
||||
Pgmajfault uint64 `json:"pgmajfault"`
|
||||
Inactive_anon uint64 `json:"inactive_anon"`
|
||||
Active_anon uint64 `json:"active_anon"`
|
||||
Inactive_file uint64 `json:"inactive_file"`
|
||||
Active_file uint64 `json:"active_file"`
|
||||
InactiveAnon uint64 `json:"inactive_anon"`
|
||||
ActiveAnon uint64 `json:"active_anon"`
|
||||
InctiveFile uint64 `json:"inactive_file"`
|
||||
ActiveFile uint64 `json:"active_file"`
|
||||
Unevictable uint64 `json:"unevictable"`
|
||||
Hierarchical_memory_limit uint64 `json:"hierarchical_memory_limit"`
|
||||
Total_cache uint64 `json:"total_cache"`
|
||||
Total_rss uint64 `json:"total_rss"`
|
||||
Total_rss_huge uint64 `json:"total_rss_huge"`
|
||||
Total_mapped_file uint64 `json:"total_mapped_file"`
|
||||
Total_pgpgin uint64 `json:"total_pgpgin"`
|
||||
Total_pgpgout uint64 `json:"total_pgpgout"`
|
||||
Total_pgfault uint64 `json:"total_pgfault"`
|
||||
Total_pgmajfault uint64 `json:"total_pgmajfault"`
|
||||
Total_inactive_anon uint64 `json:"total_inactive_anon"`
|
||||
Total_active_anon uint64 `json:"total_active_anon"`
|
||||
Total_inactive_file uint64 `json:"total_inactive_file"`
|
||||
Total_active_file uint64 `json:"total_active_file"`
|
||||
Total_unevictable uint64 `json:"total_unevictable"`
|
||||
HierarchicalMemoryLimit uint64 `json:"hierarchical_memory_limit"`
|
||||
TotalCache uint64 `json:"total_cache"`
|
||||
TotalRSS uint64 `json:"total_rss"`
|
||||
TotalRSSHuge uint64 `json:"total_rss_huge"`
|
||||
TotalMappedFile uint64 `json:"total_mapped_file"`
|
||||
TotalPgpgIn uint64 `json:"total_pgpgin"`
|
||||
TotalPgpgOut uint64 `json:"total_pgpgout"`
|
||||
TotalPgFault uint64 `json:"total_pgfault"`
|
||||
TotalPgMajFault uint64 `json:"total_pgmajfault"`
|
||||
TotalInactiveAnon uint64 `json:"total_inactive_anon"`
|
||||
TotalActiveAnon uint64 `json:"total_active_anon"`
|
||||
TotalInactiveFile uint64 `json:"total_inactive_file"`
|
||||
TotalActiveFile uint64 `json:"total_active_file"`
|
||||
TotalUnevictable uint64 `json:"total_unevictable"`
|
||||
}
|
||||
|
||||
// GetDockerIDList returnes a list of DockerID.
|
||||
@ -120,9 +120,9 @@ func CgroupMem(containerid string, base string) (*CgroupMemStat, error) {
|
||||
case "rss":
|
||||
ret.RSS = v
|
||||
case "rss_huge":
|
||||
ret.Rss_huge = v
|
||||
ret.RSSHuge = v
|
||||
case "mapped_file":
|
||||
ret.Mapped_file = v
|
||||
ret.MappedFile = v
|
||||
case "pgpgin":
|
||||
ret.Pgpgin = v
|
||||
case "pgpgout":
|
||||
@ -132,43 +132,43 @@ func CgroupMem(containerid string, base string) (*CgroupMemStat, error) {
|
||||
case "pgmajfault":
|
||||
ret.Pgmajfault = v
|
||||
case "inactive_anon":
|
||||
ret.Inactive_anon = v
|
||||
ret.InactiveAnon = v
|
||||
case "active_anon":
|
||||
ret.Active_anon = v
|
||||
ret.ActiveAnon = v
|
||||
case "inactive_file":
|
||||
ret.Inactive_file = v
|
||||
ret.InctiveFile = v
|
||||
case "active_file":
|
||||
ret.Active_file = v
|
||||
ret.ActiveFile = v
|
||||
case "unevictable":
|
||||
ret.Unevictable = v
|
||||
case "hierarchical_memory_limit":
|
||||
ret.Hierarchical_memory_limit = v
|
||||
ret.HierarchicalMemoryLimit = v
|
||||
case "total_cache":
|
||||
ret.Total_cache = v
|
||||
ret.TotalCache = v
|
||||
case "total_rss":
|
||||
ret.Total_rss = v
|
||||
ret.TotalRSS = v
|
||||
case "total_rss_huge":
|
||||
ret.Total_rss_huge = v
|
||||
ret.TotalRSSHuge = v
|
||||
case "total_mapped_file":
|
||||
ret.Total_mapped_file = v
|
||||
ret.TotalMappedFile = v
|
||||
case "total_pgpgin":
|
||||
ret.Total_pgpgin = v
|
||||
ret.TotalPgpgIn = v
|
||||
case "total_pgpgout":
|
||||
ret.Total_pgpgout = v
|
||||
ret.TotalPgpgOut = v
|
||||
case "total_pgfault":
|
||||
ret.Total_pgfault = v
|
||||
ret.TotalPgFault = v
|
||||
case "total_pgmajfault":
|
||||
ret.Total_pgmajfault = v
|
||||
ret.TotalPgMajFault = v
|
||||
case "total_inactive_anon":
|
||||
ret.Total_inactive_anon = v
|
||||
ret.TotalInactiveAnon = v
|
||||
case "total_active_anon":
|
||||
ret.Total_active_anon = v
|
||||
ret.TotalActiveAnon = v
|
||||
case "total_inactive_file":
|
||||
ret.Total_inactive_file = v
|
||||
ret.TotalInactiveFile = v
|
||||
case "total_active_file":
|
||||
ret.Total_active_file = v
|
||||
ret.TotalActiveFile = v
|
||||
case "total_unevictable":
|
||||
ret.Total_unevictable = v
|
||||
ret.TotalUnevictable = v
|
||||
}
|
||||
}
|
||||
return ret, nil
|
||||
|
@ -15,20 +15,20 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
UTX_USERSIZE = 256 /* include/NetBSD/utmpx.h */
|
||||
UTX_IDSIZE = 4
|
||||
UTX_LINESIZE = 32
|
||||
UTX_HOSTSIZE = 256
|
||||
UTXUserSize = 256 /* include/NetBSD/utmpx.h */
|
||||
UTXIDSize = 4
|
||||
UTXLineSize = 32
|
||||
UTXHostSize = 256
|
||||
)
|
||||
|
||||
type utmpx32 struct {
|
||||
UtUser [UTX_USERSIZE]byte /* login name */
|
||||
UtId [UTX_IDSIZE]byte /* id */
|
||||
UtLine [UTX_LINESIZE]byte /* tty name */
|
||||
UtUser [UTXUserSize]byte /* login name */
|
||||
UtID [UTXIDSize]byte /* id */
|
||||
UtLine [UTXLineSize]byte /* tty name */
|
||||
//TODO UtPid pid_t /* process id creating the entry */
|
||||
UtType [4]byte /* type of this entry */
|
||||
//TODO UtTv timeval32 /* time entry was created */
|
||||
UtHost [UTX_HOSTSIZE]byte /* host name */
|
||||
UtHost [UTXHostSize]byte /* host name */
|
||||
UtPad [16]byte /* reserved for future use */
|
||||
}
|
||||
|
||||
|
@ -4,14 +4,14 @@
|
||||
package gopsutil
|
||||
|
||||
const (
|
||||
UT_NAMESIZE = 16 /* see MAXLOGNAME in <sys/param.h> */
|
||||
UT_LINESIZE = 8
|
||||
UT_HOSTSIZE = 16
|
||||
UTNameSize = 16 /* see MAXLOGNAME in <sys/param.h> */
|
||||
UTLineSize = 8
|
||||
UTHostSize = 16
|
||||
)
|
||||
|
||||
type utmp struct {
|
||||
UtLine [UT_LINESIZE]byte
|
||||
UtName [UT_NAMESIZE]byte
|
||||
UtHost [UT_HOSTSIZE]byte
|
||||
UtLine [UTLineSize]byte
|
||||
UtName [UTNameSize]byte
|
||||
UtHost [UTHostSize]byte
|
||||
UtTime int32
|
||||
}
|
||||
|
@ -16,15 +16,15 @@ var (
|
||||
)
|
||||
|
||||
const (
|
||||
TCP_TABLE_BASIC_LISTENER = iota
|
||||
TCP_TABLE_BASIC_CONNECTIONS
|
||||
TCP_TABLE_BASIC_ALL
|
||||
TCP_TABLE_OWNER_PID_LISTENER
|
||||
TCP_TABLE_OWNER_PID_CONNECTIONS
|
||||
TCP_TABLE_OWNER_PID_ALL
|
||||
TCP_TABLE_OWNER_MODULE_LISTENER
|
||||
TCP_TABLE_OWNER_MODULE_CONNECTIONS
|
||||
TCP_TABLE_OWNER_MODULE_ALL
|
||||
TCPTableBasicListener = iota
|
||||
TCPTableBasicConnections
|
||||
TCPTableBasicAll
|
||||
TCPTableOwnerPIDListener
|
||||
TCPTableOwnerPIDConnections
|
||||
TCPTableOwnerPIDAll
|
||||
TCPTableOwnerModuleListener
|
||||
TCPTableOwnerModuleConnections
|
||||
TCPTableOwnerModuleAll
|
||||
)
|
||||
|
||||
func NetIOCounters(pernic bool) ([]NetIOCountersStat, error) {
|
||||
|
@ -200,7 +200,7 @@ func copyParams(k *KinfoProc, p *Process) error {
|
||||
func processes() ([]Process, error) {
|
||||
results := make([]Process, 0, 50)
|
||||
|
||||
mib := []int32{CTL_KERN, KERN_PROC, KERN_PROC_PROC, 0}
|
||||
mib := []int32{CTLKern, KernProc, KernProcProc, 0}
|
||||
buf, length, err := callSyscall(mib)
|
||||
if err != nil {
|
||||
return results, err
|
||||
@ -280,7 +280,7 @@ func callSyscall(mib []int32) ([]byte, uint64, error) {
|
||||
}
|
||||
|
||||
func (p *Process) getKProc() (*KinfoProc, error) {
|
||||
mib := []int32{CTL_KERN, KERN_PROC, KERN_PROC_PID, p.Pid}
|
||||
mib := []int32{CTLKern, KernProc, KernProcPID, p.Pid}
|
||||
|
||||
buf, length, err := callSyscall(mib)
|
||||
if err != nil {
|
||||
|
@ -5,11 +5,11 @@ package gopsutil
|
||||
|
||||
// copied from sys/sysctl.h
|
||||
const (
|
||||
CTL_KERN = 1 // "high kernel": proc, limits
|
||||
KERN_PROC = 14 // struct: process entries
|
||||
KERN_PROC_PID = 1 // by process id
|
||||
KERN_PROC_PROC = 8 // only return procs
|
||||
KERN_PROC_PATHNAME = 12 // path to executable
|
||||
CTLKern = 1 // "high kernel": proc, limits
|
||||
KernProc = 14 // struct: process entries
|
||||
KernProcPID = 1 // by process id
|
||||
KernProcProc = 8 // only return procs
|
||||
KernProcPathname = 12 // path to executable
|
||||
)
|
||||
|
||||
// copied from sys/user.h
|
||||
|
@ -198,7 +198,7 @@ func copyParams(k *KinfoProc, p *Process) error {
|
||||
func processes() ([]Process, error) {
|
||||
results := make([]Process, 0, 50)
|
||||
|
||||
mib := []int32{CTL_KERN, KERN_PROC, KERN_PROC_PROC, 0}
|
||||
mib := []int32{CTLKern, KernProc, KernProcProc, 0}
|
||||
buf, length, err := callSyscall(mib)
|
||||
if err != nil {
|
||||
return results, err
|
||||
@ -278,7 +278,7 @@ func callSyscall(mib []int32) ([]byte, uint64, error) {
|
||||
}
|
||||
|
||||
func (p *Process) getKProc() (*KinfoProc, error) {
|
||||
mib := []int32{CTL_KERN, KERN_PROC, KERN_PROC_PID, p.Pid}
|
||||
mib := []int32{CTLKern, KernProc, KernProcPID, p.Pid}
|
||||
|
||||
buf, length, err := callSyscall(mib)
|
||||
if err != nil {
|
||||
|
@ -5,11 +5,11 @@ package gopsutil
|
||||
|
||||
// copied from sys/sysctl.h
|
||||
const (
|
||||
CTL_KERN = 1 // "high kernel": proc, limits
|
||||
KERN_PROC = 14 // struct: process entries
|
||||
KERN_PROC_PID = 1 // by process id
|
||||
KERN_PROC_PROC = 8 // only return procs
|
||||
KERN_PROC_PATHNAME = 12 // path to executable
|
||||
CTLKern = 1 // "high kernel": proc, limits
|
||||
KernProc = 14 // struct: process entries
|
||||
KernProcPID = 1 // by process id
|
||||
KernProcProc = 8 // only return procs
|
||||
KernProcPathname = 12 // path to executable
|
||||
)
|
||||
|
||||
// copied from sys/user.h
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
PRIO_PROCESS = 0 // linux/resource.h
|
||||
PrioProcess = 0 // linux/resource.h
|
||||
)
|
||||
|
||||
// MemoryInfoExStat is different between OSes
|
||||
@ -390,8 +390,8 @@ func (p *Process) fillFromStatm() (*MemoryInfoStat, *MemoryInfoExStat, error) {
|
||||
}
|
||||
fields := strings.Split(string(contents), " ")
|
||||
|
||||
rss := mustParseUint64(fields[0]) * PAGESIZE
|
||||
vms := mustParseUint64(fields[1]) * PAGESIZE
|
||||
rss := mustParseUint64(fields[0]) * PageSize
|
||||
vms := mustParseUint64(fields[1]) * PageSize
|
||||
memInfo := &MemoryInfoStat{
|
||||
RSS: rss,
|
||||
VMS: vms,
|
||||
@ -399,10 +399,10 @@ func (p *Process) fillFromStatm() (*MemoryInfoStat, *MemoryInfoExStat, error) {
|
||||
memInfoEx := &MemoryInfoExStat{
|
||||
RSS: rss,
|
||||
VMS: vms,
|
||||
Shared: mustParseUint64(fields[2]) * PAGESIZE,
|
||||
Text: mustParseUint64(fields[3]) * PAGESIZE,
|
||||
Lib: mustParseUint64(fields[4]) * PAGESIZE,
|
||||
Dirty: mustParseUint64(fields[5]) * PAGESIZE,
|
||||
Shared: mustParseUint64(fields[2]) * PageSize,
|
||||
Text: mustParseUint64(fields[3]) * PageSize,
|
||||
Lib: mustParseUint64(fields[4]) * PageSize,
|
||||
Dirty: mustParseUint64(fields[5]) * PageSize,
|
||||
}
|
||||
|
||||
return memInfo, memInfoEx, nil
|
||||
@ -485,17 +485,17 @@ func (p *Process) fillFromStat() (string, int32, *CPUTimesStat, int64, int32, er
|
||||
|
||||
cpuTimes := &CPUTimesStat{
|
||||
CPU: "cpu",
|
||||
User: float32(utime * (1000 / CLOCK_TICKS)),
|
||||
System: float32(stime * (1000 / CLOCK_TICKS)),
|
||||
User: float32(utime * (1000 / ClockTicks)),
|
||||
System: float32(stime * (1000 / ClockTicks)),
|
||||
}
|
||||
|
||||
bootTime, _ := BootTime()
|
||||
ctime := ((mustParseUint64(fields[21]) / uint64(CLOCK_TICKS)) + uint64(bootTime)) * 1000
|
||||
ctime := ((mustParseUint64(fields[21]) / uint64(ClockTicks)) + uint64(bootTime)) * 1000
|
||||
createTime := int64(ctime)
|
||||
|
||||
// p.Nice = mustParseInt32(fields[18])
|
||||
// use syscall instead of parse Stat file
|
||||
snice, _ := syscall.Getpriority(PRIO_PROCESS, int(pid))
|
||||
snice, _ := syscall.Getpriority(PrioProcess, int(pid))
|
||||
nice := int32(snice) // FIXME: is this true?
|
||||
|
||||
return terminal, ppid, cpuTimes, createTime, nice, nil
|
||||
|
@ -4,6 +4,6 @@
|
||||
package gopsutil
|
||||
|
||||
const (
|
||||
CLOCK_TICKS = 100 // C.sysconf(C._SC_CLK_TCK)
|
||||
PAGESIZE = 4096 // C.sysconf(C._SC_PAGE_SIZE)
|
||||
ClockTicks = 100 // C.sysconf(C._SC_CLK_TCK)
|
||||
PageSize = 4096 // C.sysconf(C._SC_PAGE_SIZE)
|
||||
)
|
||||
|
@ -4,6 +4,6 @@
|
||||
package gopsutil
|
||||
|
||||
const (
|
||||
CLOCK_TICKS = 100 // C.sysconf(C._SC_CLK_TCK)
|
||||
PAGESIZE = 4096 // C.sysconf(C._SC_PAGE_SIZE)
|
||||
ClockTicks = 100 // C.sysconf(C._SC_CLK_TCK)
|
||||
PageSize = 4096 // C.sysconf(C._SC_PAGE_SIZE)
|
||||
)
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func test_getProcess() Process {
|
||||
func testGetProcess() Process {
|
||||
checkPid := os.Getpid()
|
||||
if runtime.GOOS == "windows" {
|
||||
checkPid = 7960
|
||||
@ -81,7 +81,7 @@ func Test_Process_memory_maps(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Process_Ppid(t *testing.T) {
|
||||
p := test_getProcess()
|
||||
p := testGetProcess()
|
||||
|
||||
v, err := p.Ppid()
|
||||
if err != nil {
|
||||
@ -94,7 +94,7 @@ func Test_Process_Ppid(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Process_IOCounters(t *testing.T) {
|
||||
p := test_getProcess()
|
||||
p := testGetProcess()
|
||||
|
||||
v, err := p.IOCounters()
|
||||
if err != nil {
|
||||
@ -108,7 +108,7 @@ func Test_Process_IOCounters(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Process_NumCtx(t *testing.T) {
|
||||
p := test_getProcess()
|
||||
p := testGetProcess()
|
||||
|
||||
_, err := p.NumCtxSwitches()
|
||||
if err != nil {
|
||||
|
@ -11,11 +11,11 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
ERROR_NO_MORE_FILES = 0x12
|
||||
MAX_PATH = 260
|
||||
NoMoreFiles = 0x12
|
||||
MaxPathLength = 260
|
||||
)
|
||||
|
||||
type SYSTEM_PROCESS_INFORMATION struct {
|
||||
type SystemProcessInformation struct {
|
||||
NextEntryOffset uint64
|
||||
NumberOfThreads uint64
|
||||
Reserved1 [48]byte
|
||||
@ -241,12 +241,12 @@ func processes() ([]*Process, error) {
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func getProcInfo(pid int32) (*SYSTEM_PROCESS_INFORMATION, error) {
|
||||
func getProcInfo(pid int32) (*SystemProcessInformation, error) {
|
||||
initialBufferSize := uint64(0x4000)
|
||||
bufferSize := initialBufferSize
|
||||
buffer := make([]byte, bufferSize)
|
||||
|
||||
var sysProcInfo SYSTEM_PROCESS_INFORMATION
|
||||
var sysProcInfo SystemProcessInformation
|
||||
ret, _, _ := procNtQuerySystemInformation.Call(
|
||||
uintptr(unsafe.Pointer(&sysProcInfo)),
|
||||
uintptr(unsafe.Pointer(&buffer[0])),
|
||||
|
Loading…
x
Reference in New Issue
Block a user