Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - How to get storage and memory information?: (5 Items)
   
How to get storage and memory information?  
I want to implement a program in C++ to get system storage information, such as total storage size, free storage size, 
total memory size and free memory size.
How to do it?

Allen Chen
RE: How to get storage and memory information?  
You could have a look at the df source for disk space:
http://svn.ott.qnx.com/view/product/trunk/utils/d/df/nto/

Below is some C code for getting free and total memory.

Chris

#include <errno.h>
#include <stdint.h>
#include <unistd.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/syspage.h>

uint64_t
get_free_mem (void)
{
        int ret;
        struct stat64 sbuf;
        ret = stat64("/proc", &sbuf);
        if (ret == -1) {
                printf("stat(/proc) failed: %s", strerror(errno));
        }
        return sbuf.st_size;
}

uint64_t
get_total_mem (void)
{
        char *str = SYSPAGE_ENTRY(strings)->data;
        struct asinfo_entry     *as = SYSPAGE_ENTRY(asinfo);
        uint64_t total = 0;
        unsigned num;
     
        for (num = _syspage_ptr->asinfo.entry_size / sizeof(*as); num > 0; --num) {
                if(strcmp(&str[as->name], "ram") == 0) {
                        total += as->end - as->start + 1;
                }
                ++as;
        }
        return total;
}

int main (int argc, char **argv)
{
        uint64_t free_mem = get_free_mem();
        uint64_t total_mem = get_total_mem();

        printf("FreeMem/TotalMem: %llu/%llu",free_mem,total_mem );
}

-----Original Message-----
From: Allen Chen [mailto:community-noreply@qnx.com] 
Sent: May-07-13 3:29 AM
To: general-filesystems
Subject: How to get storage and memory information?

I want to implement a program in C++ to get system storage information, such as total storage size, free storage size, 
total memory size and free memory size.
How to do it?

Allen Chen



_______________________________________________

General
http://community.qnx.com/sf/go/post101198
To cancel your subscription to this discussion, please e-mail general-filesystems-unsubscribe@community.qnx.com
RE: How to get storage and memory information?  
Actually you wouldn't have access to this source link...this might be available on foundry27 for you...let me look.

-----Original Message-----
From: Chris Travis 
Sent: May-07-13 9:05 AM
To: general-filesystems
Subject: RE: How to get storage and memory information?

You could have a look at the df source for disk space:
http://svn.ott.qnx.com/view/product/trunk/utils/d/df/nto/

Below is some C code for getting free and total memory.

Chris

#include <errno.h>
#include <stdint.h>
#include <unistd.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/syspage.h>

uint64_t
get_free_mem (void)
{
        int ret;
        struct stat64 sbuf;
        ret = stat64("/proc", &sbuf);
        if (ret == -1) {
                printf("stat(/proc) failed: %s", strerror(errno));
        }
        return sbuf.st_size;
}

uint64_t
get_total_mem (void)
{
        char *str = SYSPAGE_ENTRY(strings)->data;
        struct asinfo_entry     *as = SYSPAGE_ENTRY(asinfo);
        uint64_t total = 0;
        unsigned num;
     
        for (num = _syspage_ptr->asinfo.entry_size / sizeof(*as); num > 0; --num) {
                if(strcmp(&str[as->name], "ram") == 0) {
                        total += as->end - as->start + 1;
                }
                ++as;
        }
        return total;
}

int main (int argc, char **argv)
{
        uint64_t free_mem = get_free_mem();
        uint64_t total_mem = get_total_mem();

        printf("FreeMem/TotalMem: %llu/%llu",free_mem,total_mem ); }

-----Original Message-----
From: Allen Chen [mailto:community-noreply@qnx.com]
Sent: May-07-13 3:29 AM
To: general-filesystems
Subject: How to get storage and memory information?

I want to implement a program in C++ to get system storage information, such as total storage size, free storage size, 
total memory size and free memory size.
How to do it?

Allen Chen



_______________________________________________

General
http://community.qnx.com/sf/go/post101198
To cancel your subscription to this discussion, please e-mail general-filesystems-unsubscribe@community.qnx.com
RE: How to get storage and memory information?  
Sorry, but this has Restricted Source Access, so if you are a customer or a partner of QNX Software Systems and need 
access to QNX proprietary source code in this project please contact your QSS Sales or Support representative.

Unless somebody has some code they can share with you for storage info.

-----Original Message-----
From: Chris Travis 
Sent: May-07-13 9:07 AM
To: 'general-filesystems@community.qnx.com'
Subject: RE: How to get storage and memory information?

Actually you wouldn't have access to this source link...this might be available on foundry27 for you...let me look.

-----Original Message-----
From: Chris Travis 
Sent: May-07-13 9:05 AM
To: general-filesystems
Subject: RE: How to get storage and memory information?

You could have a look at the df source for disk space:
http://svn.ott.qnx.com/view/product/trunk/utils/d/df/nto/

