Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make /v flag optional #6

Closed
MarkTiedemann opened this issue Mar 3, 2017 · 6 comments
Closed

Make /v flag optional #6

MarkTiedemann opened this issue Mar 3, 2017 · 6 comments

Comments

@MarkTiedemann
Copy link
Contributor

MarkTiedemann commented Mar 3, 2017

tasklist seems to be round about 1 second slower when used with the verbose flag. Therefore, I propose making the /v flag optional.


Using timeit from the Windows Server 2003 Resource Kit Tools, I got the following outputs:

timeit tasklist:

Version Number:   Windows NT 6.2 (Build 9200)
Exit Time:        5:05 pm, Friday, March 3 2017
Elapsed Time:     0:00:00.114
Process Time:     0:00:00.015
System Calls:     56499
Context Switches: 23459
Page Faults:      6867
Bytes Read:       1708
Bytes Written:    117698
Bytes Other:      1061894

timeit tasklist /v:

Version Number:   Windows NT 6.2 (Build 9200)
Exit Time:        5:05 pm, Friday, March 3 2017
Elapsed Time:     0:00:01.359
Process Time:     0:00:00.062
System Calls:     244191
Context Switches: 65230
Page Faults:      43840
Bytes Read:       19524
Bytes Written:    648250
Bytes Other:      6542373

Hope I'm gonna be able to submit a PR soon. :)


EDIT: Just noticed there's already a closed issue regarding tasklist being slow: #4. It was closed as a wontfix. Making the /v flag optional, however, would be that missing fix.


Another question in this regard would be: Should the verbose option be true or false by default? I'm leaning towards false considering the performance impact.

@sindresorhus
Copy link
Owner

What is the difference between verbose and non-verbose output?

@MarkTiedemann
Copy link
Contributor Author

MarkTiedemann commented Mar 3, 2017

Normal output is:

  • imageName
  • pid
  • sessionName
  • sessionNumber
  • memUsage

Verbose output is (normal output plus):

  • status
  • username
  • cpuTime
  • windowTitle

Making the /v flag optional would be a breaking change, of course.

PS: Just writing a PR. :)

PPS: Love your work.

@MarkTiedemann
Copy link
Contributor Author

MarkTiedemann commented Mar 3, 2017

Another thought: How about adding a stream or even emitter interface? This would be nice for running the verbose option on slow systems, especially if you're not interested in all tasks anyway.

@sindresorhus
Copy link
Owner

How about adding a stream or even emitter interface?

Does tasklist.exe actually stream the output though?

@MarkTiedemann
Copy link
Contributor Author

Yeah, tasklist.exe outputs in chunks.

For a streaming implementation, I'm thinking about something along the lines of this ...

const spawn = require('child_process').spawn
const Transform = require('stream').Transform
const csv = require('csv')

module.exports = () => 
  spawn('tasklist.exe', ['/fo', 'csv'])
  .stdout
  .pipe(csv.parse({
    columns: [ 'imageName', 'pid', 'sessionName', 'sessionNumber', 'memUsage' ],
    from: 2 // skip header record
  }))
  .pipe(new Transform({
    objectMode: true,
    transform(task, encoding, callback) {
      callback(null, Object.assign(task, {
        pid: Number(task.pid),
        sessionNumber: Number(task.sessionNumber),
        memUsage: 1024 * Number(task.memUsage.replace(/[^\d]/g, ''))
      }))
    }
  }))

... which could be used like this ...

const tasklist = require('tasklist')

tasklist()
  .on('data', console.log)
  /* => { imageName: 'tasklist.exe',
          pid: 9620,
          sessionName: 'Console',
          sessionNumber: 3,
          memUsage: 864420 } */

Should this be part of this module, though? Or would it be better to put it in a new one, for example, tasklist-stream?

@MarkTiedemann
Copy link
Contributor Author

If anyone reading this issue is interested in a streaming interface, check out tasklist-stream. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants