From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 08CC9138200 for ; Thu, 25 Jul 2013 15:20:37 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 71F80E0A6D; Thu, 25 Jul 2013 15:20:35 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B206EE0A6A for ; Thu, 25 Jul 2013 15:20:34 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 8487833E9B2 for ; Thu, 25 Jul 2013 15:20:33 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id F3D1AE5458 for ; Thu, 25 Jul 2013 15:20:31 +0000 (UTC) From: "André Erdmann" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "André Erdmann" Message-ID: <1374762692.4b9358dbf616678865d53b699e4ba6734b00b6d2.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/stats/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/stats/abstract.py roverlay/stats/base.py roverlay/stats/collector.py X-VCS-Directories: roverlay/stats/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: 4b9358dbf616678865d53b699e4ba6734b00b6d2 X-VCS-Branch: master Date: Thu, 25 Jul 2013 15:20:31 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: c25017b3-f921-4605-9f38-9367bb29cd56 X-Archives-Hash: 021e408cfc073fb94d4f560a1c91ef21 commit: 4b9358dbf616678865d53b699e4ba6734b00b6d2 Author: André Erdmann mailerd de> AuthorDate: Thu Jul 25 14:31:32 2013 +0000 Commit: André Erdmann mailerd de> CommitDate: Thu Jul 25 14:31:32 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=4b9358db stats collection: data types, overlay stats --- roverlay/stats/abstract.py | 109 ++++++++++++++++++++++++++++++++------------ roverlay/stats/base.py | 24 ++++++---- roverlay/stats/collector.py | 6 +-- 3 files changed, 98 insertions(+), 41 deletions(-) diff --git a/roverlay/stats/abstract.py b/roverlay/stats/abstract.py index b6a4ee9..a8a2200 100644 --- a/roverlay/stats/abstract.py +++ b/roverlay/stats/abstract.py @@ -4,9 +4,21 @@ # Distributed under the terms of the GNU General Public License; # either version 2 of the License, or (at your option) any later version. +from __future__ import division + import collections import time +class MethodNotImplemented ( NotImplementedError ): + def __init__ ( self, obj, method ): + super ( MethodNotImplemented, self ).__init__ ( + "{n}.{f}()".format ( n=obj.__class__.__name__, f=method ) + ) + # --- end of __init__ (...) --- + +# --- end of MethodNotImplemented --- + + class RoverlayStatsBase ( object ): @classmethod @@ -15,9 +27,17 @@ class RoverlayStatsBase ( object ): # --- end of get_new (...) --- def merge_with ( self, other ): - raise NotImplementedError() + if hasattr ( self, '_MEMBERS' ): + self.merge_members ( other ) + else: + raise MethodNotImplemented ( self, 'merge_with' ) # --- end of merge_with (...) --- + def merge_members ( self, other ): + for member in self.__class__._MEMBERS: + getattr ( self, member ).merge_with ( getattr ( other, member ) ) + # --- end of merge_members (...) --- + def _iter_members ( self, nofail=False ): if not nofail or hasattr ( self, '_MEMBERS' ): for member in self.__class__._MEMBERS: @@ -33,7 +53,7 @@ class RoverlayStatsBase ( object ): if hasattr ( self.__class__, '_MEMBERS' ): self.reset_members() else: - raise NotImplementedError() + raise MethodNotImplemented ( self, 'reset' ) # --- end of reset (...) --- def get_description_str ( self ): @@ -57,7 +77,7 @@ class RoverlayStatsBase ( object ): if ret: return ret else: - raise NotImplementedError() + raise MethodNotImplemented ( self, '__str__' ) # --- end of __str__ (...) --- # --- end of RoverlayStatsBase --- @@ -76,14 +96,61 @@ class RoverlayStats ( RoverlayStatsBase ): # --- end of RoverlayStats --- +class Counter ( RoverlayStatsBase ): + def __init__ ( self, description=None, initial_value=0 ): + super ( Counter, self ).__init__() + self.description = description + self.total_count = initial_value + self.underflow = False + # --- end of __init__ (...) --- + + def __int__ ( self ): + return self.total_count + # --- end of __int__ (...) --- + + def __float__ ( self ): + return float ( self.total_count ) + # --- end of __float__ (...) --- + + def reset ( self ): + self.total_count = 0 + self.underflow = False + # --- end of reset (...) --- + + def inc ( self, step=1 ): + self.total_count += step + # --- end of inc (...) --- + + def dec ( self, step=1 ): + self.total_count -= step + if self.total_count < 0: + self.underflow = True + # --- end of dec (...) --- + + def merge_with ( self, other ): + self.total_count += other.total_count + if other.underflow: + self.underflow = True + # --- end of merge_with (...) --- + + def gen_str ( self ): + desc = self.get_description_str() + if desc: + yield "{}: {:d}".format ( desc, self.total_count ) + else: + yield str ( self.total_count ) + + if self.underflow: + yield "*** underflow detected ***" + # --- end of gen_str (...) --- + +# --- end of Counter --- + -class DetailedCounter ( RoverlayStatsBase ): +class DetailedCounter ( Counter ): def __init__ ( self, description=None ): - super ( DetailedCounter, self ).__init__() - self.description = description - self.total_count = 0 + super ( DetailedCounter, self ).__init__ ( description=description ) self._detailed_count = collections.defaultdict ( int ) - self.underflow = False # --- end of __init__ (...) --- def __getitem__ ( self, key ): @@ -93,14 +160,6 @@ class DetailedCounter ( RoverlayStatsBase ): raise KeyError ( key ) # --- end of __getitem__ (...) --- - def __int__ ( self ): - return self.total_count - # --- end of __int__ (...) --- - - def __float__ ( self ): - return float ( self.total_count ) - # --- end of __float__ (...) --- - def get ( self, key=None, fallback=0 ): if key is None: return self.total_count @@ -111,8 +170,7 @@ class DetailedCounter ( RoverlayStatsBase ): # --- end of get (...) --- def reset ( self ): - self.total_count = 0 - self.underflow = False + super ( DetailedCounter, self ).reset() self._detailed_count.clear() # --- end of reset (...) --- @@ -121,8 +179,8 @@ class DetailedCounter ( RoverlayStatsBase ): self._detailed_count [k] += 1 # --- end of inc_details_v (...) --- - def inc ( self, *details ): - self.total_count += 1 + def inc ( self, *details, **kw ): + super ( DetailedCounter, self ).inc ( **kw ) self.inc_details_v ( details ) # --- end of inc (...) --- @@ -139,10 +197,8 @@ class DetailedCounter ( RoverlayStatsBase ): self.underflow = True # --- end of dec_details_v (...) --- - def dec ( self, *details ): - self.total_count -= 1 - if self.total_count < 0: - self.underflow = True + def dec ( self, *details, **kw ): + super ( DetailedCounter, self ).dec ( **kw ) self.dec_details_v ( details ) # --- end of dec (...) --- @@ -151,12 +207,9 @@ class DetailedCounter ( RoverlayStatsBase ): # --- end of dec_details (...) --- def merge_with ( self, other ): - self.total_count += other.totalcount + super ( DetailedCounter, self ).merge_with ( other ) for key, value in other._detailed_count.items(): self._detailed_count [key] += value - - if other.underflow: - self.underflow = True # --- end of merge_with (...) --- def gen_str ( self ): diff --git a/roverlay/stats/base.py b/roverlay/stats/base.py index 6e37581..b03092b 100644 --- a/roverlay/stats/base.py +++ b/roverlay/stats/base.py @@ -59,24 +59,28 @@ class OverlayCreationStats ( abstract.RoverlayStats ): return 0 # --- end of get_relevant_package_count (...) --- + def __str__ ( self ): + return "*** no overlay creation stats available ***" + # --- end of __str__ (...) --- + # --- end of OverlayCreationStats --- class OverlayStats ( abstract.RoverlayStats ): - _MEMBERS = frozenset({ 'ebuild_count', }) + _MEMBERS = frozenset ({ + 'ebuilds_scanned', 'ebuild_count', 'ebuilds_written', + }) def __init__ ( self ): super ( OverlayStats, self ).__init__() - # ebuild_count counts *physical* ebuilds - # number of created ebuilds is part of overlay creation stats - self.ebuild_count = abstract.DetailedCounter ( - description="ebuild count" - ) - # --- end of __init__ (...) --- + # ebuilds_scanned: ebuild count prior to running overlay creation + self.ebuilds_scanned = abstract.Counter ( "pre" ) - def ebuild_added ( self, origin ): - self.ebuild_count.inc ( origin ) - # --- end of ebuild_added (...) --- + # ebuild count: ebuild count after writing the overlay + self.ebuild_count = abstract.Counter ( "post" ) + + self.ebuilds_written = abstract.Counter ( "written" ) + # --- end of __init__ (...) --- # --- end of OverlayStats --- diff --git a/roverlay/stats/collector.py b/roverlay/stats/collector.py index fc48d2a..d3c318e 100644 --- a/roverlay/stats/collector.py +++ b/roverlay/stats/collector.py @@ -4,8 +4,6 @@ # Distributed under the terms of the GNU General Public License; # either version 2 of the License, or (at your option) any later version. -from __future__ import division - from . import abstract from . import base @@ -14,7 +12,7 @@ class StatsCollector ( abstract.RoverlayStatsBase ): _instance = None - _MEMBERS = frozenset ({ 'repo', 'overlay', 'overlay_creation', }) + _MEMBERS = [ 'repo', 'distmap', 'overlay_creation', 'overlay', ] @classmethod def get_instance ( cls ): @@ -41,6 +39,8 @@ class StatsCollector ( abstract.RoverlayStatsBase ): # (Still better than using the repo package count since that may # not include old package files) # + # !!! useless. distmap includes "successful" packages only + # return abstract.SuccessRatio ( num_ebuilds = self.overlay.ebuild_count, num_pkg = self.distmap.pkg_count,