Skip to content

Commit

Permalink
Merge branch 'separate_directories'
Browse files Browse the repository at this point in the history
Conflicts:
	README.rst
  • Loading branch information
shirou committed Dec 31, 2014
2 parents 9e216ad + cfb473f commit ce433bf
Show file tree
Hide file tree
Showing 73 changed files with 1,265 additions and 560 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*~
#*
_obj
154 changes: 78 additions & 76 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ psutil functions on some architectures...

.. highlights:: Package Structure Changed!

Package (a.k.a. directory) structure has been changed!! see `#24 <https://github.com/shirou/gopsutil/issues/24`_
Package (a.k.a. directory) structure has been changed!! see `issue 24 <https://github.com/shirou/gopsutil/issues/24>`_

.. highlights:: golang 1.4 will become REQUIRED!

Since syscall package becomes frozen, we should use golang/x/sys of golang 1.4 as soon as possible.


Available Architectures
Expand All @@ -23,9 +27,7 @@ Available Architectures
- Linux/amd64
- Linux/arm (raspberry pi)
- Windows/amd64

(I do not have a darwin machine)

- Darwin/amd64

All works are implemented without cgo by porting c struct to golang struct.

Expand Down Expand Up @@ -125,57 +127,57 @@ Current Status
- x: work
- b: almost work but something broken

================= ========= ========= =========== ====== =======
name Linux 686 Linux ARM FreeBSD 686 MacOSX Windows
cpu_times x x x x
cpu_count x x x x x
cpu_percent x x x x x
cpu_times_percent x x x x x
virtual_memory x x x x x
swap_memory x x x x
disk_partitions x x x x
disk_io_counters x x
disk_usage x x x x
net_io_counters x x x x x
boot_time x x x x b
users x x x x x
pids x x x x x
pid_exists x x x x x
================= =========== ========= ============= ====== =======
name Linux amd64 Linux ARM FreeBSD amd64 MacOSX Windows
cpu_times x x x
cpu_count x x x x x
cpu_percent x x x x
cpu_times_percent x x x x
virtual_memory x x x x x
swap_memory x x x x
disk_partitions x x x x x
disk_io_counters x x
disk_usage x x x x x
net_io_counters x x x x x
boot_time x x x x b
users x x x x x
pids x x x x x
pid_exists x x x x x
net_connections
================= ========= ========= =========== ====== =======
================= =========== ========= ============= ====== =======

Process class
^^^^^^^^^^^^^^^

================ ========= ========= =========== ====== =======
name Linux 686 Linux ARM FreeBSD 686 MacOSX Windows
pid x x x x x
ppid x x x x x
name x x x x
cmdline x x
create_time x x
status x x x x
cwd x x
exe x x x x
uids x x x x
gids x x x x
terminal x x x x
io_counters x x
nice x x
num_fds x x
num_ctx_switches x x
num_threads x x x x
cpu_times x x
memory_info x x x x
memory_info_ex x x
memory_maps x x
open_files x x
send_signal x x x x
suspend x x x x
resume x x x x
terminate x x x x
kill x x x x
username x x x x
================ =========== ========= ============= ====== =======
name Linux amd64 Linux ARM FreeBSD amd64 MacOSX Windows
pid x x x x x
ppid x x x x x
name x x x x
cmdline x x
create_time x x
status x x x x
cwd x x
exe x x x x
uids x x x x
gids x x x x
terminal x x x x
io_counters x x
nice x x
num_fds x x
num_ctx_switches x x
num_threads x x x x
cpu_times x x
memory_info x x x x
memory_info_ex x x
memory_maps x x
open_files x x
send_signal x x x x
suspend x x x x
resume x x x x
terminate x x x x
kill x x x x
username x x x x
ionice
rlimit
num_handlres
Expand All @@ -186,41 +188,41 @@ memory_percent
children
connections
is_running
================ ========= ========= =========== ====== =======
================ =========== ========= ============= ====== =======

Original Metrics
^^^^^^^^^^^^^^^^^^^
================== ========= ========= =========== ====== =======
item Linux 686 Linux ARM FreeBSD 686 MacOSX Windows
================== =========== ========= ============= ====== =======
item Linux amd64 Linux ARM FreeBSD amd64 MacOSX Windows
**HostInfo**
hostname x x x
uptime x x x
proces x x x
os x x x x x
platform x x x
platformfamiliy x x x
virtualization x x
hostname x x x x x
uptime x x x x
proces x x x
os x x x x x
platform x x x x
platformfamiliy x x x x
virtualization x x
**CPU**
VendorID x x
Family x x
Model x x
Stepping x x
PhysicalID x x
CoreID x x
Cores x x
ModelName x x
VendorID x x x x
Family x x x x
Model x x x x
Stepping x x x x
PhysicalID x x
CoreID x x
Cores x x
ModelName x x x x
**LoadAvg**
Load1 x x x
Load5 x x x
Load15 x x x
Load1 x x x x
Load5 x x x x
Load15 x x x x
**GetDockerID**
container id x x
container id x x no no no
**CgroupsCPU**
user x x
system x x
user x x no no no
system x x no no no
**CgroupsMem**
various x x
================== ========= ========= =========== ====== =======
various x x no no no
================== =========== ========= ============= ====== =======

