Patchwork [2,of,2] branchmap: log events related to branch cache

login
register
mail settings
Submitter Gregory Szorc
Date March 25, 2014, 4:28 a.m.
Message ID <b3ee4130d09aeb4884f4.1395721721@77.1.168.192.in-addr.arpa>
Download mbox | patch
Permalink /patch/4054/
State Superseded
Commit 05cfcecb3aefbfbf2ccc711a44673782622cc232
Headers show

Comments

Gregory Szorc - March 25, 2014, 4:28 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1395533677 25200
#      Sat Mar 22 17:14:37 2014 -0700
# Node ID b3ee4130d09aeb4884f4e24bd906e8ce613fefad
# Parent  2c1c27fd67fb5be2a35a9906de07ad2610ce5fd6
branchmap: log events related to branch cache

The blackblox log will now contain log events when the branch caches are
updated and written.
Augie Fackler - April 12, 2014, 4:17 p.m.
On Mon, Mar 24, 2014 at 09:28:41PM -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1395533677 25200
> #      Sat Mar 22 17:14:37 2014 -0700
> # Node ID b3ee4130d09aeb4884f4e24bd906e8ce613fefad
> # Parent  2c1c27fd67fb5be2a35a9906de07ad2610ce5fd6
> branchmap: log events related to branch cache

These both look great to me, but I don't feel comfortable guessing
mpm's feelings. Matt?


>
> The blackblox log will now contain log events when the branch caches are
> updated and written.
>
> diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
> --- a/mercurial/branchmap.py
> +++ b/mercurial/branchmap.py
> @@ -3,16 +3,17 @@
>  # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
>  #
>  # This software may be used and distributed according to the terms of the
>  # GNU General Public License version 2 or any later version.
>
>  from node import bin, hex, nullid, nullrev
>  import encoding
>  import util
> +import time
>
>  def _filename(repo):
>      """name of a branchcache file for a given repo or repoview"""
>      filename = "cache/branch2"
>      if repo.filtername:
>          filename = '%s-%s' % (filename, repo.filtername)
>      return filename
>
> @@ -201,34 +202,40 @@ class branchcache(dict):
>
>      def write(self, repo):
>          try:
>              f = repo.opener(_filename(repo), "w", atomictemp=True)
>              cachekey = [hex(self.tipnode), str(self.tiprev)]
>              if self.filteredhash is not None:
>                  cachekey.append(hex(self.filteredhash))
>              f.write(" ".join(cachekey) + '\n')
> +            nodecount = 0
>              for label, nodes in sorted(self.iteritems()):
>                  for node in nodes:
> +                    nodecount += 1
>                      if node in self._closednodes:
>                          state = 'c'
>                      else:
>                          state = 'o'
>                      f.write("%s %s %s\n" % (hex(node), state,
>                                              encoding.fromlocal(label)))
>              f.close()
> +            repo.ui.log('branchcache',
> +                        'wrote %s branch cache with %d labels and %d nodes\n',
> +                        repo.filtername, len(self), nodecount)
>          except (IOError, OSError, util.Abort):
>              # Abort may be raise by read only opener
>              pass
>
>      def update(self, repo, revgen):
>          """Given a branchhead cache, self, that may have extra nodes or be
>          missing heads, and a generator of nodes that are strictly a superset of
>          heads missing, this function updates self to be correct.
>          """
> +        starttime = time.time()
>          cl = repo.changelog
>          # collect new branch entries
>          newbranches = {}
>          getbranchinfo = cl.branchinfo
>          for r in revgen:
>              branch, closesbranch = getbranchinfo(r)
>              newbranches.setdefault(branch, []).append(r)
>              if closesbranch:
> @@ -267,8 +274,12 @@ class branchcache(dict):
>              self.tipnode = nullid
>              self.tiprev = nullrev
>              for heads in self.values():
>                  tiprev = max(cl.rev(node) for node in heads)
>                  if tiprev > self.tiprev:
>                      self.tipnode = cl.node(tiprev)
>                      self.tiprev = tiprev
>          self.filteredhash = self._hashfiltered(repo)
> +
> +        duration = time.time() - starttime
> +        repo.ui.log('branchcache', 'updated %s branch cache in %.2f seconds\n',
> +                    repo.filtername, duration)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
Pierre-Yves David - April 12, 2014, 4:23 p.m.
On 04/12/2014 12:17 PM, Augie Fackler wrote:
> On Mon, Mar 24, 2014 at 09:28:41PM -0700, Gregory Szorc wrote:
>> # HG changeset patch
>> # User Gregory Szorc <gregory.szorc@gmail.com>
>> # Date 1395533677 25200
>> #      Sat Mar 22 17:14:37 2014 -0700
>> # Node ID b3ee4130d09aeb4884f4e24bd906e8ce613fefad
>> # Parent  2c1c27fd67fb5be2a35a9906de07ad2610ce5fd6
>> branchmap: log events related to branch cache
>
> These both look great to me, but I don't feel comfortable guessing
> mpm's feelings. Matt?


