Last active
June 23, 2023 21:43
-
-
Save hokiegeek2/915d91f3ab092db0f63c17bdfbc8073f to your computer and use it in GitHub Desktop.
arkouda-memory-mgmt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The chapel code get total memory, available memory, and Chapel memoryUsed: