ProcessController: Fix memory calculations.

On systems with > 4GB of memory, the calculations would overflow,
leading to the memory bars being drawn incorrectly.
This commit is contained in:
Rene Gollent 2013-07-19 20:50:36 -04:00
parent 8f79f5f3b8
commit 1c292f7eb4
5 changed files with 19 additions and 17 deletions

View File

@ -39,9 +39,9 @@ KernelMemoryBarMenuItem::KernelMemoryBarMenuItem(system_info& systemInfo)
fLastSum = -1;
fGrenze1 = -1;
fGrenze2 = -1;
fPhysicalMemory = systemInfo.max_pages * B_PAGE_SIZE / 1024LL;
fCommittedMemory = systemInfo.used_pages * B_PAGE_SIZE / 1024LL;
fCachedMemory = systemInfo.cached_pages * B_PAGE_SIZE / 1024LL;
fPhysicalMemory = (int64)systemInfo.max_pages * B_PAGE_SIZE / 1024LL;
fCommittedMemory = (int64)systemInfo.used_pages * B_PAGE_SIZE / 1024LL;
fCachedMemory = (int64)systemInfo.cached_pages * B_PAGE_SIZE / 1024LL;
}

View File

@ -89,8 +89,8 @@ MemoryBarMenu::Pulse()
{
system_info sinfo;
get_system_info(&sinfo);
int committedMemory = int(sinfo.used_pages * B_PAGE_SIZE / 1024);
int cachedMemory = int(sinfo.cached_pages * B_PAGE_SIZE / 1024);
int64 committedMemory = (int64)sinfo.used_pages * B_PAGE_SIZE / 1024;
int64 cachedMemory = (int64)sinfo.cached_pages * B_PAGE_SIZE / 1024;
Window()->BeginViewTransaction();
// create the list of items to remove, for their team is gone. Update the old teams.

View File

@ -55,7 +55,7 @@ MemoryBarMenuItem::Init()
fAllMemory = -1;
fGrenze1 = -1;
fGrenze2 = -1;
fLastCommited = -1;
fLastCommitted = -1;
fLastWrite = -1;
fLastAll = -1;
}
@ -108,7 +108,7 @@ MemoryBarMenuItem::DrawBar(bool force)
{
// only draw anything if something has changed
if (!force && fWriteMemory == fLastWrite && fAllMemory == fLastAll
&& fCommitedMemory == fLastCommited)
&& fCommittedMemory == fLastCommitted)
return;
bool selected = IsSelected();
@ -135,8 +135,10 @@ MemoryBarMenuItem::DrawBar(bool force)
rect.InsetBy(1, 1);
BRect r = rect;
double grenze1 = rect.left + (rect.right - rect.left) * float(fWriteMemory) / fCommitedMemory;
double grenze2 = rect.left + (rect.right - rect.left) * float(fAllMemory) / fCommitedMemory;
double grenze1 = rect.left + (rect.right - rect.left) * float(fWriteMemory)
/ fCommittedMemory;
double grenze2 = rect.left + (rect.right - rect.left) * float(fAllMemory)
/ fCommittedMemory;
if (grenze1 > rect.right)
grenze1 = rect.right;
if (grenze2 > rect.right)
@ -188,7 +190,7 @@ MemoryBarMenuItem::DrawBar(bool force)
fGrenze1 = grenze1;
fGrenze2 = grenze2;
fLastCommited = fCommitedMemory;
fLastCommitted = fCommittedMemory;
// Draw the values if necessary; if only fCommitedMemory changes, only
// the bar might have to be updated
@ -234,9 +236,9 @@ MemoryBarMenuItem::GetContentSize(float* _width, float* _height)
int
MemoryBarMenuItem::UpdateSituation(int64 commitedMemory)
MemoryBarMenuItem::UpdateSituation(int64 committedMemory)
{
fCommitedMemory = commitedMemory;
fCommittedMemory = committedMemory;
BarUpdate();
return fWriteMemory;
}

View File

@ -36,17 +36,17 @@ class MemoryBarMenuItem : public BMenuItem {
void DrawIcon();
void DrawBar(bool force);
int UpdateSituation(int64 commitedMemory);
int UpdateSituation(int64 committedMemory);
void BarUpdate();
void Init();
void Reset(char* name, team_id team, BBitmap* icon, bool deleteIcon);
private:
int64 fPhysicalMemory;
int64 fCommitedMemory;
int64 fCommittedMemory;
int64 fWriteMemory;
int64 fAllMemory;
int64 fLastCommited;
int64 fLastCommitted;
int64 fLastWrite;
int64 fLastAll;
team_id fTeamID;

View File

@ -738,14 +738,14 @@ thread_popup(void *arg)
// Memory Usage section
MemoryBarMenu* MemoryPopup = new MemoryBarMenu(B_TRANSLATE("Memory usage"),
infos, systemInfo);
int commitedMemory = int(systemInfo.used_pages * B_PAGE_SIZE / 1024);
int64 committedMemory = (int64)systemInfo.used_pages * B_PAGE_SIZE / 1024;
for (m = 0; m < systemInfo.used_teams; m++) {
if (infos[m].team_info.team >= 0) {
MemoryBarMenuItem* memoryItem =
new MemoryBarMenuItem(infos[m].team_name,
infos[m].team_info.team, infos[m].team_icon, false, NULL);
MemoryPopup->AddItem(memoryItem);
memoryItem->UpdateSituation(commitedMemory);
memoryItem->UpdateSituation(committedMemory);
}
}