I love this change and was planning to do it myself at some point. 
however it could maybe use some test?
Augie Fackler - April 12, 2014, 4:27 p.m.
On Apr 12, 2014, at 12:23 PM, Pierre-Yves David <pierre-yves.david@ens-lyon.org> wrote:

> 
> 
> On 04/12/2014 12:17 PM, Augie Fackler wrote:
>> On Mon, Mar 24, 2014 at 09:28:41PM -0700, Gregory Szorc wrote:
>>> # HG changeset patch
>>> # User Gregory Szorc <gregory.szorc@gmail.com>
>>> # Date 1395533677 25200
>>> #      Sat Mar 22 17:14:37 2014 -0700
>>> # Node ID b3ee4130d09aeb4884f4e24bd906e8ce613fefad
>>> # Parent  2c1c27fd67fb5be2a35a9906de07ad2610ce5fd6
>>> branchmap: log events related to branch cache
>> 
>> These both look great to me, but I don't feel comfortable guessing
>> mpm's feelings. Matt?
> 
> 
> I love this change and was planning to do it myself at some point. however it could maybe use some test?

I'd be a fan of seeing some tests, yes. Honestly, since marmoute likes it, Greg, can you add a simple test that verifies this works as intended and resend?

Patch

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -3,16 +3,17 @@ 
 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
 from node import bin, hex, nullid, nullrev
 import encoding
 import util
+import time
 
 def _filename(repo):
     """name of a branchcache file for a given repo or repoview"""
     filename = "cache/branch2"
     if repo.filtername:
         filename = '%s-%s' % (filename, repo.filtername)
     return filename
 
@@ -201,34 +202,40 @@  class branchcache(dict):
 
     def write(self, repo):
         try:
             f = repo.opener(_filename(repo), "w", atomictemp=True)
             cachekey = [hex(self.tipnode), str(self.tiprev)]
             if self.filteredhash is not None:
                 cachekey.append(hex(self.filteredhash))
             f.write(" ".join(cachekey) + '\n')
+            nodecount = 0
             for label, nodes in sorted(self.iteritems()):
                 for node in nodes:
+                    nodecount += 1
                     if node in self._closednodes:
                         state = 'c'
                     else:
                         state = 'o'
                     f.write("%s %s %s\n" % (hex(node), state,
                                             encoding.fromlocal(label)))
             f.close()
+            repo.ui.log('branchcache',
+                        'wrote %s branch cache with %d labels and %d nodes\n',
+                        repo.filtername, len(self), nodecount)
         except (IOError, OSError, util.Abort):
             # Abort may be raise by read only opener
             pass
 
     def update(self, repo, revgen):
         """Given a branchhead cache, self, that may have extra nodes or be
         missing heads, and a generator of nodes that are strictly a superset of
         heads missing, this function updates self to be correct.
         """
+        starttime = time.time()
         cl = repo.changelog
         # collect new branch entries
         newbranches = {}
         getbranchinfo = cl.branchinfo
         for r in revgen:
             branch, closesbranch = getbranchinfo(r)
             newbranches.setdefault(branch, []).append(r)
             if closesbranch:
@@ -267,8 +274,12 @@  class branchcache(dict):
             self.tipnode = nullid
             self.tiprev = nullrev
             for heads in self.values():
                 tiprev = max(cl.rev(node) for node in heads)
                 if tiprev > self.tiprev:
                     self.tipnode = cl.node(tiprev)
                     self.tiprev = tiprev
         self.filteredhash = self._hashfiltered(repo)
+
+        duration = time.time() - starttime
+        repo.ui.log('branchcache', 'updated %s branch cache in %.2f seconds\n',
+                    repo.filtername, duration)