Skip to content

Commit

Permalink
getmem() for solaris
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Jan 20, 2010
1 parent faefb3f commit f88d39d
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,50 @@ v8::Handle<v8::Value> Exit(const v8::Arguments& args) {
return Undefined();
}

#ifdef __sun
#define HAVE_GETMEM 1
#include <unistd.h> /* getpagesize() */

#if (!defined(_LP64)) && (_FILE_OFFSET_BITS - 0 == 64)
#define PROCFS_FILE_OFFSET_BITS_HACK 1
#undef _FILE_OFFSET_BITS
#else
#define PROCFS_FILE_OFFSET_BITS_HACK 0
#endif

#include <procfs.h>

#if (PROCFS_FILE_OFFSET_BITS_HACK - 0 == 1)
#define _FILE_OFFSET_BITS 64
#endif

int getmem(size_t *rss, size_t *vsize) {
pid_t pid = getpid();

size_t page_size = getpagesize();
char pidpath[1024];
sprintf(pidpath, "/proc/%d/psinfo", pid);

psinfo_t psinfo;
FILE *f = fopen(pidpath, "r");
if (!f) return -1;

if (fread(&psinfo, sizeof(psinfo_t), 1, f) != 1) {
fclose (f);
return -1;
}

/* XXX correct? */

*vsize = (size_t) psinfo.pr_size * page_size;
*rss = (size_t) psinfo.pr_rssize * 1024;

fclose (f);

return 0;
}
#endif


#ifdef __FreeBSD__
#define HAVE_GETMEM 1
Expand Down

0 comments on commit f88d39d

Please sign in to comment.