This is an archive of the discontinued Mercurial Phabricator instance.

util: enable observing of util.bufferedinputpipe
ClosedPublic

Authored by indygreg on Feb 23 2018, 2:01 PM.

Details

Summary

Our file object proxy is useful. But it doesn't capture all I/O.
The "os" module offers low-level interfaces to various system calls.
For example, os.read() exposes read(2) to read from a file
descriptor.

bufferedinputpipe is special in a few ways. First, it acts as a
proxy of sorts around our [potentially proxied] file object. In
addition, it uses os.read() to satisfy all I/O. This means that
our observer doesn't see notifications for reads on this type.
This is preventing us from properly instrumenting reads on ssh
peers.

This commit teaches bufferedinputpipe to be aware of our
observed file objects. We do this by introducing a class variation
that notifies our observer of os.read() events. Since read()
and readline() bypass os.read(), we also teach this instance
to notify the observer for buffered variations of these reads as
well. We don't report them as actual read() and readline() calls
because these methods are never called on the actual file object
but rather a buffered version of it.

We introduce bufferedinputpipe.new to swap in the new class
if the passed file object is a fileobjectproxy. This makes hooking
up the observer automatic. And it is a zero cost abstraction for
I/O operations on non-proxied file objects.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

indygreg created this revision.Feb 23 2018, 2:01 PM
indygreg planned changes to this revision.Feb 23 2018, 3:12 PM

I have some revisions to this...

indygreg edited the summary of this revision. (Show Details)Feb 23 2018, 3:51 PM
indygreg retitled this revision from util: enable observing of os.read() from bufferedinputpipe to util: enable observing of util.bufferedinputpipe.
indygreg updated this revision to Diff 6025.
indygreg updated this revision to Diff 6247.Mar 1 2018, 11:30 AM
durin42 accepted this revision.Mar 1 2018, 4:13 PM
This revision is now accepted and ready to land.Mar 1 2018, 4:13 PM
This revision was automatically updated to reflect the committed changes.