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

Add a comparison mode: disable timestamps, obscure 0xblah repr pointers, & canonicalize pathnames #46

Open
1 of 2 tasks
gpshead opened this issue Oct 8, 2021 · 2 comments

Comments

@gpshead
Copy link
Contributor

gpshead commented Oct 8, 2021

My first use of snoop was to compare execution logs for a buggy area of the code between two runs to figure out where their behavior diverged. (A weak form of co-execution I suppose)

But before I could use diff, I had to post process the snoop output to remove the timestamps, obscure the repr's that contain 0x7f267b0a00 style memory addresses, and canonicalize the pathnames in str reprs that contained them as they differed between each execution environment.

It'd be nice to have a way to do a lot of this upfront via parameters to snoop() itself. I propose both of these:

  • Add the ability to omit timestamps.
  • Accept a repr post-processing callable.

The latter would allow for hex pointer value matching and cleanup as well as pathname cleanup. A pointer value cleanup only function could be provided as an example. Beyond that it's probably getting individual use case and application specific as to what people need to sanitize to make execution log comparisons easy.

@alexmojaki
Copy link
Owner

You can omit timestamps with snoop.install(columns=[]).

For the reprs, you can try cheap_repr.register_repr for specific classes, or monkeypatch my_cheap_repr in the snoop.tracer module to post-process all reprs. But this will affect the output in other ways because these reprs are used to determine if a variable's value has changed.

Alternatively you can subclass snoop.formatting.DefaultFormatter and override format_variable, then snoop.install(formatter_class=MyFormatter).

PySnooper has this feature built in since cool-RR/PySnooper#168, so snoop(normalize=True) should work there.

@martinsmid
Copy link

For a nice comparison, I've also found setting a random seed to the same value in both processes to be useful.

 import random
 random.seed(42)

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

3 participants