memory percent

git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@571 e54a6e83-5905-42d5-8d5c-058d10e6a962


Origin commit data
------------------
Commit: 393ef2a20d
Author: Jacek Jendrzej <overx300@gmail.com>
Date: 2010-05-06 (Thu, 06 May 2010)
This commit is contained in:
Jacek Jendrzej
2010-05-06 14:16:33 +00:00
parent 1543c84b7b
commit 3ca30ded7c

View File

@@ -223,38 +223,10 @@ void CDBoxInfoWidget::paint()
ypos+= mheight/2; ypos+= mheight/2;
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(x+ 10, ypos+ mheight, width - 10, sbuf, COL_MENUCONTENT); g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(x+ 10, ypos+ mheight, width - 10, sbuf, COL_MENUCONTENT);
ypos+= mheight; ypos+= mheight;
snprintf(ubuf,buf_size, "memory total %dKb, free %dKb", (int) info.totalram/1024, (int) info.freeram/1024);
ypos+= mheight/2;
g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(x+ 10, ypos+ mheight, width - 10, ubuf, COL_MENUCONTENT);
ypos+= mheight;
int headOffset=0; int headOffset=0;
int mpOffset=0; int mpOffset=0;
bool rec_mp=false; bool rec_mp=false, memory_flag = false;
if ((mountFile = setmntent("/proc/mounts", "r")) == 0 ) {
perror("/proc/mounts");
}
else {
float gb=0;
char c=' ';
while ((mnt = getmntent(mountFile)) != 0) {
if (::statfs(mnt->mnt_dir, &s) == 0) {
switch (s.f_type)
{
case (int) 0xEF53: /*EXT2 & EXT3*/
case (int) 0x6969: /*NFS*/
case (int) 0xFF534D42: /*CIFS*/
case (int) 0x517B: /*SMB*/
case (int) 0x52654973: /*REISERFS*/
case (int) 0x65735546: /*fuse for ntfs*/
case (int) 0x58465342: /*xfs*/
case (int) 0x4d44: /*msdos*/
gb = 1024.0*1024.0;
c = 'G';
break;
case (int) 0x72b6: /*jffs2*/
if (strcmp(mnt->mnt_fsname, "rootfs") == 0)
continue;
// paint mount head // paint mount head
for (int j = 0; j < headSize; j++) { for (int j = 0; j < headSize; j++) {
switch (j) switch (j)
@@ -279,16 +251,46 @@ void CDBoxInfoWidget::paint()
} }
ypos+= mheight; ypos+= mheight;
if ((mountFile = setmntent("/proc/mounts", "r")) == 0 ) {
perror("/proc/mounts");
}
else {
float gb=0;
char c=' ';
while ((mnt = getmntent(mountFile)) != 0) {
if (::statfs(mnt->mnt_dir, &s) == 0) {
switch (s.f_type)
{
case (int) 0xEF53: /*EXT2 & EXT3*/
case (int) 0x6969: /*NFS*/
case (int) 0xFF534D42: /*CIFS*/
case (int) 0x517B: /*SMB*/
case (int) 0x52654973: /*REISERFS*/
case (int) 0x65735546: /*fuse for ntfs*/
case (int) 0x58465342: /*xfs*/
case (int) 0x4d44: /*msdos*/
gb = 1024.0*1024.0;
c = 'G';
break;
case (int) 0x72b6: /*jffs2*/
if (strcmp(mnt->mnt_fsname, "rootfs") == 0){
strcpy(mnt->mnt_fsname,"memory");
memory_flag = true;
}
gb = 1024.0; gb = 1024.0;
c = 'M'; c = 'M';
break; break;
default: default:
continue; continue;
} }
if ( s.f_blocks > 0 ) { if ( s.f_blocks > 0 || memory_flag ) {
long blocks_used; long blocks_used;
long blocks_percent_used; long blocks_percent_used;
blocks_used = s.f_blocks - s.f_bfree; blocks_used = s.f_blocks - s.f_bfree;
if(memory_flag){
blocks_percent_used = (info.totalram/1024 - info.freeram/1024)*100/(info.totalram/1024);
}else
blocks_percent_used = (long)(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5); blocks_percent_used = (long)(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
//paint mountpoints //paint mountpoints
for (int j = 0; j < headSize; j++) { for (int j = 0; j < headSize; j++) {
@@ -318,14 +320,24 @@ void CDBoxInfoWidget::paint()
break; break;
case 1: case 1:
mpOffset = nameOffset + 10; mpOffset = nameOffset + 10;
if(memory_flag)
snprintf(ubuf,buf_size,"%7.2f%c", info.totalram/1024.0 / gb, c);
else
snprintf(ubuf,buf_size,"%7.2f%c", (s.f_blocks * (s.f_bsize / 1024.0)) / gb, c); snprintf(ubuf,buf_size,"%7.2f%c", (s.f_blocks * (s.f_bsize / 1024.0)) / gb, c);
break; break;
case 2: case 2:
mpOffset = nameOffset+ (sizeOffset+10)*1+10; mpOffset = nameOffset+ (sizeOffset+10)*1+10;
if(memory_flag)
snprintf(ubuf,buf_size,"%7.2f%c", (info.totalram/1024.0 - info.freeram/1024.0) / gb, c);
else
snprintf(ubuf,buf_size,"%7.2f%c", ((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)) / gb, c); snprintf(ubuf,buf_size,"%7.2f%c", ((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)) / gb, c);
break; break;
case 3: case 3:
mpOffset = nameOffset+ (sizeOffset+10)*2+10; mpOffset = nameOffset+ (sizeOffset+10)*2+10;
if(memory_flag)
snprintf(ubuf,buf_size,"%7.2f%c", info.freeram / 1024.0 / gb, c);
else
snprintf(ubuf,buf_size,"%7.2f%c", s.f_bavail * (s.f_bsize / 1024.0) / gb, c); snprintf(ubuf,buf_size,"%7.2f%c", s.f_bavail * (s.f_bsize / 1024.0) / gb, c);
break; break;
case 4: case 4:
@@ -337,6 +349,7 @@ void CDBoxInfoWidget::paint()
rec_mp = false; rec_mp = false;
} }
int pbw = width - offsetw - 10; int pbw = width - offsetw - 10;
memory_flag = false;
//fprintf(stderr, "width: %d offsetw: %d pbw: %d\n", width, offsetw, pbw); //fprintf(stderr, "width: %d offsetw: %d pbw: %d\n", width, offsetw, pbw);
if (pbw > 8) /* smaller progressbar is not useful ;) */ if (pbw > 8) /* smaller progressbar is not useful ;) */
{ {