blob: eeac989b30b6763c43bf221005dea535de3dc985 [file] [log] [blame]
# Copyright 2016 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Collect network stats from the DUT.
# For now just collect the byte count from the default interface.
from autotest_lib.client.common_lib import utils
def get_network_stats(machine):
dut = hosts.create_target_machine(machine)
# The information is not critical, so ping the DUT first
# and if it doesn't reply quickly, give up.
if, tries=1, timeout=3) != 0:'ping failed: not collecting network stats')
# In a single ssh call, get list of network interfaces
# and their byte counts.
result ='route; echo SEPARATOR; cat /proc/net/dev')
# Split output
lines = result.stdout.splitlines()
separator_index = lines.index('SEPARATOR')
route_lines = lines[:separator_index]
proc_lines = lines[separator_index+1:]
for line in route_lines:
fields = line.split()
# look for default network interface
if fields[0] == 'default':
iface = fields[7]
iface_prefix = iface + ':'
else:'get_network_stats: no default interface')
for line in proc_lines:
fields = line.split()
# Look for the interface in /proc/net/dev.
if fields[0] == iface_prefix:'get_network_stats: %s RXbytes %s TXbytes %s',
network_stats_label, fields[1], fields[9])
else:'get_network_stats: iface %s not in /proc/net/dev',
except Exception as e:'get_network_stats: ignoring exception: %s', e)
job.parallel_simple(get_network_stats, machines)