Skip to content

Commit 21dfb33

Browse files
committed
Make Remote provider collect wire statistics.
New info items to query wire stats counters.
1 parent 31a3bdc commit 21dfb33

File tree

8 files changed

+190
-13
lines changed

8 files changed

+190
-13
lines changed

src/include/firebird/impl/inf_pub.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,17 @@ enum db_info_types
178178

179179
fb_info_parallel_workers = 149,
180180

181+
// Wire stats items, implemented by Remote provider only
182+
fb_info_wire_out_packets = 150,
183+
fb_info_wire_in_packets = 151,
184+
fb_info_wire_out_bytes = 152,
185+
fb_info_wire_in_bytes = 153,
186+
fb_info_wire_snd_packets = 154,
187+
fb_info_wire_rcv_packets = 155,
188+
fb_info_wire_snd_bytes = 156,
189+
fb_info_wire_rcv_bytes = 157,
190+
fb_info_wire_roundtrips = 158,
191+
181192
isc_info_db_last_value /* Leave this LAST! */
182193
};
183194

src/include/gen/Firebird.pas

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4496,6 +4496,15 @@ IProfilerStatsImpl = class(IProfilerStats)
44964496
fb_info_username = byte(147);
44974497
fb_info_sqlrole = byte(148);
44984498
fb_info_parallel_workers = byte(149);
4499+
fb_info_wire_out_packets = byte(150);
4500+
fb_info_wire_in_packets = byte(151);
4501+
fb_info_wire_out_bytes = byte(152);
4502+
fb_info_wire_in_bytes = byte(153);
4503+
fb_info_wire_snd_packets = byte(154);
4504+
fb_info_wire_rcv_packets = byte(155);
4505+
fb_info_wire_snd_bytes = byte(156);
4506+
fb_info_wire_rcv_bytes = byte(157);
4507+
fb_info_wire_roundtrips = byte(158);
44994508
fb_info_crypt_encrypted = $01;
45004509
fb_info_crypt_process = $02;
45014510
fb_feature_multi_statements = byte(1);

src/remote/client/interface.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,8 @@ class Attachment final : public RefCntIface<IAttachmentImpl<Attachment, CheckSta
936936
void internalDetach(CheckStatusWrapper* status);
937937
void internalDropDatabase(CheckStatusWrapper* status);
938938
SLONG getSingleInfo(CheckStatusWrapper* status, UCHAR infoItem);
939+
bool getWireStatsInfo(unsigned int item_length, const unsigned char* items,
940+
unsigned int buffer_length, unsigned char* buffer) const;
939941

940942
Rdb* rdb;
941943
const PathName dbPath;
@@ -1966,6 +1968,55 @@ IAttachment* Loopback::createDatabase(CheckStatusWrapper* status, const char* fi
19661968
}
19671969

19681970

