Last active
August 29, 2015 14:01
-
-
Save paulrouget/e59eb6dca3eeed87e46c to your computer and use it in GitHub Desktop.
This file contains 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
Cu.import("resource://gre/modules/Task.jsm"); | |
GetUSS("self").then(s => alert(s +"kB")) | |
// Works with any PID. "self" is an alias to current process. | |
function GetUSS(PID) { | |
const BUF_SIZE = 32 * 1024; | |
let path = "/proc/" + PID + "/smaps"; | |
let decoder = new TextDecoder(); | |
return Task.spawn(function* () { | |
let file = yield OS.File.open(path); | |
let text = ""; | |
// There would be an easier way to do that | |
// if we would be reading a regular file. | |
// smaps' size is 0 at first until we start | |
// reading, so we need to read piece by piece. | |
for(;;) { | |
let bytes = yield file.read(BUF_SIZE); | |
if(bytes.byteLength == 0) { | |
break; | |
} | |
text += decoder.decode(bytes); | |
} | |
let lines = text.split("\n"); | |
let total = 0; | |
for (let line of lines) { | |
if (line.indexOf("Private_Dirty") == 0 || line.indexOf("Private_Clean") == 0) { | |
total += parseInt(line.match(/Private_.*:\s+([\d]+)/)[1]); | |
} | |
} | |
return total; | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment