capture/napatech: 0-pad thread names

Apply zero-padding to Napatech worker threads so alphanumeric sorting
displays workers in proper order.

Set padding for thread names according to stream count:

1-9 streams: no padding, e.g, nt1, nt9
10-99 streams: use padding, e.g, nt01, nt99
100-999 streams: use padding, e.g, nt001, nt099, nt999

This will insure that thread names, when sorted alphanumerically,
maintain thread worker id order.

Issue: 8337
pull/15091/head
Jeff Lucovsky 4 weeks ago committed by Victor Julien
parent e7dc0d885b
commit 448915fb55

@ -132,12 +132,21 @@ static int NapatechRegisterDeviceStreams(void)
num_configured_streams = stream_cnt;
SCLogDebug("Configuring %d Napatech Streams...", stream_cnt);
// We will use zero-padding so the names sort properly alphanumerically
// Note: Napatech stream count is currently limited to 128 and is expected to not
// exceed 3 digits in the future.
// Stream count Example
// 4 nt1, nt4
// 12 nt01, nt04, nt11
// 104 nt001, nt004, nt011, nt103
int width = (stream_cnt >= 100) ? 3 : (stream_cnt >= 10) ? 2 : 0;
for (uint16_t inst = 0; inst < stream_cnt; ++inst) {
char *plive_dev_buf = SCCalloc(1, 9);
if (unlikely(plive_dev_buf == NULL)) {
FatalError("Failed to allocate memory for NAPATECH stream counter.");
}
snprintf(plive_dev_buf, 9, "nt%d", stream_config[inst].stream_id);
snprintf(plive_dev_buf, 9, "nt%0*d", width, stream_config[inst].stream_id);
if (auto_config) {
if (stream_config[inst].is_active) {

Loading…
Cancel
Save