1971+
bool Attachment::getWireStatsInfo(unsigned int item_length, const unsigned char* items,
1972+
unsigned int buffer_length, unsigned char* buffer) const
1973+
{
1974+
const rem_port* const port = rdb->rdb_port;
1975+
1976+
UCHAR* ptr = buffer;
1977+
const UCHAR* const end = buffer + buffer_length;
1978+
1979+
for (auto item = items; item < items + item_length; item++)
1980+
{
1981+
switch (*item)
1982+
{
1983+
case fb_info_wire_snd_packets:
1984+
case fb_info_wire_rcv_packets:
1985+
case fb_info_wire_out_packets:
1986+
case fb_info_wire_in_packets:
1987+
case fb_info_wire_snd_bytes:
1988+
case fb_info_wire_rcv_bytes:
1989+
case fb_info_wire_out_bytes:
1990+
case fb_info_wire_in_bytes:
1991+
case fb_info_wire_roundtrips:
1992+
{
1993+
const FB_UINT64 value = port->getStatItem(*item);
1994+
1995+
if (value <= MAX_SLONG)
1996+
ptr = fb_utils::putInfoItemInt(*item, (SLONG) value, ptr, end);
1997+
else
1998+
ptr = fb_utils::putInfoItemInt(*item, value, ptr, end);
1999+
2000+
fb_assert(ptr);
2001+
break;
2002+
}
2003+
2004+
case isc_info_end:
2005+
if (ptr < end)
2006+
*ptr++ = *item;
2007+
2008+
return true;
2009+
2010+
default:
2011+
// Let someone else handle unknown item
2012+
return false;
2013+
}
2014+
}
2015+
2016+
return true;
2017+
}
2018+
2019+
19692020
void Attachment::getInfo(CheckStatusWrapper* status,
19702021
unsigned int item_length, const unsigned char* items,
19712022
unsigned int buffer_length, unsigned char* buffer)
@@ -1994,6 +2045,9 @@ void Attachment::getInfo(CheckStatusWrapper* status,
19942045

19952046
RefMutexGuard portGuard(*port->port_sync, FB_FUNCTION);
19962047

2048+
if (getWireStatsInfo(item_length, items, buffer_length, buffer))
2049+
return;
2050+
19972051
UCHAR* temp_buffer = temp.getBuffer(buffer_length);
19982052

19992053
info(status, rdb, op_info_database, rdb->rdb_id, 0,

src/remote/inet.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3129,8 +3129,7 @@ static bool packet_receive(rem_port* port, UCHAR* buffer, SSHORT buffer_length,
31293129
} // end scope
31303130
#endif
31313131

3132-
port->port_rcv_packets++;
3133-
port->port_rcv_bytes += n;
3132+
port->bumpPhysStats(rem_port::RECEIVE, n);
31343133

31353134
*length = n;
31363135

@@ -3305,9 +3304,7 @@ static bool packet_send( rem_port* port, const SCHAR* buffer, SSHORT buffer_leng
33053304
} // end scope
33063305
#endif
33073306

3308-
port->port_snd_packets++;
3309-
port->port_snd_bytes += buffer_length;
3310-
3307+
port->bumpPhysStats(rem_port::SEND, buffer_length);
33113308
return true;
33123309
}
33133310

src/remote/os/win32/xnet.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,8 +1991,8 @@ static bool_t xnet_read(RemoteXdr* xdrs)
19911991
{
19921992
// Client has written some data for us (server) to read
19931993

1994-
port->port_rcv_packets++;
1995-
port->port_rcv_bytes += xch->xch_length;
1994+
port->bumpPhysStats(rem_port::RECEIVE, xch->xch_length);
1995+
port->bumpLogBytes(rem_port::RECEIVE, xch->xch_length); // XNET not calls REMOTE_inflate
19961996

19971997
xdrs->x_handy = xch->xch_length;
19981998
xdrs->x_private = xdrs->x_base;
@@ -2048,8 +2048,8 @@ static bool_t xnet_write(RemoteXdr* xdrs)
20482048
xch->xch_length = xdrs->x_private - xdrs->x_base;
20492049
if (SetEvent(xcc->xcc_event_send_channel_filled))
20502050
{
2051-
port->port_snd_packets++;
2052-
port->port_snd_bytes += xch->xch_length;
2051+
port->bumpPhysStats(rem_port::SEND, xch->xch_length);
2052+
port->bumpLogBytes(rem_port::SEND, xch->xch_length); // XNET not calls REMOTE_deflate
20532053

20542054
xdrs->x_private = xdrs->x_base;
20552055
xdrs->x_handy = xch->xch_size;

src/remote/protocol.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ bool_t xdr_protocol(RemoteXdr* xdrs, PACKET* p)
303303

304304
const auto port = xdrs->x_public;
305305

306+
if (xdrs->x_op != XDR_FREE)
307+
port->bumpLogPackets(xdrs->x_op == XDR_ENCODE ? rem_port::SEND : rem_port::RECEIVE);
308+
306309
switch (p->p_operation)
307310
{
308311
case op_reject:

src/remote/remote.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,12 @@ bool REMOTE_inflate(rem_port* port, PacketReceive* packet_receive, UCHAR* buffer
14931493
{
14941494
#ifdef WIRE_COMPRESS_SUPPORT
14951495
if (!port->port_compressed)
1496-
return packet_receive(port, buffer, buffer_length, length);
1496+
{
1497+
const bool ret = packet_receive(port, buffer, buffer_length, length);
1498+
if (ret)
1499+
port->bumpLogBytes(rem_port::RECEIVE, *length);
1500+
return ret;
1501+
}
14971502

14981503
z_stream& strm = port->port_recv_stream;
14991504
strm.avail_out = buffer_length;
@@ -1565,16 +1570,22 @@ bool REMOTE_inflate(rem_port* port, PacketReceive* packet_receive, UCHAR* buffer
15651570
fprintf(stderr, "ZLib buffer %s\n", port->port_z_data ? "has data" : "is empty");
15661571
#endif
15671572

1573+
port->bumpLogBytes(rem_port::RECEIVE, *length);
15681574
return true;
15691575
#else
1570-
return packet_receive(port, buffer, buffer_length, length);
1576+
const bool ret = packet_receive(port, buffer, buffer_length, length);
1577+
if (ret)
1578+
port->bumpLogBytes(rem_port::RECEIVE, *length);
1579+
return ret;
15711580
#endif
15721581
}
15731582

15741583
bool REMOTE_deflate(RemoteXdr* xdrs, ProtoWrite* proto_write, PacketSend* packet_send, bool flush)
15751584
{
1576-
#ifdef WIRE_COMPRESS_SUPPORT
15771585
rem_port* port = xdrs->x_public;
1586+
port->bumpLogBytes(rem_port::SEND, xdrs->x_private - xdrs->x_base);
1587+
1588+
#ifdef WIRE_COMPRESS_SUPPORT
15781589
if (!(port->port_compressed && (port->port_flags & PORT_compressed)))
15791590
return proto_write(xdrs);
15801591

src/remote/remote.h

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,10 +1144,100 @@ struct rem_port : public Firebird::GlobalStorage, public Firebird::RefCounted
11441144

11451145
UCharArrayAutoPtr port_buffer;
11461146

1147+
1148+
enum io_direction_t {
1149+
NONE,
1150+
SEND,
1151+
RECEIVE
1152+
};
1153+
1154+
private:
1155+
// packets over physical connection
11471156
FB_UINT64 port_snd_packets;
11481157
FB_UINT64 port_rcv_packets;
1158+
// protocol packets
1159+
FB_UINT64 port_out_packets;
1160+
FB_UINT64 port_in_packets;
1161+
// bytes over physical connection
11491162
FB_UINT64 port_snd_bytes;
11501163
FB_UINT64 port_rcv_bytes;
1164+
// bytes before/after compression
1165+
FB_UINT64 port_out_bytes;
1166+
FB_UINT64 port_in_bytes;
1167+
FB_UINT64 port_roundtrips; // number of changes of IO direction from SEND to RECEIVE
1168+
io_direction_t port_io_direction; // last direction of IO
1169+
1170+
public:
1171+
void bumpPhysStats(io_direction_t direction, ULONG count)
1172+
{
1173+
fb_assert(direction != NONE);
1174+
1175+
if (direction == SEND)
1176+
{
1177+
port_snd_packets++;
1178+
port_snd_bytes += count;
1179+
}
1180+
else
1181+
{
1182+
port_rcv_packets++;
1183+
port_rcv_bytes += count;
1184+
}
1185+
1186+
if (direction != port_io_direction)
1187+
{
1188+
if (port_io_direction != NONE && direction == RECEIVE)
1189+
port_roundtrips++;
1190+
port_io_direction = direction;
1191+
}
1192+
}
1193+
1194+
void bumpLogBytes(io_direction_t direction, ULONG count)
1195+
{
1196+
fb_assert(direction != NONE);
1197+
1198+
if (direction == SEND)
1199+
port_out_bytes += count;
1200+
else
1201+
port_in_bytes += count;
1202+
}
1203+
1204+
void bumpLogPackets(io_direction_t direction)
1205+
{
1206+
fb_assert(direction != NONE);
1207+
1208+
if (direction == SEND)
1209+
port_out_packets++;
1210+
else
1211+
port_in_packets++;
1212+
}
1213+
1214+
FB_UINT64 getStatItem(UCHAR infoItem) const
1215+
{
1216+
switch (infoItem)
1217+
{
1218+
case fb_info_wire_snd_packets:
1219+
return port_snd_packets;
1220+
case fb_info_wire_rcv_packets:
1221+
return port_rcv_packets;
1222+
case fb_info_wire_out_packets:
1223+
return port_out_packets;
1224+
case fb_info_wire_in_packets:
1225+
return port_in_packets;
1226+
case fb_info_wire_snd_bytes:
1227+
return port_snd_bytes;
1228+
case fb_info_wire_rcv_bytes:
1229+
return port_rcv_bytes;
1230+
case fb_info_wire_out_bytes:
1231+
return port_out_bytes;
1232+
case fb_info_wire_in_bytes:
1233+
return port_in_bytes;
1234+
case fb_info_wire_roundtrips:
1235+
return port_roundtrips;
1236+
default:
1237+
return 0;
1238+
}
1239+
}
1240+
11511241

11521242
#ifdef WIRE_COMPRESS_SUPPORT
11531243
z_stream port_send_stream, port_recv_stream;
@@ -1187,7 +1277,9 @@ struct rem_port : public Firebird::GlobalStorage, public Firebird::RefCounted
11871277
port_known_server_keys(getPool()), port_crypt_plugin(NULL),
11881278
port_client_crypt_callback(NULL), port_server_crypt_callback(NULL), port_crypt_name(getPool()),
11891279
port_replicator(NULL), port_buffer(FB_NEW_POOL(getPool()) UCHAR[rpt]),
1190-
port_snd_packets(0), port_rcv_packets(0), port_snd_bytes(0), port_rcv_bytes(0)
1280+
port_snd_packets(0), port_rcv_packets(0), port_out_packets(0), port_in_packets(0),
1281+
port_snd_bytes(0), port_rcv_bytes(0), port_out_bytes(0), port_in_bytes(0),
1282+
port_roundtrips(0), port_io_direction(NONE)
11911283
{
11921284
addRef();
11931285
memset(&port_linger, 0, sizeof port_linger);

0 commit comments

Comments
 (0)