revlogstat.py on Windows

Adrian Buehlmann adrian at cadifra.com
Mon Mar 31 16:27:30 CDT 2008


On 31.03.2008 20:33, Patrick Mézard wrote:
> Adrian Buehlmann a écrit :
>> Question from a newbie trying to understand Mercurial source code
>> (just asking for my own learning):
>>
>> As already posted, I fail to run Matt's revlogstat python script:
>> http://selenic.com/pipermail/mercurial/2008-March/018276.html
>>
>> I would like to ask if anyone has an idea what's wrong with my setup.
>>
>> I have (slightly modified):
>>
>> '''
>> #!/usr/bin/python
>>
>> import sys
>> from mercurial import revlog
>>
>> def stat(f):
>>     r = revlog.revlog(open, f)
> 
> Here you want to open the file in binary mode. Just create a function like:
> 
> binopen = lambda fn: open(fn, 'rb')
> 
> and pass it to revlog instead of "open".
> 

Ahhh, works like a charm now. That makes a lot of sense, too. Thanks Patrick!

Many thanks also to Benoit (yes, it hg verifies - I forgot to mention that
in my original post).

Here is the output for 593a598a9377 of mercurial:

> python revlogstat.py .hg/store/00manifest.i
0 453 453 100.00
1000 185808 131249 70.64
2000 415933 244696 58.83
3000 756190 367033 48.54
4000 1044076 490668 47.00
5000 1925727 614546 31.91
6000 3009722 741498 24.64
6415 3306671 802653 24.27

And here is the adjusted complete revlogstat.py that produced
above output:

'''
#!/usr/bin/python

import sys
from mercurial import revlog

def stat(f):
    binopen = lambda fn: open(fn, 'rb')  # needed on Windows
    r = revlog.revlog(binopen, f)
    frags = []
    total = 0
    optimized = 0

    for i in range(r.count()):
        n = r.node(i)
        c = r.length(i)
        total += c
        o = [c]
        for p in r.parentrevs(i):
            if p != -1:
                rd = r.revdiff(p, i)
                d = revlog.compress(rd)
                o.append(len(d[0]) + len(d[1]))
        optimized += min(o)
        if not i % 1000:
            print i, total, optimized, "%5.2f" % (100.0 * optimized/total)

    print i, total, optimized, "%5.2f" % (100.0 * optimized/total)

if __name__ == '__main__':
    f = sys.argv[1]
    stat(f)
'''


More information about the Mercurial mailing list