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

Zero maps from Python #142

Closed
brendangregg opened this issue Aug 18, 2015 · 3 comments
Closed

Zero maps from Python #142

brendangregg opened this issue Aug 18, 2015 · 3 comments

Comments

@brendangregg
Copy link
Member

When using maps to store per-interval sums, it would be handy if we could clear the maps from Python, otherwise it's necessary to store the prior values and then calculate the delta each interval. Of course, Python could pretend to clear the maps and keep its own tally of what to expose.

@drzaeus77
Copy link
Collaborator

This actually already works! Python conveniently implements a bunch of functions (like clear) when one inherits from MutableMapping. I will add a test case to capture this.

drzaeus77 pushed a commit that referenced this issue Aug 22, 2015
@brendangregg
Copy link
Member Author

I couldn't get clear() to work. Maybe I'm using it incorrectly? From pidpersec:

# output
while (1):
        try:
                sleep(1)
        except KeyboardInterrupt:
                pass; exit()

        print("%s: PIDs/sec: %d" % (strftime("%H:%M:%S"),
            b["stats"][S_COUNT].value))
        b["stats"].clear()
# ./pidpersec 
Tracing... Ctrl-C to end.
19:29:33: PIDs/sec: 0
19:29:34: PIDs/sec: 0
19:29:35: PIDs/sec: 0
19:29:36: PIDs/sec: 0
19:29:37: PIDs/sec: 17
19:29:38: PIDs/sec: 17
19:29:39: PIDs/sec: 18
19:29:40: PIDs/sec: 19
19:29:41: PIDs/sec: 19
19:29:42: PIDs/sec: 19
19:29:43: PIDs/sec: 19

@brendangregg
Copy link
Member Author

this now works, thanks!

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