Skip to content

Instantly share code, notes, and snippets.

@paulrouget
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulrouget/e59eb6dca3eeed87e46c to your computer and use it in GitHub Desktop.
Save paulrouget/e59eb6dca3eeed87e46c to your computer and use it in GitHub Desktop.
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