Skip to content

Commit

Permalink
Reengineer "/memory" command.
Browse files Browse the repository at this point in the history
  • Loading branch information
emsquared committed Jul 1, 2012
1 parent ccfaa5a commit 13b58c7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
<key>TXBundleBuildCodeName</key>
<string>Dave Matthews Band® Magic Brownies™ Encore Edition</string>
<key>TXBundleBuildNumber</key>
<string>11719</string>
<string>11729</string>
<key>TXBundleBuildReference</key>
<string>2.1.1-214-g384398f-debug,llvm4.0</string>
<string>2.1.1-215-gccfaa5a-debug,llvm4.0</string>
</dict>
</plist>
1 change: 1 addition & 0 deletions Resources/Plugins/System Profiler/SystemProfiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <mach/mach.h>
#include <mach/mach_host.h>
#include <mach/host_info.h>
#include <mach/mach_vm.h>

#include <sys/mount.h>
#include <sys/types.h>
Expand Down
62 changes: 50 additions & 12 deletions Resources/Plugins/System Profiler/TPI_SP_SysInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ + (NSString *)compiledOutput

sysinfo = [sysinfo stringByAppendingString:_new];
}

if ([sysinfo hasSuffix:@" \002\002"]) {
sysinfo = [sysinfo safeSubstringToIndex:(sysinfo.length - 3)];
}
Expand Down Expand Up @@ -415,21 +415,17 @@ + (NSString *)formattedCPUFrequency:(TXNSDouble)rate

+ (NSString *)applicationMemoryUsage
{
struct task_basic_info info;

mach_msg_type_number_t size = sizeof(info);
kern_return_t kerr = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &size);

if (kerr == KERN_SUCCESS) {
return TXTFLS(@"SystemInformationApplicationMemoryUse", [self formattedDiskSize:info.resident_size]);
}

return nil;
NSDictionary *mem = [TPI_SP_SysInfo _applicationMemoryInternalInformation];

NSString *shared = [self formattedDiskSize:[mem integerForKey:@"shared"]];
NSString *private = [self formattedDiskSize:[mem integerForKey:@"private"]];

return TXTFLS(@"SystemInformationApplicationMemoryUse", private, shared);
}

+ (NSString *)graphicsCardInfo
{
CGDirectDisplayID displayID = CGMainDisplayID();
CGDirectDisplayID displayID = CGMainDisplayID();
CGOpenGLDisplayMask displayMask = CGDisplayIDToOpenGLDisplayMask(displayID);

GLint numPixelFormats = 0;
Expand Down Expand Up @@ -650,4 +646,46 @@ + (NSString *)physicalMemorySize
return [self formattedDiskSize:[self totalMemorySize]];
}

+ (NSDictionary *)_applicationMemoryInternalInformation
{
kern_return_t kernr;

mach_vm_address_t addr = 0;

NSInteger shrdmem = 0;
NSInteger privmem = 0;

int pagesize = getpagesize();

while (1 == 1) {
mach_vm_address_t size;

vm_region_top_info_data_t info;

mach_msg_type_number_t count = VM_REGION_TOP_INFO_COUNT;
mach_port_t object_name;

kernr = mach_vm_region(mach_task_self(), &addr, &size, VM_REGION_TOP_INFO,
(vm_region_info_t)&info, &count, &object_name);

if (NSDissimilarObjects(kernr, KERN_SUCCESS)) {
break;
}

if (info.share_mode == SM_PRIVATE) {
privmem += (info.private_pages_resident * pagesize);
shrdmem += (info.shared_pages_resident * pagesize);
} else if (info.share_mode == SM_COW) {
privmem += (info.private_pages_resident * pagesize);
shrdmem += (info.shared_pages_resident * (pagesize / info.ref_count));
} else if (info.share_mode == SM_SHARED) {
shrdmem += (info.shared_pages_resident * (pagesize / info.ref_count));
}

addr += size;
}

return @{@"shared" : @(shrdmem), @"private" : @(privmem)};
}

@end

0 comments on commit 13b58c7

Please sign in to comment.