Giter Club home page Giter Club logo

pstree's Introduction

A plain pstree clone made hard to maintain. If you'd like to see the nice version, go here:

https://github.com/Stantheman/pstree/tree/c9cf104425cd1114f4ad3eb239005e655df2f3d5

I've made some changes to it since then to help speed it up. It's become less idiomatic, and more tiring to read. Along the way, I've picked up some fun benchmark numbers -- you can see the increases over many small modifications:

BenchmarkPopulate            500           5910036 ns/op
BenchmarkPopulate            500           4122985 ns/op
BenchmarkPopulate           1000           2699748 ns/op
BenchmarkPopulate           1000           2447752 ns/op
BenchmarkPopulate           1000           2264165 ns/op
BenchmarkPopulate           1000           2061597 ns/op
BenchmarkPopulate           1000           1761342 ns/op
BenchmarkPopulate           1000           1560530 ns/op

Now, who needs a really fast version of a program that doesn't do everything pstree does? I'm not sure. But it's been fun trying to squeeze some speed out.

Most changes were small, and all were guided by the help of the pprof tool, including:

  • Replacing the regex for parsing /proc/pid/stat with calls to plain old string functions like index, lastindex, and fields
  • Replacing the plain old string functions with only calls to IndexByte and some slice hackery
  • Switch to using a plain old buffer instead of ioutil's ReadAll
  • Switch from using a plain old buffer to using read on the filehandle directly
  • Don't defer the filehandle close if you know you're closing it a few lines later
  • Instead of globbing on /proc/[0-9], using readdir on a proc filehandle
  • Instead of using strconv.Atoi, writing a small isInt helper method to only look at PID directories

I think I've exhausted most of the practical changes I can make since the profiler is mostly pointing to byte-to-slice conversion and file operations now.

pstree's People

Contributors

stantheman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

madper

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.