Commit Graph

651 Commits (e864f2a037bf2e2e62d20e2f132ab08e261b6e71)
 

Author SHA1 Message Date
shirou a0cf924cac Merge pull request #170 from vecmezoni/fd-close
NewProcess does not close file descriptor
Alexander Inozemtsev f4902fae49 Properly close opened file
Shirou WAKAYAMA 6c352016d8 [net]linux: start replacing lsof. still work in progress.
Shirou WAKAYAMA 1de1357e77 [process]: add FailNow to avoid panic.
shirou 1ab11f7afd Merge pull request #167 from cgilling/cmdline_slice
process: add CmdlineSlice function for linux + freebsd
Chris Gilling 8c186ae593 process: add CmdlineSlice for darwin + windows
darwin will not perform correctly if there are spaces in the actual
arguments, in which case a single argument will be reported as
multple. Some CGO would be needed to get around this I think.

I couldn't find any good documentation on how windows handles
command line arguments with spaces inside the actual arguments, so
this implementation merely just splits on spaces.
shirou d6702c96bd Merge pull request #168 from cgilling/faster_linux_new_process
process: change linux NewProcess to only stat /proc/[pid]
Chris Gilling a3bbd9e3cd process: change linux NewProcess to only stat /proc/[pid]
Before it was doing a fillFromStatus() call which was much slower
and none of the information was needed, except by the Name() func
which now will call fillFromStatus() if p.name is not set.
Chris Gilling d098bf135f process: fix bug in CmdlineSlice where cmdline is empty
Sometimes (at least on linux) cmdline is empty, this was causing
a panic.
Chris Gilling b8c40ac83c process: add CmdlineSlice function for linux + freebsd
This allows for getting more exact information about each argument
especially if there are arguments that have spaces in them.

This was not implemented for darwin or for windows because they
both currently have not way of properly parsing the cmdline string.
Darwin parses the output of 'ps' which is already whitespace
segmented, and windows just has the cmdline string.
shirou 3618a777a8 Merge pull request #162 from shirou/load/add_misc
[load]all: add Misc in load to get miscellaneous host info from /proc…
shirou cfe7e5f1ca Merge pull request #163 from walles/walles/test_proc_cputimes
Add test for process.CPUTimes()
Johan Walles 3232d34b24 Add test for process.CPUTimes()
Shirou WAKAYAMA 97bcc355a6 [process]linux: change to use exec.LookPath to invoke lsof.
shirou 1d09f7a4e9 Merge pull request #160 from walles/walles/vmtest
Document + add tests for for mem.VirtualMemory()
Johan Walles dd875d4970 Fix memory stats on Darwin, non-CGO
Johan Walles d109284df3 Fix memory stats on Darwin, CGO
Johan Walles 27093ae2d2 mem_darwin_test.go: Compare `total` to `sysctl hw.memsize`
Johan Walles 0d5592714b Fix memory stats on LinuxFreeBSD
Johan Walles 66a07939f7 Fix memory stats on Linux
Johan Walles 4438159155 Document + add tests for for mem.VirtualMemory()
This change changes and documents the (previously undocumented) behavior of Used
to "RAM used by programs".

We also remove the undocumented and unused Shared field of that struct.

So with this change in place, the VirtualMemoryStruct contains:
* three human-consumable fields for Total, Used and Available memory
* one human-consumable UsedPercentage field
* a number of kernel specific fields
shirou e04a02d2d7 Merge pull request #161 from walles/walles/darwin-vmperf
Use OS calls rather than exec() to get memory stats on Darwin
Johan Walles 44f817eb8d Split mem_darwin.go into CGO and non CGO variants
Shirou WAKAYAMA 821a0141b1 [load]: add comments.
Shirou WAKAYAMA c973fdbc46 [load]linux: fix compile problems.
Shirou WAKAYAMA f9effa497e [load]all: add Misc in load to get miscellaneous host info from /proc/stat
Johan Walles 00504a37e3 Remove unused import
Johan Walles a6cd6f803b Use Go's built in syscall.Getpagesize()
Johan Walles 13e00c76e4 Use OS calls rather than exec() to get memory statistics
Before this change we used to exec() various binaries to find out memory
information.

While this worked, it was awfully slow.

And if somebody would want to compute how many percent of available memory all
PIDs on the system uses, that would take almost ten seconds on my laptop with
the previous implementation.

This implementation fares a lot better, and is smaller.
Johan Walles 5771ea9465 Add Darwin specific mem.VirtualMemory() tests
Shirou WAKAYAMA 3166d41538 set LC_ALL to C in order to avoid number formatting problem.
shirou 79f021f66e Merge pull request #158 from walles/walles/darwin-memorypercent
process: Implement MemoryPercent() for Darwin
Johan Walles 70444b571b process: Implement platform independent MemoryPercent()
It calls mem.VirtualMemory() and process.MemoryInfo(), so on the platforms where
those work MemoryPercent() will as well.

Tested on Darwin.
shirou 956f92742f Merge pull request #156 from shirou/add_build_check
Add build check
Shirou WAKAYAMA 01ddce7ff6 test verbose.
Shirou WAKAYAMA cb5866a546 we can not test other arch.
Shirou WAKAYAMA fb3a6df695 add other platform test
Shirou WAKAYAMA e21c97d3b2 [process]darwin: forget to change as binary.go movement.
WAKAYAMA shirou 0af91ba32b [disk,process]freebsd: binary.go moved to internal.
shirou 614df95d72 Merge pull request #155 from shirou/add_circleci
add circle.yml.
Shirou WAKAYAMA fe4c9f8ffa change CI status badge to CircleCI.
Shirou WAKAYAMA 5a09d40f6b [process]darwin: expected ps file was changed.
Shirou WAKAYAMA c822415e22 Merge branch 'master' into add_circleci
shirou 7fd975a4c0 Merge pull request #153 from walles/walles/processusername
Return correct user name from process.Username()
Shirou WAKAYAMA 7f22150707 CPU num is different on the CircleCI environemnt, so we skip it.
Shirou WAKAYAMA c54ae65e78 add circle.yml.
Johan Walles 17db0319c8 Empty commit to trigger CI
Johan Walles 09fbecef59 Darwin: Remove questionable UIDs
process.Process.uids is an array of undocumented values.

That one of them is the user that the process is running as is obvious, but what
the other two are supposed to be is AFAICT undocumented.

On Darwin, the second and third UID (out of three) seem to always be 0.

This change removes the two always-zero UIDs from the process.Process struct on
Darwin, and leaves just the one that actually identifies the user the process
is running as.
Johan Walles e3a7a45492 process.Username(): Correct user names on Darwin
Before this change, process.Username() returned "root" for all processes on
Darwin.
shirou 70b7a99f9b Merge pull request #152 from walles/walles/total-cpu-time
Make a public function for computing total CPU time