Overview
SHA1 Hash: | 79be9028ebdac88a1184179704d1a7549162aed4 |
---|---|
Date: | 2009-08-12 14:41:32 |
User: | drh |
Comment: | Keep track of total network traffic for a sync and report the totals at the end of the sync. |
Timelines: | ancestors | descendants | both | trunk |
Other Links: | files | ZIP archive | manifest |
Tags And Properties
- branch=trunk inherited from [a28c83647d]
- sym-trunk inherited from [a28c83647d]
Changes
[hide diffs]Modified src/http_transport.c from [4a0b5a79aa] to [409df8860f].
@@ -36,22 +36,37 @@ int isOpen; /* True when the transport layer is open */ char *pBuf; /* Buffer used to hold the reply */ int nAlloc; /* Space allocated for transportBuf[] */ int nUsed ; /* Space of transportBuf[] used */ int iCursor; /* Next unread by in transportBuf[] */ + int nSent; /* Number of bytes sent */ + int nRcvd; /* Number of bytes received */ FILE *pFile; /* File I/O for FILE: */ char *zOutFile; /* Name of outbound file for FILE: */ char *zInFile; /* Name of inbound file for FILE: */ } transport = { - 0, 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0 }; /* ** Return the current transport error message. */ const char *transport_errmsg(void){ return socket_errmsg(); +} + +/* +** Retrieve send/receive counts from the transport layer. If "resetFlag" +** is true, then reset the counts. +*/ +void transport_stats(int *pnSent, int *pnRcvd, int resetFlag){ + if( pnSent ) *pnSent = transport.nSent; + if( pnRcvd ) *pnRcvd = transport.nRcvd; + if( resetFlag ){ + transport.nSent = 0; + transport.nRcvd = 0; + } } /* ** Open a connection to the server. The server is defined by the following ** global variables: @@ -120,10 +135,11 @@ ** Send content over the wire. */ void transport_send(Blob *toSend){ char *z = blob_buffer(toSend); int n = blob_size(toSend); + transport.nSent += n; if( g.urlIsHttps ){ /* TBD */ }else if( g.urlIsFile ){ fwrite(z, 1, n, transport.pFile); }else{ @@ -203,10 +219,11 @@ got = socket_receive(0, zBuf, N); /* printf("received %d of %d bytes\n", got, N); fflush(stdout); */ } if( got>0 ){ nByte += got; + transport.nRcvd += got; } } return nByte; }
Modified src/xfer.c from [463e575108] to [bb547deab3].
@@ -862,16 +862,18 @@ int nFileSend = 0; int origConfigRcvMask; /* Original value of configRcvMask */ int nFileRecv; /* Number of files received */ int mxPhantomReq = 200; /* Max number of phantoms to request per comm */ const char *zCookie; /* Server cookie */ + int nSent, nRcvd; /* Bytes sent and received (after compression) */ Blob send; /* Text we are sending to the server */ Blob recv; /* Reply we got back from the server */ Xfer xfer; /* Transfer data */ const char *zSCode = db_get("server-code", "x"); const char *zPCode = db_get("project-code", 0); + transport_stats(0, 0, 1); socket_global_init(); memset(&xfer, 0, sizeof(xfer)); xfer.pIn = &recv; xfer.pOut = &send; xfer.mxSend = db_get_int("max-upload", 250000); @@ -957,15 +959,13 @@ } configSendMask = 0; } /* Append randomness to the end of the message */ -#if 1 /* Enable this after all servers have upgraded */ zRandomness = db_text(0, "SELECT hex(randomblob(20))"); blob_appendf(&send, "# %s\n", zRandomness); free(zRandomness); -#endif /* Exchange messages with the server */ nFileSend = xfer.nFileSent + xfer.nDeltaSent; printf(zValueFormat, "Send:", blob_size(&send), nCard+xfer.nGimmeSent+xfer.nIGotSent, @@ -1180,10 +1180,13 @@ */ if( xfer.nFileSent+xfer.nDeltaSent>0 ){ go = 1; } }; + transport_stats(&nSent, &nRcvd, 1); + printf("Total network traffic: %d bytes sent, %d bytes received\n", + nSent, nRcvd); transport_close(); socket_global_shutdown(); db_multi_exec("DROP TABLE onremote"); db_end_transaction(0); }