- future work

Expand Down
37 changes: 26 additions & 11 deletions common.go → common/common.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//
// gopsutil is a port of psutil(http://pythonhosted.org/psutil/).
// common is a port of psutil(http://pythonhosted.org/psutil/).
// This covers these architectures.
// - linux (amd64, arm)
// - freebsd (amd64)
// - windows (amd64)
package gopsutil
package common

import (
"bufio"
Expand All @@ -17,18 +17,18 @@ import (

var NotImplementedError = errors.New("not implemented yet")

// readLines reads contents from file and splits them by new line.
// A convenience wrapper to readLinesOffsetN(filename, 0, -1).
func readLines(filename string) ([]string, error) {
return readLinesOffsetN(filename, 0, -1)
// ReadLines reads contents from file and splits them by new line.
// A convenience wrapper to ReadLinesOffsetN(filename, 0, -1).
func ReadLines(filename string) ([]string, error) {
return ReadLinesOffsetN(filename, 0, -1)
}

// readLines reads contents from file and splits them by new line.
// ReadLines reads contents from file and splits them by new line.
// The offset tells at which line number to start.
// The count determines the number of lines to read (starting from offset):
// n >= 0: at most n lines
// n < 0: whole file
func readLinesOffsetN(filename string, offset uint, n int) ([]string, error) {
func ReadLinesOffsetN(filename string, offset uint, n int) ([]string, error) {
f, err := os.Open(filename)
if err != nil {
return []string{""}, err
Expand All @@ -52,7 +52,22 @@ func readLinesOffsetN(filename string, offset uint, n int) ([]string, error) {
return ret, nil
}

func byteToString(orig []byte) string {
func IntToString(orig []int8) string {
ret := make([]byte, len(orig))
size := 0
for i, o := range orig {
if o == 0 {
size = i
break
}

ret[i] = byte(o)
}

return string(ret[0:size])
}

func ByteToString(orig []byte) string {
n := -1
l := -1
for i, b := range orig {
Expand Down Expand Up @@ -94,7 +109,7 @@ func mustParseFloat64(val string) float64 {
}

// Check the target string slice containes src or not
func stringContains(target []string, src string) bool {
func StringContains(target []string, src string) bool {
for _, t := range target {
if t == src {
return true
Expand Down Expand Up @@ -126,7 +141,7 @@ func attributes(m interface{}) map[string]reflect.Type {
return attrs
}

func pathExists(filename string) bool {
func PathExists(filename string) bool {
if _, err := os.Stat(filename); err == nil {
return true
}
Expand Down
4 changes: 2 additions & 2 deletions common_darwin.go → common/common_darwin.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// +build darwin

package gopsutil
package common

import (
"os/exec"
"strings"
)

func doSysctrl(mib string) ([]string, error) {
func DoSysctrl(mib string) ([]string, error) {
out, err := exec.Command("/usr/sbin/sysctl", "-n", mib).Output()
if err != nil {
return []string{}, err
Expand Down
4 changes: 2 additions & 2 deletions common_freebsd.go → common/common_freebsd.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// +build freebsd

package gopsutil
package common

import (
"os/exec"
"strings"
)

func doSysctrl(mib string) ([]string, error) {
func DoSysctrl(mib string) ([]string, error) {
out, err := exec.Command("/sbin/sysctl", "-n", mib).Output()
if err != nil {
return []string{}, err
Expand Down
12 changes: 6 additions & 6 deletions common_windows.go → common/common_windows.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// +build windows

package gopsutil
package common

import (
"syscall"
"unsafe"
)

var (
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
modNt = syscall.NewLazyDLL("ntdll.dll")
Modkernel32 = syscall.NewLazyDLL("kernel32.dll")
ModNt = syscall.NewLazyDLL("ntdll.dll")

procGetSystemTimes = modkernel32.NewProc("GetSystemTimes")
procNtQuerySystemInformation = modNt.NewProc("NtQuerySystemInformation")
ProcGetSystemTimes = Modkernel32.NewProc("GetSystemTimes")
ProcNtQuerySystemInformation = ModNt.NewProc("NtQuerySystemInformation")
)

type FILETIME struct {
Expand All @@ -21,7 +21,7 @@ type FILETIME struct {
}

// borrowed from net/interface_windows.go
func bytePtrToString(p *uint8) string {
func BytePtrToString(p *uint8) string {
a := (*[10000]uint8)(unsafe.Pointer(p))
i := 0
for a[i] != 0 {
Expand Down
2 changes: 1 addition & 1 deletion cpu.go → cpu/cpu.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gopsutil
package cpu

import (
"encoding/json"
Expand Down
6 changes: 4 additions & 2 deletions cpu_darwin.go → cpu/cpu_darwin.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// +build darwin

package gopsutil
package cpu

import (
"fmt"
"os/exec"
"strconv"
"strings"

common "github.com/shirou/gopsutil/common"
)

// sys/resource.h
Expand Down Expand Up @@ -37,7 +39,7 @@ func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
ncpu = 1
}

cpuTimes, err := doSysctrl(sysctlCall)
cpuTimes, err := common.DoSysctrl(sysctlCall)
if err != nil {
return ret, err
}
Expand Down
Loading

0 comments on commit ce433bf

Please sign in to comment.