Skip to content

Instantly share code, notes, and snippets.

@hokiegeek2
Last active June 23, 2023 21:43
Show Gist options
  • Save hokiegeek2/915d91f3ab092db0f63c17bdfbc8073f to your computer and use it in GitHub Desktop.
Save hokiegeek2/915d91f3ab092db0f63c17bdfbc8073f to your computer and use it in GitHub Desktop.
arkouda-memory-mgmt
module MemoryReporting {
use IO;
use Memory.Diagnostics;
proc getMemory() throws {
var aFile = open('/proc/meminfo', ioMode.r);
var lines = aFile.reader().lines();
var line : string;
var memTotal:int;
var memAvail:int;
for line in lines do {
if line.find('MemTotal:') >= 0 {
writeln('MemTotal %i'.format(processLine(line,'MemTotal:')));
}
if line.find('MemAvailable:') >= 0 {
writeln('MemAvailable %i'.format(processLine(line,'MemAvailable:')));
}
}
writeln('Chapel MemUsed: %i'.format(getMemoryUsed()));
}
proc processLine(line: string, delimiter: string) throws {
var splits = line.split(delimiter);
for split in splits {
if split.find('kB') >= 0 {
var mem_splits = split.split("kB");
return mem_splits(0):int;
}
}
return 0;
}
proc getMemoryUsed() {
return memoryUsed()/1000;
}
proc main() {
try! getMemory();
}
}
@hokiegeek2
Copy link
Author

The chapel code get total memory, available memory, and Chapel memoryUsed:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment