Fossil SCM

Keep track of total network traffic for a sync and report the totals at the end of the sync.

drh 2009-08-12 14:41 trunk
Commit 79be9028ebdac88a1184179704d1a7549162aed4
2 files changed +19 -2 +5 -2
--- src/http_transport.c
+++ src/http_transport.c
@@ -36,23 +36,38 @@
3636
int isOpen; /* True when the transport layer is open */
3737
char *pBuf; /* Buffer used to hold the reply */
3838
int nAlloc; /* Space allocated for transportBuf[] */
3939
int nUsed ; /* Space of transportBuf[] used */
4040
int iCursor; /* Next unread by in transportBuf[] */
41
+ int nSent; /* Number of bytes sent */
42
+ int nRcvd; /* Number of bytes received */
4143
FILE *pFile; /* File I/O for FILE: */
4244
char *zOutFile; /* Name of outbound file for FILE: */
4345
char *zInFile; /* Name of inbound file for FILE: */
4446
} transport = {
45
- 0, 0, 0, 0, 0
47
+ 0, 0, 0, 0, 0, 0, 0
4648
};
4749
4850
/*
4951
** Return the current transport error message.
5052
*/
5153
const char *transport_errmsg(void){
5254
return socket_errmsg();
5355
}
56
+
57
+/*
58
+** Retrieve send/receive counts from the transport layer. If "resetFlag"
59
+** is true, then reset the counts.
60
+*/
61
+void transport_stats(int *pnSent, int *pnRcvd, int resetFlag){
62
+ if( pnSent ) *pnSent = transport.nSent;
63
+ if( pnRcvd ) *pnRcvd = transport.nRcvd;
64
+ if( resetFlag ){
65
+ transport.nSent = 0;
66
+ transport.nRcvd = 0;
67
+ }
68
+}
5469
5570
/*
5671
** Open a connection to the server. The server is defined by the following
5772
** global variables:
5873
**
@@ -120,10 +135,11 @@
120135
** Send content over the wire.
121136
*/
122137
void transport_send(Blob *toSend){
123138
char *z = blob_buffer(toSend);
124139
int n = blob_size(toSend);
140
+ transport.nSent += n;
125141
if( g.urlIsHttps ){
126142
/* TBD */
127143
}else if( g.urlIsFile ){
128144
fwrite(z, 1, n, transport.pFile);
129145
}else{
@@ -202,11 +218,12 @@
202218
}else{
203219
got = socket_receive(0, zBuf, N);
204220
/* printf("received %d of %d bytes\n", got, N); fflush(stdout); */
205221
}
206222
if( got>0 ){
207
- nByte += got;
223
+ nByte += got;
224
+ transport.nRcvd += got;
208225
}
209226
}
210227
return nByte;
211228
}
212229
213230
--- src/http_transport.c
+++ src/http_transport.c
@@ -36,23 +36,38 @@
36 int isOpen; /* True when the transport layer is open */
37 char *pBuf; /* Buffer used to hold the reply */
38 int nAlloc; /* Space allocated for transportBuf[] */
39 int nUsed ; /* Space of transportBuf[] used */
40 int iCursor; /* Next unread by in transportBuf[] */
 
 
41 FILE *pFile; /* File I/O for FILE: */
42 char *zOutFile; /* Name of outbound file for FILE: */
43 char *zInFile; /* Name of inbound file for FILE: */
44 } transport = {
45 0, 0, 0, 0, 0
46 };
47
48 /*
49 ** Return the current transport error message.
50 */
51 const char *transport_errmsg(void){
52 return socket_errmsg();
53 }
 
 
 
 
 
 
 
 
 
 
 
 
 
