Rev 25: Get rid of struct dependancy, no need for such a hammer. in http://code.launchpad.net/%7Ev-ladeuil/bzr/transportstats
Vincent Ladeuil
v.ladeuil+lp at free.fr
Tue Nov 20 10:34:22 GMT 2007
At http://code.launchpad.net/%7Ev-ladeuil/bzr/transportstats
------------------------------------------------------------
revno: 25
revision-id:v.ladeuil+lp at free.fr-20071120103420-r9wpl2gl0w7u3e20
parent: v.ladeuil+lp at free.fr-20071019165409-9grsgf0uvff2wsuy
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: transportstats
timestamp: Tue 2007-11-20 11:34:20 +0100
message:
Get rid of struct dependancy, no need for such a hammer.
* tests/test_statsfile.py:
(TestsStatsContainer.test_write, TestsStatsContainer.test_read):
Fix typos.
* serialize.py:
Get rid of struct and convert to network byte order manually.
* TODO:
Use coherent syntax.
modified:
TODO todo-20070929082541-nqthugj4zxx7hufy-1
serialize.py serialize.py-20071005112454-5v72oa7pqcdhjytc-1
stats.py stats.py-20070928061304-7i3r2h4gg6rbi03e-1
tests/test_statsfile.py test_tsfile.py-20070929082603-rmpewiprgrp8d4ej-1
-------------- next part --------------
=== modified file 'TODO'
--- a/TODO 2007-10-19 16:54:09 +0000
+++ b/TODO 2007-11-20 10:34:20 +0000
@@ -1,20 +1,20 @@
-- implement missing transport methods in the decorator
-
-* open_write_stream
-
-* readv with protocol specific implementations
-
-* check that the smart protocol is addressed or add the needed methods
-
-- add more tests
-
-- API documentation
-
-- add filtering to ts-display or provide a ts-filter command
-
-* filter by protocol, base, method, etc
-
-- explore how all transports can be transparently decorated
+* implement missing transport methods in the decorator
+
+- open_write_stream
+
+- readv with protocol specific implementations
+
+- check that the smart protocol is addressed or add the needed methods
+
+* add more tests
+
+* API documentation
+
+* add filtering to ts-display or provide a ts-filter command
+
+- filter by protocol, base, method, etc
+
+* explore how all transports can be transparently decorated
* provide a ts-collect command
@@ -33,22 +33,22 @@
That will simplify use for ponctual needs.
-- instrument more objects than transport (repository, branch,
+* instrument more objects than transport (repository, branch,
working-tree) to get bzr fully intrumented (and change the
plugin name to Full Bzr Instrumented (fbi).
-- add statitics to command objects so that the collected stats can be easily
- associated with calling commands (the same should be true for all the
- intermediate levels between commands and transports).
- The plugin could then be viewed as a way to collect network
+* add statitics to command objects (as in cmd_pull, cmd_push etc.) so that the
+ collected stats can be easily associated with calling commands (the same
+ should be true for all the intermediate levels between commands and
+ transports). The plugin could then be viewed as a way to collect network
related statistics and be named Network Statistics Acquisition (nsa).
-- explore how stats could be stored outside of the working tree of the branch
+* explore how stats could be stored outside of the working tree of the branch
where statistics are collected, yet keeping track of the wt revno. A
solution may be store the stats files in an independant branch, collecting
branch and stats file branches being tied by tags.
-- explore backward compatiblity
+* explore backward compatiblity
That will allows production of statistics showing progress from release to
release in terms of volumes, reduction of request numbers, etc.
@@ -59,17 +59,17 @@
There are two main ways:
-* make the implementation decorator use robust signatures
+- make the implementation decorator use robust signatures
By adding *args, **kwargs on all methods
-* provides tagged versions for bzr releases
-
-- exploit statistics for:
-
-* number of files (watch for renames to avoid pollution)
-
-- Implements pack/unpack for formats
+- provides tagged versions for bzr releases
+
+* exploit statistics for:
+
+- number of files (watch for renames to avoid pollution)
+
+* Implements pack/unpack for formats
The aim is to provide a robust, cross-platform, reasonably fast
serialization. 'struct' is used to obtain network-order representtion, a C
@@ -123,7 +123,7 @@
Note: embedding a description for key and/or value may be too
complicated. Users may recursively serialize key/value as strings as needed.
-- change the stats file format to (update and put that in statsfile.py) :
+* change the stats file format to (update and put that in statsfile.py) :
file: header marker sections*
header: %(format)s
=== modified file 'serialize.py'
--- a/serialize.py 2007-10-08 12:16:19 +0000
+++ b/serialize.py 2007-11-20 10:34:20 +0000
@@ -16,8 +16,6 @@
"""Serialize/Deserialize against a file-like object."""
-import struct
-
from bzrlib import registry
from bzrlib.plugins.transportstats import errors
@@ -31,43 +29,51 @@
class UnsignedByte(FormatSpecifier):
def pack(self, f, value):
- f.write(struct.pack('>B', value))
+ f.write(chr(value))
def unpack(self, f):
- (lg,) = struct.unpack('>B', f.read(1))
+ lg = ord(f.read(1))
return lg
class UnsignedShort(FormatSpecifier):
def pack(self, f, value):
- f.write(struct.pack('>H', value))
+ hi = value >> 8
+ lo = value & 0xFF
+ f.write(chr(hi) + chr(lo))
def unpack(self, f):
- (lg,) = struct.unpack('>H', f.read(2))
- return lg
+ s = f.read(2)
+ value = (ord(s[0]) << 8) + ord(s[1])
+ return value
class UnsignedLong(FormatSpecifier):
def pack(self, f, value):
- f.write(struct.pack('>L', value))
+ hihi = value >> 24
+ hilo = value >> 16 & 0xFF
+ lohi = value >> 8 & 0xFF
+ lolo = value & 0xFF
+ f.write(chr(hihi) + chr(hilo) + chr(lohi) + chr(lolo))
def unpack(self, f):
- (lg,) = struct.unpack('>L', f.read(4))
- return lg
+ s = f.read(4)
+ value = ((ord(s[0]) << 24) + (ord(s[1]) << 16)
+ + (ord(s[2]) << 8) + ord(s[3]))
+ return value
class ByteLongString(FormatSpecifier):
def pack(self, f, str):
lg = len(str)
- fmt = '>B%ds' % lg
- f.write(struct.pack(fmt, lg, str))
+ f.write(chr(lg) + str)
def unpack(self, f):
- (lg,) = struct.unpack('>B', f.read(1))
- (str,) = struct.unpack('>%ds' % lg, f.read(lg))
+ lg = ord(f.read(1))
+ str = f.read(lg)
return str
=== modified file 'stats.py'
--- a/stats.py 2007-10-09 08:00:54 +0000
+++ b/stats.py 2007-11-20 10:34:20 +0000
@@ -253,7 +253,7 @@
def get_stats():
"""
- Accesor for the unique Stats object.
+ Accessor for the unique Stats object.
"""
global _stats
=== modified file 'tests/test_statsfile.py'
--- a/tests/test_statsfile.py 2007-10-07 19:52:40 +0000
+++ b/tests/test_statsfile.py 2007-11-20 10:34:20 +0000
@@ -93,10 +93,10 @@
sc.append('bar')
f = StringIO()
sc.write(f)
- self.assertEquals('\x00\002\x03foo\x03bar', f.getvalue())
+ self.assertEquals('\x00\x02\x03foo\x03bar', f.getvalue())
def test_read(self):
- f = StringIO('\x00\03\x05first\x06second\x05third')
+ f = StringIO('\x00\x03\x05first\x06second\x05third')
sc = statsfile.StatsContainer(3)
sc.read(f)
self.assertEquals('first', sc[0])
More information about the bazaar-commits
mailing list