From 83996dda13797c0fe9e83384ec9c36add8b5d85d Mon Sep 17 00:00:00 2001 From: Matthew Kent Date: Sun, 9 Aug 2009 15:20:25 -0700 Subject: [PATCH] Add per interface support for tx_queue_len, Linux only. Update the ifconfig example output. --- bindings/SigarWrapper.pm | 5 +++++ bindings/ruby/examples/ifconfig.rb | 3 ++- include/sigar.h | 1 + src/sigar.c | 13 ++++++++++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/bindings/SigarWrapper.pm b/bindings/SigarWrapper.pm index 5801f70e..56793a16 100644 --- a/bindings/SigarWrapper.pm +++ b/bindings/SigarWrapper.pm @@ -1081,6 +1081,11 @@ use vars qw(%classes %cmds); desc => '', plat => 'DFL' }, + { + name => 'tx_queue_len', type => 'Int', + desc => '', + plat => 'L' + }, ], NetInterfaceStat => [ { diff --git a/bindings/ruby/examples/ifconfig.rb b/bindings/ruby/examples/ifconfig.rb index 4443e7ef..d0cf21cd 100644 --- a/bindings/ruby/examples/ifconfig.rb +++ b/bindings/ruby/examples/ifconfig.rb @@ -65,7 +65,8 @@ iflist.each do |ifname| " overruns:" + ifstat.tx_overruns.to_s + " carrier:" + ifstat.tx_carrier.to_s - puts "\t" + "collisions:" + ifstat.tx_collisions.to_s + puts "\t" + "collisions:" + ifstat.tx_collisions.to_s + + " txqueuelen:" + ifconfig.tx_queue_len.to_s rx_bytes = ifstat.rx_bytes tx_bytes = ifstat.tx_bytes diff --git a/include/sigar.h b/include/sigar.h index a09ecebd..0ca85fa5 100644 --- a/include/sigar.h +++ b/include/sigar.h @@ -613,6 +613,7 @@ typedef struct { flags, mtu, metric; + int tx_queue_len; } sigar_net_interface_config_t; SIGAR_DECLARE(int) diff --git a/src/sigar.c b/src/sigar.c index 9ab00450..e0d7623f 100644 --- a/src/sigar.c +++ b/src/sigar.c @@ -1640,7 +1640,18 @@ int sigar_net_interface_config_get(sigar_t *sigar, const char *name, ifconfig->metric = ifr.ifr_metric ? ifr.ifr_metric : 1; } - close(sock); +#if defined(SIOCGIFTXQLEN) + if (!ioctl(sock, SIOCGIFTXQLEN, &ifr)) { + ifconfig->tx_queue_len = ifr.ifr_qlen; + } + else { + ifconfig->tx_queue_len = -1; /* net-tools behaviour */ + } +#else + ifconfig->tx_queue_len = -1; +#endif + + close(sock); /* XXX can we get a better description like win32? */ SIGAR_SSTRCPY(ifconfig->description,