@@ -587,6 +587,7 @@ public:
587
587
KeepTranParams = true;
588
588
TranParams->assign(DEFAULT_DML_TRANS_SQL);
589
589
PerTableStats = false;
590
+ WireStats = false;
590
591
}
591
592
592
593
ColList global_Cols;
@@ -611,6 +612,7 @@ public:
611
612
SCHAR ISQL_charset[MAXCHARSET_SIZE];
612
613
bool KeepTranParams;
613
614
bool PerTableStats;
615
+ bool WireStats;
614
616
};
615
617
616
618
static SetValues setValues;
@@ -5381,7 +5383,7 @@ static processing_state frontend_set(const char* cmd, const char* const* parms,
5381
5383
exec_path_display,
5382
5384
sql, warning, sqlCont, heading, bail,
5383
5385
bulk_insert, maxrows, stmtTimeout,
5384
- keepTranParams, perTableStats,
5386
+ keepTranParams, perTableStats, wireStats,
5385
5387
wrong
5386
5388
};
5387
5389
SetOptions(const optionsMap* inmap, size_t insize, int wrongval)
@@ -5422,7 +5424,8 @@ static processing_state frontend_set(const char* cmd, const char* const* parms,
5422
5424
{SetOptions::stmtTimeout, "LOCAL_TIMEOUT", 0},
5423
5425
{SetOptions::sqlCont, "DECFLOAT", 0},
5424
5426
{SetOptions::keepTranParams, "KEEP_TRAN_PARAMS", 9},
5425
- {SetOptions::perTableStats, "PER_TABLE_STATS", 7}
5427
+ {SetOptions::perTableStats, "PER_TABLE_STATS", 7},
5428
+ {SetOptions::wireStats, "WIRE_STATS", 4}
5426
5429
};
5427
5430
5428
5431
// Display current set options
@@ -5662,6 +5665,10 @@ static processing_state frontend_set(const char* cmd, const char* const* parms,
5662
5665
ret = do_set_command(parms[2], &setValues.PerTableStats);
5663
5666
break;
5664
5667
5668
+ case SetOptions::wireStats:
5669
+ ret = do_set_command(parms[2], &setValues.WireStats);
5670
+ break;
5671
+
5665
5672
default:
5666
5673
//{
5667
5674
// TEXT msg_string[MSG_LENGTH];
@@ -6452,6 +6459,7 @@ static processing_state print_sets()
6452
6459
6453
6460
print_set("Print statistics:", setValues.Stats);
6454
6461
print_set("Print per-table stats:", setValues.PerTableStats);
6462
+ print_set("Print wire stats:", setValues.WireStats);
6455
6463
print_set("Echo commands:", setValues.Echo);
6456
6464
print_set("List format:", setValues.List);
6457
6465
print_set("Show Row Count:", setValues.Docount);
@@ -9004,6 +9012,10 @@ static processing_state process_statement(const TEXT* str2)
9004
9012
if (setValues.PerTableStats)
9005
9013
perTableStats->getStats(DB, true);
9006
9014
9015
+ IsqlWireStats wireStats(DB);
9016
+ if (setValues.WireStats)
9017
+ wireStats.get(true);
9018
+
9007
9019
// Prepare the dynamic query stored in string.
9008
9020
// But put this on the DDL transaction to get maximum visibility of
9009
9021
// metadata.
@@ -9172,6 +9184,9 @@ static processing_state process_statement(const TEXT* str2)
9172
9184
if (setValues.PerTableStats)
9173
9185
perTableStats->getStats(DB, false);
9174
9186
9187
+ if (setValues.WireStats)
9188
+ wireStats.print(false);
9189
+
9175
9190
return ret;
9176
9191
}
9177
9192
@@ -9191,6 +9206,9 @@ static processing_state process_statement(const TEXT* str2)
9191
9206
if (setValues.PerTableStats)
9192
9207
perTableStats->getStats(DB, false);
9193
9208
9209
+ if (setValues.WireStats)
9210
+ wireStats.print(false);
9211
+
9194
9212
return ret;
9195
9213
}
9196
9214
@@ -9238,6 +9256,9 @@ static processing_state process_statement(const TEXT* str2)
9238
9256
if (setValues.PerTableStats)
9239
9257
perTableStats->getStats(DB, false);
9240
9258
9259
+ if (setValues.WireStats)
9260
+ wireStats.print(false);
9261
+
9241
9262
return ret;
9242
9263
}
9243
9264
@@ -9433,6 +9454,9 @@ static processing_state process_statement(const TEXT* str2)
9433
9454
if (setValues.PerTableStats)
9434
9455
perTableStats->getStats(DB, false);
9435
9456
9457
+ if (setValues.WireStats)
9458
+ wireStats.print(false);
9459
+
9436
9460
if (pad)
9437
9461
ISQL_FREE(pad);
9438
9462
if (line)
@@ -9930,3 +9954,112 @@ unsigned PerTableStats::loadRelNames(Firebird::IAttachment* att)
9930
9954
9931
9955
return maxLen;
9932
9956
}
9957
+
9958
+ /// class IsqlWireStats
9959
+
9960
+ bool IsqlWireStats::get(bool initial)
9961
+ {
9962
+ if (!m_att)
9963
+ return false;
9964
+
9965
+ const UCHAR info[] = {
9966
+ fb_info_wire_snd_packets, fb_info_wire_rcv_packets,
9967
+ fb_info_wire_out_packets, fb_info_wire_in_packets,
9968
+ fb_info_wire_snd_bytes, fb_info_wire_rcv_bytes,
9969
+ fb_info_wire_out_bytes, fb_info_wire_in_bytes,
9970
+ fb_info_wire_roundtrips,
9971
+ isc_info_end
9972
+ };
9973
+
9974
+ UCHAR buffer[128];
9975
+
9976
+ m_att->getInfo(fbStatus, sizeof(info), info, sizeof(buffer), buffer);
9977
+
9978
+ if (fbStatus->getState() & Firebird::IStatus::STATE_ERRORS)
9979
+ return false;
9980
+
9981
+ Firebird::ClumpletReader p(Firebird::ClumpletReader::InfoResponse, buffer, sizeof(buffer));
9982
+ for (; !p.isEof(); p.moveNext())
9983
+ {
9984
+ FB_UINT64* pField = nullptr;
9985
+ switch (p.getClumpTag())
9986
+ {
9987
+ case fb_info_wire_snd_packets:
9988
+ pField = &m_snd_packets;
9989
+ break;
9990
+ case fb_info_wire_rcv_packets:
9991
+ pField = &m_rcv_packets;
9992
+ break;
9993
+ case fb_info_wire_out_packets:
9994
+ pField = &m_out_packets;
9995
+ break;
9996
+ case fb_info_wire_in_packets:
9997
+ pField = &m_in_packets;
9998
+ break;
9999
+ case fb_info_wire_snd_bytes:
10000
+ pField = &m_snd_bytes;
10001
+ break;
10002
+ case fb_info_wire_rcv_bytes:
10003
+ pField = &m_rcv_bytes;
10004
+ break;
10005
+ case fb_info_wire_out_bytes:
10006
+ pField = &m_out_bytes;
10007
+ break;
10008
+ case fb_info_wire_in_bytes:
10009
+ pField = &m_in_bytes;
10010
+ break;
10011
+ case fb_info_wire_roundtrips:
10012
+ pField = &m_roundtrips;
10013
+ break;
10014
+ case isc_info_end:
10015
+ break;
10016
+ case isc_info_error:
10017
+ // don't return false here, as we not put error into status
10018
+ return true;
10019
+ /* uncomment to show error (isc_infunk) instead
10020
+ {
10021
+ ISC_STATUS errs[3] = { isc_arg_gds, 0, isc_arg_end };
10022
+ auto b = p.getBytes();
10023
+ errs[1] = isc_portable_integer(b + 1, p.getClumpLength() - 1);
10024
+ fbStatus->setErrors(errs);
10025
+ return false;
10026
+ }*/
10027
+
10028
+ default:
10029
+ fb_assert(false);
10030
+ break;
10031
+ }
10032
+
10033
+ if (pField)
10034
+ {
10035
+ const FB_UINT64 val = p.getBigInt();
10036
+ *pField = initial ? val : val - *pField;
10037
+ }
10038
+ }
10039
+
10040
+ return true;
10041
+ }
10042
+
10043
+ bool IsqlWireStats::print(bool initial)
10044
+ {
10045
+ if (!get(initial))
10046
+ {
10047
+ ISQL_errmsg(fbStatus);
10048
+ return false;
10049
+ }
10050
+
10051
+ IUTILS_printf2(Diag, "Wire logical statistics:%s", NEWLINE);
10052
+ IUTILS_printf2(Diag, " send packets = %8" SQUADFORMAT "%s", m_out_packets, NEWLINE);
10053
+ IUTILS_printf2(Diag, " recv packets = %8" SQUADFORMAT "%s", m_in_packets, NEWLINE);
10054
+ IUTILS_printf2(Diag, " send bytes = %8" SQUADFORMAT "%s", m_out_bytes, NEWLINE);
10055
+ IUTILS_printf2(Diag, " recv bytes = %8" SQUADFORMAT "%s", m_in_bytes, NEWLINE);
10056
+
10057
+ IUTILS_printf2(Diag, "Wire physical statistics:%s", NEWLINE);
10058
+ IUTILS_printf2(Diag, " send packets = %8" SQUADFORMAT "%s", m_snd_packets, NEWLINE);
10059
+ IUTILS_printf2(Diag, " recv packets = %8" SQUADFORMAT "%s", m_rcv_packets, NEWLINE);
10060
+ IUTILS_printf2(Diag, " send bytes = %8" SQUADFORMAT "%s", m_snd_bytes, NEWLINE);
10061
+ IUTILS_printf2(Diag, " recv bytes = %8" SQUADFORMAT "%s", m_rcv_bytes, NEWLINE);
10062
+ IUTILS_printf2(Diag, " roundtrips = %8" SQUADFORMAT "%s", m_roundtrips, NEWLINE);
10063
+
10064
+ return true;
10065
+ }
0 commit comments