Skip to content

Commit

Permalink
Merge pull request #7 from koron-go/darwin-support-1
Browse files Browse the repository at this point in the history
add darwin (macos) support
  • Loading branch information
koron authored Nov 27, 2020
2 parents 81d607b + 55d0718 commit 3b5029d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions phymem.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// +build !windows
// +build !linux
// +build !darwin
// +build !freebsd
// +build !plan9
// +build !netbsd
Expand Down
23 changes: 23 additions & 0 deletions phymem_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package phymem

// #include <mach/mach.h>
//
//static vm_size_t getRSS(void) {
// struct task_basic_info info;
// mach_msg_type_number_t size = sizeof(info);
// kern_return_t kerr = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &size);
// return kerr == KERN_SUCCESS ? info.resident_size : 0;
//}
import "C"
import "errors"

// for test.
const providedCurrent = true

func Current() (uint, error) {
rss := uint(C.getRSS())
if rss == 0 {
return 0, errors.New("failed to get RSS")
}
return rss, nil
}

0 comments on commit 3b5029d

Please sign in to comment.