54
55 /*
56 ** Open a connection to the server. The server is defined by the following
57 ** global variables:
58 **
@@ -120,10 +135,11 @@
120 ** Send content over the wire.
121 */
122 void transport_send(Blob *toSend){
123 char *z = blob_buffer(toSend);
124 int n = blob_size(toSend);
 
125 if( g.urlIsHttps ){
126 /* TBD */
127 }else if( g.urlIsFile ){
128 fwrite(z, 1, n, transport.pFile);
129 }else{
@@ -202,11 +218,12 @@
202 }else{
203 got = socket_receive(0, zBuf, N);
204 /* printf("received %d of %d bytes\n", got, N); fflush(stdout); */
205 }
206 if( got>0 ){
207 nByte += got;
 
208 }
209 }
210 return nByte;
211 }
212
213
--- src/http_transport.c
+++ src/http_transport.c
@@ -36,23 +36,38 @@
36 int isOpen; /* True when the transport layer is open */
37 char *pBuf; /* Buffer used to hold the reply */
38 int nAlloc; /* Space allocated for transportBuf[] */
39 int nUsed ; /* Space of transportBuf[] used */
40 int iCursor; /* Next unread by in transportBuf[] */
41 int nSent; /* Number of bytes sent */
42 int nRcvd; /* Number of bytes received */
43 FILE *pFile; /* File I/O for FILE: */
44 char *zOutFile; /* Name of outbound file for FILE: */
45 char *zInFile; /* Name of inbound file for FILE: */
46 } transport = {
47 0, 0, 0, 0, 0, 0, 0
48 };
49
50 /*
51 ** Return the current transport error message.
52 */
53 const char *transport_errmsg(void){
54 return socket_errmsg();
55 }
56
57 /*
58 ** Retrieve send/receive counts from the transport layer. If "resetFlag"
59 ** is true, then reset the counts.
60 */
61 void transport_stats(int *pnSent, int *pnRcvd, int resetFlag){
62 if( pnSent ) *pnSent = transport.nSent;
63 if( pnRcvd ) *pnRcvd = transport.nRcvd;
64 if( resetFlag ){
65 transport.nSent = 0;
66 transport.nRcvd = 0;
67 }
68 }
69
70 /*
71 ** Open a connection to the server. The server is defined by the following
72 ** global variables:
73 **
@@ -120,10 +135,11 @@
135 ** Send content over the wire.
136 */
137 void transport_send(Blob *toSend){
138 char *z = blob_buffer(toSend);
139 int n = blob_size(toSend);
140 transport.nSent += n;
141 if( g.urlIsHttps ){
142 /* TBD */
143 }else if( g.urlIsFile ){
144 fwrite(z, 1, n, transport.pFile);
145 }else{
@@ -202,11 +218,12 @@
218 }else{
219 got = socket_receive(0, zBuf, N);
220 /* printf("received %d of %d bytes\n", got, N); fflush(stdout); */
221 }
222 if( got>0 ){
223 nByte += got;
224 transport.nRcvd += got;
225 }
226 }
227 return nByte;
228 }
229
230
+5 -2
--- src/xfer.c
+++ src/xfer.c
@@ -862,16 +862,18 @@
862862
int nFileSend = 0;
863863
int origConfigRcvMask; /* Original value of configRcvMask */
864864
int nFileRecv; /* Number of files received */
865865
int mxPhantomReq = 200; /* Max number of phantoms to request per comm */
866866
const char *zCookie; /* Server cookie */
867
+ int nSent, nRcvd; /* Bytes sent and received (after compression) */
867868
Blob send; /* Text we are sending to the server */
868869
Blob recv; /* Reply we got back from the server */
869870
Xfer xfer; /* Transfer data */
870871
const char *zSCode = db_get("server-code", "x");
871872
const char *zPCode = db_get("project-code", 0);
872873
874
+ transport_stats(0, 0, 1);
873875
socket_global_init();
874876
memset(&xfer, 0, sizeof(xfer));
875877
xfer.pIn = &recv;
876878
xfer.pOut = &send;
877879
xfer.mxSend = db_get_int("max-upload", 250000);
@@ -957,15 +959,13 @@
957959
}
958960
configSendMask = 0;
959961
}
960962
961963
/* Append randomness to the end of the message */
962
-#if 1 /* Enable this after all servers have upgraded */
963964
zRandomness = db_text(0, "SELECT hex(randomblob(20))");
964965
blob_appendf(&send, "# %s\n", zRandomness);
965966
free(zRandomness);
966
-#endif
967967
968968
/* Exchange messages with the server */
969969
nFileSend = xfer.nFileSent + xfer.nDeltaSent;
970970
printf(zValueFormat, "Send:",
971971
blob_size(&send), nCard+xfer.nGimmeSent+xfer.nIGotSent,
@@ -1180,10 +1180,13 @@
11801180
*/
11811181
if( xfer.nFileSent+xfer.nDeltaSent>0 ){
11821182
go = 1;
11831183
}
11841184
};
1185
+ transport_stats(&nSent, &nRcvd, 1);
1186
+ printf("Total network traffic: %d bytes sent, %d bytes received\n",
1187
+ nSent, nRcvd);
11851188
transport_close();
11861189
socket_global_shutdown();
11871190
db_multi_exec("DROP TABLE onremote");
11881191
db_end_transaction(0);
11891192
}
11901193
--- src/xfer.c
+++ src/xfer.c
@@ -862,16 +862,18 @@
862 int nFileSend = 0;
863 int origConfigRcvMask; /* Original value of configRcvMask */
864 int nFileRecv; /* Number of files received */
865 int mxPhantomReq = 200; /* Max number of phantoms to request per comm */
866 const char *zCookie; /* Server cookie */
 
