Permalink
Browse files

Adding os.totalmem() and os.freemem() for SunOS

  • Loading branch information...
1 parent 21724ec commit 5d9dc1c6d5babaf033f40d90c13e87563c7f5de5 @alram alram committed with ry May 19, 2011
Showing with 27 additions and 2 deletions.
  1. +27 −2 src/platform_sunos.cc
View
29 src/platform_sunos.cc
@@ -216,12 +216,37 @@ int Platform::GetCPUInfo(Local<Array> *cpus) {
double Platform::GetFreeMemory() {
- return 0.0;
+ kstat_ctl_t *kc;
+ kstat_t *ksp;
+ kstat_named_t *knp;
+
+ double pagesize = static_cast<double>(sysconf(_SC_PAGESIZE));
+ ulong_t freemem;
+
+ if((kc = kstat_open()) == NULL)
+ throw "could not open kstat";
+
+ ksp = kstat_lookup(kc, "unix", 0, "system_pages");
+
+ if(kstat_read(kc, ksp, NULL) == -1){
+ throw "could not read kstat";
+ }
+ else {
+ knp = (kstat_named_t *) kstat_data_lookup(ksp, "freemem");
+ freemem = knp->value.ul;
+ }
+
+ kstat_close(kc);
+
+ return static_cast<double>(freemem)*pagesize;
}
double Platform::GetTotalMemory() {
- return 0.0;
+ double pagesize = static_cast<double>(sysconf(_SC_PAGESIZE));
+ double pages = static_cast<double>(sysconf(_SC_PHYS_PAGES));
+
+ return pagesize*pages;
}
double Platform::GetUptime() {

0 comments on commit 5d9dc1c

Please sign in to comment.