From: Ben Hutchings <bhutchings@solarflare.com>
To: Bill Fink <billfink@mindspring.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>,
James Cammarata <jimi@sngx.net>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org,
Linux Netdev List <netdev@vger.kernel.org>
Subject: Re: [PATCH] net: add ability to clear stats via ethtool - e1000/pcnet32
Date: Sun, 1 Jun 2008 02:46:22 +0100 [thread overview]
Message-ID: <20080601014620.GG30769@solarflare.com> (raw)
In-Reply-To: <20080531195702.0b879dd1.billfink@mindspring.com>
Bill Fink wrote:
<snip>
> Yes, every individual Linux network administrator can re-create the
> wheel by devising their own scripts, but it makes much more sense
> to me to implement a simple general kernel mechanism once that could
> be used generically, than to have hundreds (or thousands) of Linux
> network administrators each having to do it themselves (perhaps
> multiple times if they have a variety of types of systems and types
> of NICs).
The ethtool interface is pretty generic, even if the names aren't.
Here's some Python code I just knocked up which demonstrates how
to get a set of named stats. It shouldn't be terribly hard to
extend this to saving and subtracting stat sets.
Ben.
import array, fcntl, os, socket, struct
SIOCETHTOOL = 0x8946
ETH_GSTRING_LEN = 32
ETH_SS_STATS = 1
ETHTOOL_GDRVINFO = 0x00000003
ETHTOOL_GSTRINGS = 0x0000001b
ETHTOOL_GSTATS = 0x0000001d
def ethtool(sock, name, buf):
ifreq = struct.pack('16sP', name, buf.buffer_info()[0])
fcntl.ioctl(sock.fileno(), SIOCETHTOOL, ifreq)
def ethtool_gdrvinfo(sock, name):
cmd = struct.pack('=I', ETHTOOL_GDRVINFO)
buf = array.array('c', cmd)
format = '=32s32s32s32s32x12xIIIII'
buf.extend('\0' * struct.calcsize(format))
ethtool(sock, name, buf)
return dict(zip(['driver', 'version', 'fw_version', 'bus_info',
'n_priv_flags', 'n_stats', 'testinfo_len',
'eedump_len', 'regdump_len'],
struct.unpack(format, buf[len(cmd):])))
def ethtool_gstrings(sock, name, string_set, count):
cmd = struct.pack('=II', ETHTOOL_GSTRINGS, string_set)
buf = array.array('c', cmd)
buf.extend('\0' * (4 + count * ETH_GSTRING_LEN))
ethtool(sock, name, buf)
def nth_string(buf, n):
data = buf[12 + n * ETH_GSTRING_LEN : 12 + (n + 1) * ETH_GSTRING_LEN]
return data.tostring().replace('\0', '')
return [nth_string(buf, n) for n in range(count)]
def ethtool_gstats(sock, name, count):
cmd = struct.pack('=I', ETHTOOL_GSTATS)
buf = array.array('c', cmd)
buf.extend('\0' * (4 + count * 8))
ethtool(sock, name, buf)
def nth_stat(buf, n):
data = buf[8 + n * 8 : 8 + (n + 1) * 8]
return struct.unpack('=Q', data)[0]
return [nth_stat(buf, n) for n in range(count)]
if __name__ == '__main__':
import sys
name = sys.argv[1]
sock = socket.socket()
drvinfo = ethtool_gdrvinfo(sock, name)
count = drvinfo['n_stats']
print dict(zip(ethtool_gstrings(sock, name, ETH_SS_STATS, count),
ethtool_gstats(sock, name, count)))
--
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
next prev parent reply other threads:[~2008-06-01 1:47 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-16 15:18 [PATCH updated] net: add ability to clear per-interface network statistics via procfs James Cammarata
2008-05-16 16:20 ` Eric Dumazet
2008-05-16 20:03 ` David Miller
2008-05-17 14:54 ` James Cammarata
2008-05-17 21:41 ` Eric Dumazet
2008-05-17 22:49 ` James Cammarata
2008-05-18 0:31 ` Ben Hutchings
2008-05-18 1:43 ` Patrick McHardy
2008-05-18 5:09 ` James Cammarata
2008-05-18 11:27 ` Ben Hutchings
2008-05-29 1:45 ` [PATCH] net: add ability to clear stats via ethtool - e1000/pcnet32 James Cammarata
2008-05-29 2:08 ` James Cammarata
2008-05-29 5:11 ` Andrew Morton
2008-05-29 12:34 ` James Cammarata
2008-05-29 14:45 ` Alan Cox
2008-05-29 17:15 ` James Cammarata
2008-05-29 20:50 ` David Miller
2008-05-29 21:18 ` James Cammarata
2008-05-30 19:12 ` Bill Fink
2008-05-30 22:14 ` Rick Jones
2008-05-31 1:09 ` Bill Fink
2008-05-31 2:41 ` Stephen Hemminger
2008-05-31 2:41 ` Stephen Hemminger
2008-05-31 4:47 ` Bill Fink
2008-05-31 12:11 ` Alan Cox
2008-05-31 23:57 ` Bill Fink
2008-06-01 1:46 ` Ben Hutchings [this message]
2008-06-01 20:46 ` Bill Fink
2008-06-01 22:29 ` Ben Hutchings
2008-06-02 3:55 ` Bill Fink
2008-06-02 5:39 ` David Miller
2008-06-02 15:41 ` Bill Fink
2008-06-02 4:50 ` Glen Turner
2008-06-02 16:10 ` Bill Fink
2008-06-03 12:28 ` James Cammarata
2008-06-03 12:35 ` Ben Hutchings
2008-06-03 14:46 ` Alan Cox
2008-06-04 3:05 ` James Cammarata
2008-05-29 14:48 ` Chris Friesen
2008-05-16 20:00 ` [PATCH updated] net: add ability to clear per-interface network statistics via procfs David Miller
2008-05-16 20:09 ` Rick Jones
2008-05-17 15:06 ` James Cammarata
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080601014620.GG30769@solarflare.com \
--to=bhutchings@solarflare.com \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=billfink@mindspring.com \
--cc=jimi@sngx.net \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.