867 Blob send; /* Text we are sending to the server */
868 Blob recv; /* Reply we got back from the server */
869 Xfer xfer; /* Transfer data */
870 const char *zSCode = db_get("server-code", "x");
871 const char *zPCode = db_get("project-code", 0);
872
 
873 socket_global_init();
874 memset(&xfer, 0, sizeof(xfer));
875 xfer.pIn = &recv;
876 xfer.pOut = &send;
877 xfer.mxSend = db_get_int("max-upload", 250000);
@@ -957,15 +959,13 @@
957 }
958 configSendMask = 0;
959 }
960
961 /* Append randomness to the end of the message */
962 #if 1 /* Enable this after all servers have upgraded */
963 zRandomness = db_text(0, "SELECT hex(randomblob(20))");
964 blob_appendf(&send, "# %s\n", zRandomness);
965 free(zRandomness);
966 #endif
967
968 /* Exchange messages with the server */
969 nFileSend = xfer.nFileSent + xfer.nDeltaSent;
970 printf(zValueFormat, "Send:",
971 blob_size(&send), nCard+xfer.nGimmeSent+xfer.nIGotSent,
@@ -1180,10 +1180,13 @@
1180 */
1181 if( xfer.nFileSent+xfer.nDeltaSent>0 ){
1182 go = 1;
1183 }
1184 };
 
 
 
1185 transport_close();
1186 socket_global_shutdown();
1187 db_multi_exec("DROP TABLE onremote");
1188 db_end_transaction(0);
1189 }
1190
--- src/xfer.c
+++ src/xfer.c
@@ -862,16 +862,18 @@
862 int nFileSend = 0;
863 int origConfigRcvMask; /* Original value of configRcvMask */
864 int nFileRecv; /* Number of files received */
865 int mxPhantomReq = 200; /* Max number of phantoms to request per comm */
866 const char *zCookie; /* Server cookie */
867 int nSent, nRcvd; /* Bytes sent and received (after compression) */
868 Blob send; /* Text we are sending to the server */
869 Blob recv; /* Reply we got back from the server */
870 Xfer xfer; /* Transfer data */
871 const char *zSCode = db_get("server-code", "x");
872 const char *zPCode = db_get("project-code", 0);
873
874 transport_stats(0, 0, 1);
875 socket_global_init();
876 memset(&xfer, 0, sizeof(xfer));
877 xfer.pIn = &recv;
878 xfer.pOut = &send;
879 xfer.mxSend = db_get_int("max-upload", 250000);
@@ -957,15 +959,13 @@
959 }
960 configSendMask = 0;
961 }
962
963 /* Append randomness to the end of the message */
 
964 zRandomness = db_text(0, "SELECT hex(randomblob(20))");
965 blob_appendf(&send, "# %s\n", zRandomness);
966 free(zRandomness);
 
967
968 /* Exchange messages with the server */
969 nFileSend = xfer.nFileSent + xfer.nDeltaSent;
970 printf(zValueFormat, "Send:",
971 blob_size(&send), nCard+xfer.nGimmeSent+xfer.nIGotSent,
@@ -1180,10 +1180,13 @@
1180 */
1181 if( xfer.nFileSent+xfer.nDeltaSent>0 ){
1182 go = 1;
1183 }
1184 };
1185 transport_stats(&nSent, &nRcvd, 1);
1186 printf("Total network traffic: %d bytes sent, %d bytes received\n",
1187 nSent, nRcvd);
1188 transport_close();
1189 socket_global_shutdown();
1190 db_multi_exec("DROP TABLE onremote");
1191 db_end_transaction(0);
1192 }
1193

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button