diff -ur postgresql-jdbc-8.4-701.src/org/postgresql/core/BaseConnection.java postgresql-jdbc-8.4-701.src_modified/org/postgresql/core/BaseConnection.java --- postgresql-jdbc-8.4-701.src/org/postgresql/core/BaseConnection.java 2008-04-15 08:23:54.000000000 +0400 +++ postgresql-jdbc-8.4-701.src_modified/org/postgresql/core/BaseConnection.java 2009-12-17 21:47:47.000000000 +0300 @@ -139,4 +139,8 @@ // Get the bind-string-as-varchar config flag public boolean getStringVarcharFlag(); + + public int getRecvdBytes(); + + public int getSentBytes(); } diff -ur postgresql-jdbc-8.4-701.src/org/postgresql/core/PGStream.java postgresql-jdbc-8.4-701.src_modified/org/postgresql/core/PGStream.java --- postgresql-jdbc-8.4-701.src/org/postgresql/core/PGStream.java 2008-01-08 09:56:27.000000000 +0300 +++ postgresql-jdbc-8.4-701.src_modified/org/postgresql/core/PGStream.java 2009-12-17 21:31:00.000000000 +0300 @@ -46,6 +46,8 @@ private Encoding encoding; private Writer encodingWriter; + protected int sentBytes; + protected int recvdBytes; /** * Constructor: Connect to the PostgreSQL back end and return * a stream connection. @@ -56,6 +58,7 @@ */ public PGStream(String host, int port) throws IOException { + sentBytes=recvdBytes=0; this.host = host; this.port = port; @@ -78,6 +81,15 @@ return connection; } + public int getSentBytes() + { + return sentBytes; + } + + public int getRecvdBytes() + { + return recvdBytes; + } /** * Check for pending backend messages without blocking. * Might return false when there actually are messages @@ -172,6 +184,7 @@ public void SendChar(int val) throws IOException { pg_output.write(val); + sentBytes+=1; } /** @@ -187,6 +200,7 @@ _int4buf[2] = (byte)(val >>> 8); _int4buf[3] = (byte)(val); pg_output.write(_int4buf); + sentBytes+=4; } /** @@ -203,6 +217,7 @@ _int2buf[0] = (byte)(val >>> 8); _int2buf[1] = (byte)val; pg_output.write(_int2buf); + sentBytes+=2; } /** @@ -214,6 +229,7 @@ public void Send(byte buf[]) throws IOException { pg_output.write(buf); + sentBytes+=buf.length; } /** @@ -246,6 +262,7 @@ { pg_output.write(0); } + sentBytes+= siz; } /** @@ -259,6 +276,7 @@ int c = pg_input.read(); if (c < 0) throw new EOFException(); + recvdBytes++; return c; } @@ -272,7 +290,7 @@ { if (pg_input.read(_int4buf) != 4) throw new EOFException(); - + recvdBytes+=4; return (_int4buf[0] & 0xFF) << 24 | (_int4buf[1] & 0xFF) << 16 | (_int4buf[2] & 0xFF) << 8 | _int4buf[3] & 0xFF; } @@ -286,7 +304,7 @@ { if (pg_input.read(_int2buf) != 2) throw new EOFException(); - + recvdBytes+=2; return (_int2buf[0] & 0xFF) << 8 | _int2buf[1] & 0xFF; } @@ -304,6 +322,7 @@ String res = encoding.decode(pg_input.getBuffer(), pg_input.getIndex(), len); pg_input.skip(len); + recvdBytes+=len; return res; } @@ -320,6 +339,7 @@ String res = encoding.decode(pg_input.getBuffer(), pg_input.getIndex(), len - 1); pg_input.skip(len); + recvdBytes+=len; return res; } @@ -447,6 +467,7 @@ throw new EOFException(); s += w; } + recvdBytes+=siz; } public void Skip(int size) throws IOException { @@ -454,6 +475,7 @@ while (s < size) { s += pg_input.skip(size - s); } + recvdBytes+=size; } diff -ur postgresql-jdbc-8.4-701.src/org/postgresql/core/ProtocolConnection.java postgresql-jdbc-8.4-701.src_modified/org/postgresql/core/ProtocolConnection.java --- postgresql-jdbc-8.4-701.src/org/postgresql/core/ProtocolConnection.java 2008-01-08 09:56:27.000000000 +0300 +++ postgresql-jdbc-8.4-701.src_modified/org/postgresql/core/ProtocolConnection.java 2009-12-17 21:48:01.000000000 +0300 @@ -132,4 +132,8 @@ * @return the version of the implementation */ public int getProtocolVersion(); + + public int getRecvdBytes(); + + public int getSentBytes(); } diff -ur postgresql-jdbc-8.4-701.src/org/postgresql/core/v2/ProtocolConnectionImpl.java postgresql-jdbc-8.4-701.src_modified/org/postgresql/core/v2/ProtocolConnectionImpl.java --- postgresql-jdbc-8.4-701.src/org/postgresql/core/v2/ProtocolConnectionImpl.java 2008-04-01 11:19:20.000000000 +0400 +++ postgresql-jdbc-8.4-701.src_modified/org/postgresql/core/v2/ProtocolConnectionImpl.java 2009-12-17 21:49:51.000000000 +0300 @@ -218,4 +218,18 @@ private final String database; private final QueryExecutorImpl executor; private final Logger logger; + + public int getRecvdBytes() { + if(pgStream==null) + return 0; + else + return pgStream.getRecvdBytes(); + } + + public int getSentBytes() { + if(pgStream==null) + return 0; + else + return pgStream.getSentBytes(); + } } diff -ur postgresql-jdbc-8.4-701.src/org/postgresql/core/v3/ProtocolConnectionImpl.java postgresql-jdbc-8.4-701.src_modified/org/postgresql/core/v3/ProtocolConnectionImpl.java --- postgresql-jdbc-8.4-701.src/org/postgresql/core/v3/ProtocolConnectionImpl.java 2008-04-01 11:19:20.000000000 +0400 +++ postgresql-jdbc-8.4-701.src_modified/org/postgresql/core/v3/ProtocolConnectionImpl.java 2009-12-17 21:50:21.000000000 +0300 @@ -200,6 +200,20 @@ return 3; } + public int getRecvdBytes() { + if(pgStream==null) + return 0; + else + return pgStream.getRecvdBytes(); + } + + public int getSentBytes() { + if(pgStream==null) + return 0; + else + return pgStream.getSentBytes(); + } + private String serverVersion; private int cancelPid; private int cancelKey; diff -ur postgresql-jdbc-8.4-701.src/org/postgresql/jdbc2/AbstractJdbc2Connection.java postgresql-jdbc-8.4-701.src_modified/org/postgresql/jdbc2/AbstractJdbc2Connection.java --- postgresql-jdbc-8.4-701.src/org/postgresql/jdbc2/AbstractJdbc2Connection.java 2009-07-01 09:00:40.000000000 +0400 +++ postgresql-jdbc-8.4-701.src_modified/org/postgresql/jdbc2/AbstractJdbc2Connection.java 2009-12-17 21:52:26.000000000 +0300 @@ -1068,4 +1068,18 @@ copyManager = new CopyManager(this); return copyManager; } + + public int getRecvdBytes() { + if(protoConnection==null) + return 0; + else + return protoConnection.getRecvdBytes(); + } + + public int getSentBytes() { + if(protoConnection==null) + return 0; + else + return protoConnection.getSentBytes(); + } }