-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Return value of getRSS() is too short for 64-bit environment. This will fixed in my next commit.
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package phymem | ||
|
||
/* | ||
#include <stdio.h> | ||
#include <sys/param.h> | ||
#include <sys/sysctl.h> | ||
#include <unistd.h> | ||
static int | ||
getRSS(void) | ||
{ | ||
int ret; | ||
size_t len; | ||
struct kinfo_proc2 kp; | ||
int mib[] = {CTL_KERN, KERN_PROC2, KERN_PROC_PID, getpid(), sizeof(kp), 1}; | ||
size_t miblen = __arraycount(mib); | ||
len = sizeof(kp); | ||
ret = sysctl(mib, miblen, &kp, &len, NULL, 0); | ||
if (ret < 0) { | ||
return -1; | ||
} | ||
long pagesize = sysconf(_SC_PAGESIZE); | ||
return kp.p_vm_rssize * pagesize; | ||
} | ||
*/ | ||
import "C" | ||
import "fmt" | ||
|
||
// for test. | ||
const providedCurrent = true | ||
|
||
func Current() (uint, error){ | ||
rss := int(C.getRSS()) | ||
if rss < 0 { | ||
return 0, fmt.Errorf("failed to get RSS via sysctl: %d", rss) | ||
} | ||
return uint(rss), nil | ||
} |