Below is some C code for getting free and total memory.

Chris

#include <errno.h>
#include <stdint.h>
#include <unistd.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/syspage.h>

uint64_t
get_free_mem (void)
{
        int ret;
        struct stat64 sbuf;
        ret = stat64("/proc", &sbuf);
        if (ret == -1) {
                printf("stat(/proc) failed: %s", strerror(errno));
        }
        return sbuf.st_size;
}

uint64_t
get_total_mem (void)
{
        char *str = SYSPAGE_ENTRY(strings)->data;
        struct asinfo_entry     *as = SYSPAGE_ENTRY(asinfo);
        uint64_t total = 0;
        unsigned num;
     
        for (num = _syspage_ptr->asinfo.entry_size / sizeof(*as); num > 0; --num) {
                if(strcmp(&str[as->name], "ram") == 0) {
                        total += as->end - as->start + 1;
                }
                ++as;
        }
        return total;
}

int main (int argc, char **argv)
{
        uint64_t free_mem = get_free_mem();
        uint64_t total_mem = get_total_mem();

        printf("FreeMem/TotalMem: %llu/%llu",free_mem,total_mem ); }

-----Original Message-----
From: Allen Chen [mailto:community-noreply@qnx.com]
Sent: May-07-13 3:29 AM
To: general-filesystems
Subject: How to get storage and memory information?

I want to implement a program in C++ to get system storage information, such as total storage size, free storage size, 
total memory size and free memory size.
How to do it?

Allen Chen



_______________________________________________

General
http://community.qnx.com/sf/go/post101198
To cancel your subscription to this discussion, please e-mail general-filesystems-unsubscribe@community.qnx.com
Re: How to get storage and memory information?  
Thank you very much.
I really appreciate your help.

于 2013/5/7 21:18, Chris Travis 写道:
> Sorry, but this has Restricted Source Access, so if you are a customer or a partner of QNX Software Systems and need 
access to QNX proprietary source code in this project please contact your QSS Sales or Support representative.
>
> Unless somebody has some code they can share with you for storage info.
>
> -----Original Message-----
> From: Chris Travis
> Sent: May-07-13 9:07 AM
> To: 'general-filesystems@community.qnx.com'
> Subject: RE: How to get storage and memory information?
>
> Actually you wouldn't have access to this source link...this might be available on foundry27 for you...let me look.
>
> -----Original Message-----
> From: Chris Travis
> Sent: May-07-13 9:05 AM
> To: general-filesystems
> Subject: RE: How to get storage and memory information?
>
> You could have a look at the df source for disk space:
> http://svn.ott.qnx.com/view/product/trunk/utils/d/df/nto/
>
> Below is some C code for getting free and total memory.
>
> Chris
>
> #include <errno.h>
> #include <stdint.h>
> #include <unistd.h>
> #include <stdarg.h>
> #include <stdlib.h>
> #include <stdio.h>
> #include <string.h>
> #include <sys/stat.h>
> #include <sys/mman.h>
> #include <sys/syspage.h>
>
> uint64_t
> get_free_mem (void)
> {
>          int ret;
>          struct stat64 sbuf;
>          ret = stat64("/proc", &sbuf);
>          if (ret == -1) {
>                  printf("stat(/proc) failed: %s", strerror(errno));
>          }
>          return sbuf.st_size;
> }
>
> uint64_t
> get_total_mem (void)
> {
>          char *str = SYSPAGE_ENTRY(strings)->data;
>          struct asinfo_entry     *as = SYSPAGE_ENTRY(asinfo);
>          uint64_t total = 0;
>          unsigned num;
>       
>          for (num = _syspage_ptr->asinfo.entry_size / sizeof(*as); num > 0; --num) {
>                  if(strcmp(&str[as->name], "ram") == 0) {
>                          total += as->end - as->start + 1;
>                  }
>                  ++as;
>          }
>          return total;
> }
>
> int main (int argc, char **argv)
> {
>          uint64_t free_mem = get_free_mem();
>          uint64_t total_mem = get_total_mem();
>
>          printf("FreeMem/TotalMem: %llu/%llu",free_mem,total_mem ); }
>
> -----Original Message-----
> From: Allen Chen [mailto:community-noreply@qnx.com]
> Sent: May-07-13 3:29 AM
> To: general-filesystems
> Subject: How to get storage and memory information?
>
> I want to implement a program in C++ to get system storage information, such as total storage size, free storage size,
 total memory size and free memory size.
> How to do it?
>
> Allen Chen
>
>
>
> _______________________________________________
>
> General
> http://community.qnx.com/sf/go/post101198
> To cancel your subscription to this discussion, please e-mail general-filesystems-unsubscribe@community.qnx.com
>
>
>
>
> _______________________________________________
>
> General
> http://community.qnx.com/sf/go/post101215
> To cancel your subscription to this discussion, please e-mail general-filesystems-unsubscribe@community.qnx.com
>