@@ -577,6 +577,7 @@ public:
577
577
KeepTranParams = true;
578
578
TranParams->assign(DEFAULT_DML_TRANS_SQL);
579
579
PerTableStats = false;
580
+ WireStats = false;
580
581
ExplainCommand = false;
581
582
}
582
583
@@ -603,6 +604,7 @@ public:
603
604
SCHAR ISQL_charset[MAXCHARSET_SIZE];
604
605
bool KeepTranParams;
605
606
bool PerTableStats;
607
+ bool WireStats;
606
608
bool ExplainCommand;
607
609
};
608
610
@@ -5453,7 +5455,7 @@ static processing_state frontend_set(const char* cmd, const char* const* parms,
5453
5455
exec_path_display,
5454
5456
sql, warning, sqlCont, heading, bail,
5455
5457
bulk_insert, maxrows, stmtTimeout,
5456
- keepTranParams, perTableStats,
5458
+ keepTranParams, perTableStats, wireStats,
5457
5459
wrong
5458
5460
};
5459
5461
SetOptions(const optionsMap* inmap, size_t insize, int wrongval)
@@ -5495,7 +5497,8 @@ static processing_state frontend_set(const char* cmd, const char* const* parms,
5495
5497
{SetOptions::stmtTimeout, "LOCAL_TIMEOUT", 0},
5496
5498
{SetOptions::sqlCont, "DECFLOAT", 0},
5497
5499
{SetOptions::keepTranParams, "KEEP_TRAN_PARAMS", 9},
5498
- {SetOptions::perTableStats, "PER_TABLE_STATS", 7}
5500
+ {SetOptions::perTableStats, "PER_TABLE_STATS", 7},
5501
+ {SetOptions::wireStats, "WIRE_STATS", 4}
5499
5502
};
5500
5503
5501
5504
// Display current set options
@@ -5746,6 +5749,10 @@ static processing_state frontend_set(const char* cmd, const char* const* parms,
5746
5749
ret = do_set_command(parms[2], &setValues.PerTableStats);
5747
5750
break;
5748
5751
5752
+ case SetOptions::wireStats:
5753
+ ret = do_set_command(parms[2], &setValues.WireStats);
5754
+ break;
5755
+
5749
5756
default:
5750
5757
//{
5751
5758
// TEXT msg_string[MSG_LENGTH];
@@ -6372,6 +6379,7 @@ static processing_state print_sets()
6372
6379
6373
6380
print_set("Print statistics:", setValues.Stats);
6374
6381
print_set("Print per-table stats:", setValues.PerTableStats);
6382
+ print_set("Print wire stats:", setValues.WireStats);
6375
6383
print_set("Echo commands:", setValues.Echo);
6376
6384
print_set("List format:", setValues.List);
6377
6385
print_set("Show Row Count:", setValues.Docount);
@@ -8950,6 +8958,10 @@ static processing_state process_statement(const std::string& str)
8950
8958
if (setValues.PerTableStats)
8951
8959
perTableStats->getStats(DB, true);
8952
8960
8961
+ IsqlWireStats wireStats(DB);
8962
+ if (setValues.WireStats)
8963
+ wireStats.get(true);
8964
+
8953
8965
// Prepare the dynamic query stored in string.
8954
8966
// But put this on the DDL transaction to get maximum visibility of
8955
8967
// metadata.
@@ -9137,6 +9149,9 @@ static processing_state process_statement(const std::string& str)
9137
9149
if (setValues.PerTableStats)
9138
9150
perTableStats->getStats(DB, false);
9139
9151
9152
+ if (setValues.WireStats)
9153
+ wireStats.print(false);
9154
+
9140
9155
return ret;
9141
9156
}
9142
9157
@@ -9156,6 +9171,9 @@ static processing_state process_statement(const std::string& str)
9156
9171
if (setValues.PerTableStats)
9157
9172
perTableStats->getStats(DB, false);
9158
9173
9174
+ if (setValues.WireStats)
9175
+ wireStats.print(false);
9176
+
9159
9177
return ret;
9160
9178
}
9161
9179
@@ -9203,6 +9221,9 @@ static processing_state process_statement(const std::string& str)
9203
9221
if (setValues.PerTableStats)
9204
9222
perTableStats->getStats(DB, false);
9205
9223
9224
+ if (setValues.WireStats)
9225
+ wireStats.print(false);
9226
+
9206
9227
return ret;
9207
9228
}
9208
9229
@@ -9398,6 +9419,9 @@ static processing_state process_statement(const std::string& str)
9398
9419
if (setValues.PerTableStats)
9399
9420
perTableStats->getStats(DB, false);
9400
9421
9422
+ if (setValues.WireStats)
9423
+ wireStats.print(false);
9424
+
9401
9425
if (pad)
9402
9426
ISQL_FREE(pad);
9403
9427
if (line)
@@ -9895,3 +9919,112 @@ unsigned PerTableStats::loadRelNames(Firebird::IAttachment* att)
9895
9919
9896
9920
return maxLen;
9897
9921
}
9922
+
9923
+ /// class IsqlWireStats
9924
+
9925
+ bool IsqlWireStats::get(bool initial)
9926
+ {
9927
+ if (!m_att)
9928
+ return false;
9929
+
9930
+ const UCHAR info[] = {
9931
+ fb_info_wire_snd_packets, fb_info_wire_rcv_packets,
9932
+ fb_info_wire_out_packets, fb_info_wire_in_packets,
9933
+ fb_info_wire_snd_bytes, fb_info_wire_rcv_bytes,
9934
+ fb_info_wire_out_bytes, fb_info_wire_in_bytes,
9935
+ fb_info_wire_roundtrips,
9936
+ isc_info_end
9937
+ };
9938
+
9939
+ UCHAR buffer[128];
9940
+
9941
+ m_att->getInfo(fbStatus, sizeof(info), info, sizeof(buffer), buffer);
9942
+
9943
+ if (fbStatus->getState() & Firebird::IStatus::STATE_ERRORS)
9944
+ return false;
9945
+
9946
+ Firebird::ClumpletReader p(Firebird::ClumpletReader::InfoResponse, buffer, sizeof(buffer));
9947
+ for (; !p.isEof(); p.moveNext())
9948
+ {
9949
+ FB_UINT64* pField = nullptr;
9950
+ switch (p.getClumpTag())
9951
+ {
9952
+ case fb_info_wire_snd_packets:
9953
+ pField = &m_snd_packets;
9954
+ break;
9955
+ case fb_info_wire_rcv_packets:
9956
+ pField = &m_rcv_packets;
9957
+ break;
9958
+ case fb_info_wire_out_packets:
9959
+ pField = &m_out_packets;
9960
+ break;
9961
+ case fb_info_wire_in_packets:
9962
+ pField = &m_in_packets;
9963
+ break;
9964
+ case fb_info_wire_snd_bytes:
9965
+ pField = &m_snd_bytes;
9966
+ break;
9967
+ case fb_info_wire_rcv_bytes:
9968
+ pField = &m_rcv_bytes;
9969
+ break;
9970
+ case fb_info_wire_out_bytes:
9971
+ pField = &m_out_bytes;
9972
+ break;
9973
+ case fb_info_wire_in_bytes:
9974
+ pField = &m_in_bytes;
9975
+ break;
9976
+ case fb_info_wire_roundtrips:
9977
+ pField = &m_roundtrips;
9978
+ break;
9979
+ case isc_info_end:
9980
+ break;
9981
+ case isc_info_error:
9982
+ // don't return false here, as we not put error into status
9983
+ return true;
9984
+ /* uncomment to show error (isc_infunk) instead
9985
+ {
9986
+ ISC_STATUS errs[3] = { isc_arg_gds, 0, isc_arg_end };
9987
+ auto b = p.getBytes();
9988
+ errs[1] = isc_portable_integer(b + 1, p.getClumpLength() - 1);
9989
+ fbStatus->setErrors(errs);
9990
+ return false;
9991
+ }*/
9992
+
9993
+ default:
9994
+ fb_assert(false);
9995
+ break;
9996
+ }
9997
+
9998
+ if (pField)
9999
+ {
10000
+ const FB_UINT64 val = p.getBigInt();
10001
+ *pField = initial ? val : val - *pField;
10002
+ }
10003
+ }
10004
+
10005
+ return true;
10006
+ }
10007
+
10008
+ bool IsqlWireStats::print(bool initial)
10009
+ {
10010
+ if (!get(initial))
10011
+ {
10012
+ ISQL_errmsg(fbStatus);
10013
+ return false;
10014
+ }
10015
+
10016
+ IUTILS_printf2(Diag, "Wire logical statistics:%s", NEWLINE);
10017
+ IUTILS_printf2(Diag, " send packets = %8" SQUADFORMAT "%s", m_out_packets, NEWLINE);
10018
+ IUTILS_printf2(Diag, " recv packets = %8" SQUADFORMAT "%s", m_in_packets, NEWLINE);
10019
+ IUTILS_printf2(Diag, " send bytes = %8" SQUADFORMAT "%s", m_out_bytes, NEWLINE);
10020
+ IUTILS_printf2(Diag, " recv bytes = %8" SQUADFORMAT "%s", m_in_bytes, NEWLINE);
10021
+
10022
+ IUTILS_printf2(Diag, "Wire physical statistics:%s", NEWLINE);
10023
+ IUTILS_printf2(Diag, " send packets = %8" SQUADFORMAT "%s", m_snd_packets, NEWLINE);
10024
+ IUTILS_printf2(Diag, " recv packets = %8" SQUADFORMAT "%s", m_rcv_packets, NEWLINE);
10025
+ IUTILS_printf2(Diag, " send bytes = %8" SQUADFORMAT "%s", m_snd_bytes, NEWLINE);
10026
+ IUTILS_printf2(Diag, " recv bytes = %8" SQUADFORMAT "%s", m_rcv_bytes, NEWLINE);
10027
+ IUTILS_printf2(Diag, " roundtrips = %8" SQUADFORMAT "%s", m_roundtrips, NEWLINE);
10028
+
10029
+ return true;
10030
+ }
0 commit comments