Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Issue 230163004: Using decorator for power monitoring.

Created:
6 years, 8 months ago by qsr
Modified:
6 years, 1 month ago
Reviewers:
jeremy
CC:
chromium-reviews, telemetry+watch_chromium.org
Visibility:
Public.

Description

Using decorator for power monitoring. R=tonyg@chromium.org,jeremy@chromium.org

Patch Set 1 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+74 lines, -11 lines) Patch
A tools/perf/measurements/decorators.py View 1 chunk +54 lines, -0 lines 0 comments Download
M tools/perf/measurements/page_cycler.py View 6 chunks +4 lines, -7 lines 0 comments Download
M tools/perf/metrics/power.py View 2 chunks +6 lines, -4 lines 0 comments Download
M tools/telemetry/telemetry/page/page_measurement.py View 2 chunks +10 lines, -0 lines 0 comments Download

Messages

Total messages: 8 (1 generated)
qsr
Tony, Jeremy -> I'm working on adding a power metric for load. Doing this, I ...
6 years, 8 months ago (2014-04-09 11:30:06 UTC) #1
qsr
Oh yes also, not ready to review, just want an answer on the idea, will ...
6 years, 8 months ago (2014-04-09 12:26:05 UTC) #2
dtu
On 2014/04/09 12:26:05, qsr wrote: > Oh yes also, not ready to review, just want ...
6 years, 8 months ago (2014-04-09 18:04:35 UTC) #3
qsr
On 2014/04/09 18:04:35, dtu wrote: > On 2014/04/09 12:26:05, qsr wrote: > > Oh yes ...
6 years, 8 months ago (2014-04-10 07:39:46 UTC) #4
dtu
On 2014/04/10 07:39:46, qsr wrote: > On 2014/04/09 18:04:35, dtu wrote: > > On 2014/04/09 ...
6 years, 8 months ago (2014-04-10 19:52:43 UTC) #5
qsr
On 2014/04/10 19:52:43, dtu wrote: > On 2014/04/10 07:39:46, qsr wrote: > > On 2014/04/09 ...
6 years, 8 months ago (2014-04-11 06:57:31 UTC) #6
dtu
6 years, 8 months ago (2014-04-14 18:47:44 UTC) #7
On 2014/04/11 06:57:31, qsr wrote:
> On 2014/04/10 19:52:43, dtu wrote:
> > On 2014/04/10 07:39:46, qsr wrote:
> > > On 2014/04/09 18:04:35, dtu wrote:
> > > > On 2014/04/09 12:26:05, qsr wrote:
> > > > > Oh yes also, not ready to review, just want an answer on the idea,
will
> > > clean
> > > > it
> > > > > up, and use it on all measurement if we agree...
> > > > 
> > > > Are you familiar with MixIns? That would be a cleaner way of doing the
> same
> > > > thing.
> > > > (A MixIn is just using multiple inheritance to override/wrap the class's
> > > > methods.)
> > > 
> > >  I didn't know python had mixin... And I must be missing something when
> > reading
> > > the doc I do not see how I can do what I want with it.
> > > 
> > >  If I make my measurement extends my mixin, I will have to call super() on
> > every
> > > method for this to work, while by using my decorator, I can have the
metric
> > > decorator choose with method it overrides and be responsible for then
> calling
> > > the original method. Does it make sense or did I miss something obvious?
> > 
> > Ah, you're right, there's a tradeoff I didn't realize.
> 
>  There is another, and one that I need, I need to be able to decorate the
method
> before and after the call, which I do not see how to do with mixins.
> 
> > Using MixIns also reduces the boilerplate in the Decorator/MixIn itself.
> > 
> > Instead of:
> >   originalCustomizeBrowserOptions = original_class.CustomizeBrowserOptions
> >   def newCustomizeBrowserOptions(self, options):
> >     originalCustomizeBrowserOptions(self, options)
> >     power.PowerMetric.CustomizeBrowserOptions(options)
> >   original_class.CustomizeBrowserOptions = newCustomizeBrowserOptions
> > You have:
> >   def CustomizeBrowserOptions(self, options):
> >     super(PowerMetricMixIn, self).CustomizeBrowserOptions(options)
> >     power.PowerMetric.CustomizeBrowserOptions(options)
> > 
> > The tradeoff is that yes, if the measurement overrides methods, you'll need
to
> > call super. But a lot of measurements (e.g. smoothness.py) won't need to
> define
> > any methods.
> 
>  Well, a little helper function can do a lot for the boiler plate:
> 
>  def _replace(replacement):
>     """Replace the the function of original_class whith the same name as
>     replacement by replacement.
>     """
>     setattr(original_class,
>             replacement.__name__,
>             MethodType(partial(replacement,
>                                getattr(original_class, replacement.__name__)),
>                        None,
>                        original_class))
> 
>  And the replacement becomes:
> 
>   def CustomizeBrowserOptions(original, self, options):
>     original(self, options)
>     power.PowerMetric.CustomizeBrowserOptions(options)
>   _replace(CustomizeBrowserOptions)
> 
> 
>  If we want to go a step further, we can pass a class to the decorator, and it
> will use the 
> bound method of the class to find which method to decorate, and the will be no
> more boilerplate than in the MixIn case.

so abstraction

sgtm

Powered by Google App Engine
This is Rietveld 408576698