-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#540 query and expose the interface speed using comtypes
git-svn-id: https://xpra.org/svn/Xpra/trunk@18790 3bb7dfac-3a0b-4e04-842a-767bc560f471
- Loading branch information
Showing
5 changed files
with
57 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# This file is part of Xpra. | ||
# Copyright (C) 2011-2017 Antoine Martin <[email protected]> | ||
# Copyright (C) 2011-2018 Antoine Martin <[email protected]> | ||
# Copyright (C) 2008, 2009, 2010 Nathaniel Smith <[email protected]> | ||
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any | ||
# later version. See the file COPYING for details. | ||
|
@@ -13,7 +13,7 @@ | |
log = Logger("network", "protocol") | ||
from xpra.net.common import ConnectionClosedException | ||
from xpra.util import envint, envbool, csv | ||
from xpra.os_util import WIN32, PYTHON2 | ||
from xpra.os_util import WIN32, PYTHON2, POSIX | ||
from xpra.platform.features import TCP_OPTIONS, IP_OPTIONS, SOCKET_OPTIONS | ||
|
||
|
||
|
@@ -354,8 +354,12 @@ def do_get_socket_info(self): | |
except: | ||
pass | ||
try: | ||
fd = s.fileno() | ||
info["fileno"] = fd | ||
if POSIX: | ||
fd = s.fileno() | ||
else: | ||
fd = 0 | ||
if fd: | ||
info["fileno"] = fd | ||
from xpra.platform.netdev_query import get_interface_speed | ||
#ie: self.local = ("192.168.1.7", "14500") | ||
if self.local and len(self.local)==2: | ||
|
@@ -364,6 +368,7 @@ def do_get_socket_info(self): | |
#ie: iface = "eth0" | ||
if iface and iface!="lo": | ||
s = get_interface_speed(fd, iface) | ||
log("get_interface_speed(%i, %s)=%s", fd, iface, s) | ||
if s>0: | ||
info["speed"] = s | ||
except: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/usr/bin/env python | ||
# This file is part of Xpra. | ||
# Copyright (C) 2013-2017 Antoine Martin <[email protected]> | ||
# Copyright (C) 2013-2018 Antoine Martin <[email protected]> | ||
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any | ||
# later version. See the file COPYING for details. | ||
|
||
|
@@ -395,6 +395,7 @@ def get_info(): | |
def main(): | ||
from xpra.util import print_nested_dict | ||
from xpra.platform import program_context | ||
from xpra.platform.netdev_query import get_interface_speed | ||
from xpra.log import enable_color, add_debug_category, enable_debug_for | ||
with program_context("Network-Info", "Network Info"): | ||
enable_color() | ||
|
@@ -407,9 +408,14 @@ def main(): | |
print("Network interfaces found:") | ||
for iface in get_interfaces(): | ||
if if_nametoindex: | ||
print("* %s (index=%s)" % (iface.ljust(20), if_nametoindex(iface))) | ||
s = "* %s (index=%s)" % (iface.ljust(20), if_nametoindex(iface)) | ||
else: | ||
print("* %s" % iface) | ||
s = "* %s" % iface | ||
speed = get_interface_speed(0, iface) | ||
if speed>0: | ||
from xpra.simple_stats import std_unit | ||
s += " (speed=%sbps)" % std_unit(speed) | ||
print(s) | ||
|
||
def pver(v): | ||
if type(v) in (tuple, list): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# This file is part of Xpra. | ||
# Copyright (C) 2016-2018 Antoine Martin <[email protected]> | ||
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any | ||
# later version. See the file COPYING for details. | ||
|
||
|
||
import logging | ||
logging.getLogger("comtypes").setLevel(logging.INFO) | ||
|
||
import comtypes #@UnresolvedImport | ||
assert comtypes | ||
from comtypes import client #@UnresolvedImport | ||
|
||
|
||
class QuietenLogging(object): | ||
|
||
def __init__(self, *_args): | ||
self.loggers = [logging.getLogger(x) for x in ("comtypes.client._code_cache", "comtypes.client._generate")] | ||
self.saved_levels = [x.getEffectiveLevel() for x in self.loggers] | ||
self.verbose = getattr(client._generate, "__verbose__", None) | ||
|
||
def __enter__(self): | ||
client._generate.__verbose__ = False | ||
for logger in self.loggers: | ||
logger.setLevel(logging.WARNING) | ||
|
||
def __exit__(self, *_args): | ||
if self.verbose is not None: | ||
client._generate.__verbose__ = self.verbose | ||
for i, logger in enumerate(self.loggers): | ||
logger.setLevel(self.saved_levels[i]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# This file is part of Xpra. | ||
# Copyright (C) 2017 Antoine Martin <[email protected]> | ||
# Copyright (C) 2017-2018 Antoine Martin <[email protected]> | ||
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any | ||
# later version. See the file COPYING for details. | ||
|
||
|
@@ -59,6 +59,8 @@ cdef extern from "sys/ioctl.h": | |
|
||
def get_interface_speed(int sockfd, char *ifname): | ||
""" returns the ethtool speed in bps, or 0 """ | ||
if sockfd==0: | ||
return 0 | ||
cdef ifreq ifr | ||
cdef ethtool_cmd edata | ||
ifr.ifr_ifrn.ifrn_name = ifname | ||
|