model/consoleState.js
function() {
        if (process.platform !== 'darwin') {
            return;
        }

        // top is running in logging mode, spewing process info to stdout every second.
        this._topConsole = child_process.spawn('/usr/bin/top', ['-l', '0', '-stats', 'pid,cpu,mem,command']);
        this._topConsole.stdout.on('data', _.bind(function(stdout) {
            var id = $$persistence.processId();
            if (!id) {
                return;
            }

            // Find the line with the process id that matches what we're watching.
            stdout = stdout.toString();
            var lines = stdout.split('\n');
            var line = lines.filter(function(line) {
                return line.indexOf(id) === 0;
            })[0];
            if (!line) {
                return;
            }
            var parts = line.split(/\s+/g);

            // Add to the CPU history.
            var cpu = parseFloat(parts[1]);
            this._cpuFrame(cpu);

            // Add to the memory history.
            var memory = parts[2];
            var unit = 1;
            if (memory.indexOf('K') !== -1) {
                unit = 1024;
            } else if (memory.indexOf('M') !== -1) {
                unit = 1024 * 1024;
            } else if (memory.indexOf('G') !== -1) {
                unit = 1024 * 1024 * 1024;
            }
            memory = memory.replace(/[\D]/g, '');
            memory = parseInt(memory) * unit;
            this._memoryFrame(memory);

        }, this));
    }
function() {
        if (process.platform !== 'darwin') {
            return;
        }

        // top is running in logging mode, spewing process info to stdout every second.
        this._topConsole = child_process.spawn('/usr/bin/top', ['-l', '0', '-stats', 'pid,cpu,mem,command']);
        this._topConsole.stdout.on('data', _.bind(function(stdout) {
            var id = $$persistence.processId();
            if (!id) {
                return;
            }

            // Find the line with the process id that matches what we're watching.
            stdout = stdout.toString();
            var lines = stdout.split('\n');
            var line = lines.filter(function(line) {
                return line.indexOf(id) === 0;
            })[0];
            if (!line) {
                return;
            }
            var parts = line.split(/\s+/g);

            // Add to the CPU history.
            var cpu = parseFloat(parts[1]);
            this._cpuFrame(cpu);

            // Add to the memory history.
            var memory = parts[2];
            var unit = 1;
            if (memory.indexOf('K') !== -1) {
                unit = 1024;
            } else if (memory.indexOf('M') !== -1) {
                unit = 1024 * 1024;
            } else if (memory.indexOf('G') !== -1) {
                unit = 1024 * 1024 * 1024;
            }
            memory = memory.replace(/[\D]/g, '');
            memory = parseInt(memory) * unit;
            this._memoryFrame(memory);

        }, this));
    }
function ( ) { if ( process . platform !== 'darwin' ) { return ; } // top is running in logging mode, spewing process info to stdout every second. this . _topConsole = child_process . spawn ( '/usr/bin/top' , [ '-l' , '0' , '-stats' , 'pid,cpu,mem,command' ] ) ; this . _topConsole . stdout . on ( 'data' , _ . bind ( function ( stdout ) { var id = $$persistence . processId ( ) ; if ( ! id ) { return ; } // Find the line with the process id that matches what we're watching. stdout = stdout . toString ( ) ; var lines = stdout . split ( '\n' ) ; var line = lines . filter ( function ( line ) { return line . indexOf ( id ) === 0 ; } ) [ 0 ] ; if ( ! line ) { return ; } var parts = line . split ( / \s+ / g ) ; // Add to the CPU history. var cpu = parseFloat ( parts [ 1 ] ) ; this . _cpuFrame ( cpu ) ; // Add to the memory history. var memory = parts [ 2 ] ; var unit = 1 ; if ( memory . indexOf ( 'K' ) !== - 1 ) { unit = 1024 ; } else if ( memory . indexOf ( 'M' ) !== - 1 ) { unit = 1024 * 1024 ; } else if ( memory . indexOf ( 'G' ) !== - 1 ) { unit = 1024 * 1024 * 1024 ; } memory = memory . replace ( / [\D] / g , '' ) ; memory = parseInt ( memory ) * unit ; this . _memoryFrame ( memory ) ; } , this ) ) ; }
Run 'top' to get the CPU and memory usage of the app process on Mac.
Run top to get the CPU and memory usage of the app process on Mac .