Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CPUnetLOG
CPUnetLOG
Commits
295b31eb
Commit
295b31eb
authored
Oct 07, 2014
by
Mario Hock
Browse files
Copyright and license information
parent
e36c9a61
Changes
7
Hide whitespace changes
Inline
Side-by-side
LICENSE.txt
0 → 100644
View file @
295b31eb
This software project contains source code from multiple copyright holders,
who published their code under different open source licenses.
These licenses are:
- The BSD 2-Clause License
- The BSD 3-Clause License
- The MIT License (MIT)
The full license texts, including the respective copy right holders,
are given below.
================================================================================
Unless otherwise stated the source code of this software has been developed by:
Karlsruhe Institute of Technology
Institute of Telematics
Zirkel 2, 76131 Karlsruhe
Germany
and is licensed under the "BSD 2-Clause License":
--------------------------------------------------------------------------------
Copyright (c) 2014,
Karlsruhe Institute of Technology, Institute of Telematics
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
================================================================================
================================================================================
The software incorporates code from the "psutil" project:
https://github.com/giampaolo/psutil
--------------------------------------------------------------------------------
psutil is distributed under BSD license reproduced below.
Copyright (c) 2009, Giampaolo Rodola'
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the psutil authors nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
================================================================================
================================================================================
Acknowledgment:
The user interface code in the file "curses_display.py" is inspired from and
contains some code primitives found in »bwtop« written by "Mahmoud Adel
<mahmoud.adel2@gmail.com>" and distributed under the MIT license.
For more information about »bwtop« please refer to its project site:
https://github.com/mahmoudadel2/bwtop
================================================================================
__init__.py
View file @
295b31eb
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Copyright (c) 2014,
# Karlsruhe Institute of Technology, Institute of Telematics
#
# This code is provided under the BSD 2-Clause License.
# Please refer to the LICENSE.txt file for further information.
#
# Author: Mario Hock
import
os
import
psutil
import
time
...
...
curses_display.py
View file @
295b31eb
# -*- coding:utf-8 -*-
# Copyright (c) 2014,
# Karlsruhe Institute of Technology, Institute of Telematics
#
# This code is provided under the BSD 2-Clause License.
# Please refer to the LICENSE.txt file for further information.
#
# Author: Mario Hock
#
#
# Acknowledgment:
#
# This code is inspired from and contains some code primitives found in »bwtop«
# written by "Mahmoud Adel <mahmoud.adel2@gmail.com>" and distributed under
# the MIT license.
#
# For more information about »bwtop« please refer to its project site:
# https://github.com/mahmoudadel2/bwtop
'''
Curses display for »cpunetlog«.
This code is inspired and partially copied from »bwtop« written by
"Mahmoud Adel <mahmoud.adel2@gmail.com>" and distributed under the MIT license.
'''
import
curses
import
time
import
helpers
...
...
helpers.py
View file @
295b31eb
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Copyright (c) 2014,
# Karlsruhe Institute of Technology, Institute of Telematics
#
# This code is provided under the BSD 2-Clause License.
# Please refer to the LICENSE.txt file for further information.
#
# Author: Mario Hock
from
collections
import
namedtuple
import
os
import
netifaces
import
operator
_ptime_cpu_perc_nt
=
None
### Copied from »psutil« source code and adapted to calculate percentage on two input values rather than "live"
# see: psutil/__init__.py:1282 (Version: 1.2.1-1ubuntu2)
def
calculate_cpu_times_percent
(
cpu_times_older
,
cpu_times_younger
,
percpu
=
False
):
"""Same as cpu_percent() but provides utilization percentages
for each specific CPU time as is returned by cpu_times().
For instance, on Linux we'll get:
>>> cpu_times_percent()
cpupercent(user=4.8, nice=0.0, system=4.8, idle=90.5, iowait=0.0,
irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
>>>
interval and percpu arguments have the same meaning as in
cpu_percent().
"""
#global _last_cpu_times_2
#global _last_per_cpu_times_2
# blocking = interval is not None and interval > 0.0
WINDOWS
=
os
.
name
==
'nt'
def
calculate
(
t1
,
t2
):
global
_ptime_cpu_perc_nt
nums
=
[]
all_delta
=
sum
(
t2
)
-
sum
(
t1
)
for
field
in
t1
.
_fields
:
field_delta
=
getattr
(
t2
,
field
)
-
getattr
(
t1
,
field
)
try
:
field_perc
=
(
100
*
field_delta
)
/
all_delta
except
ZeroDivisionError
:
field_perc
=
0.0
field_perc
=
round
(
field_perc
,
1
)
if
WINDOWS
:
# XXX
# Work around:
# https://code.google.com/p/psutil/issues/detail?id=392
# CPU times are always supposed to increase over time
# or at least remain the same and that's because time
# cannot go backwards.
# Surprisingly sometimes this might not be the case on
# Windows where 'system' CPU time can be smaller
# compared to the previous call, resulting in corrupted
# percentages (< 0 or > 100).
# I really don't know what to do about that except
# forcing the value to 0 or 100.
if
field_perc
>
100.0
:
field_perc
=
100.0
elif
field_perc
<
0.0
:
field_perc
=
0.0
nums
.
append
(
field_perc
)
if
_ptime_cpu_perc_nt
is
None
:
_ptime_cpu_perc_nt
=
namedtuple
(
'cpupercent'
,
' '
.
join
(
t1
.
_fields
))
return
_ptime_cpu_perc_nt
(
*
nums
)
# system-wide usage
if
not
percpu
:
#if blocking:
#t1 = cpu_times()
#time.sleep(interval)
#else:
#t1 = _last_cpu_times_2
#_last_cpu_times_2 = cpu_times()
#return calculate(t1, _last_cpu_times_2)
return
calculate
(
cpu_times_older
,
cpu_times_younger
)
# per-cpu usage
else
:
ret
=
[]
#if blocking:
#tot1 = cpu_times(percpu=True)
#time.sleep(interval)
#else:
#tot1 = _last_per_cpu_times_2
#_last_per_cpu_times_2 = cpu_times(percpu=True)
for
t1
,
t2
in
zip
(
cpu_times_older
,
cpu_times_younger
):
ret
.
append
(
calculate
(
t1
,
t2
))
return
ret
def
get_nics
():
return
netifaces
.
interfaces
()
...
...
history_store.py
View file @
295b31eb
# -*- coding:utf-8 -*-
# Copyright (c) 2014,
# Karlsruhe Institute of Technology, Institute of Telematics
#
# This code is provided under the BSD 2-Clause License.
# Please refer to the LICENSE.txt file for further information.
#
# Author: Mario Hock
from
collections
import
deque
class
HistoryStore
:
...
...
logging.py
View file @
295b31eb
# -*- coding:utf-8 -*-
# Copyright (c) 2014,
# Karlsruhe Institute of Technology, Institute of Telematics
#
# This code is provided under the BSD 2-Clause License.
# Please refer to the LICENSE.txt file for further information.
#
# Author: Mario Hock
import
json
import
time
import
os
...
...
psutil_functions.py
0 → 100644
View file @
295b31eb
# -*- coding:utf-8 -*-
### This code was originally copied from »psutil« source code and adapted
# to calculate the percentage values on two input values rather than "live".
# see: psutil/__init__.py:1282 (Version: 1.2.1-1ubuntu2)
#
#
# Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
# Use of all psutils code in this file is governed by a BSD-style license that
# can also be found in the LICENSE.txt file.
#
#
# Copyright (c) 2014,
# Karlsruhe Institute of Technology, Institute of Telematics
#
# The modifications are provided under the BSD 2-Clause License.
# Please refer to the LICENSE.txt file for further information.
#
# Author: Mario Hock
_ptime_cpu_perc_nt
=
None
def
calculate_cpu_times_percent
(
cpu_times_older
,
cpu_times_younger
,
percpu
=
False
):
"""Same as cpu_percent() but provides utilization percentages
for each specific CPU time as is returned by cpu_times().
For instance, on Linux we'll get:
>>> cpu_times_percent()
cpupercent(user=4.8, nice=0.0, system=4.8, idle=90.5, iowait=0.0,
irq=0.0, softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
>>>
interval and percpu arguments have the same meaning as in
cpu_percent().
"""
#global _last_cpu_times_2
#global _last_per_cpu_times_2
# blocking = interval is not None and interval > 0.0
WINDOWS
=
os
.
name
==
'nt'
def
calculate
(
t1
,
t2
):
global
_ptime_cpu_perc_nt
nums
=
[]
all_delta
=
sum
(
t2
)
-
sum
(
t1
)
for
field
in
t1
.
_fields
:
field_delta
=
getattr
(
t2
,
field
)
-
getattr
(
t1
,
field
)
try
:
field_perc
=
(
100
*
field_delta
)
/
all_delta
except
ZeroDivisionError
:
field_perc
=
0.0
field_perc
=
round
(
field_perc
,
1
)
if
WINDOWS
:
# XXX
# Work around:
# https://code.google.com/p/psutil/issues/detail?id=392
# CPU times are always supposed to increase over time
# or at least remain the same and that's because time
# cannot go backwards.
# Surprisingly sometimes this might not be the case on
# Windows where 'system' CPU time can be smaller
# compared to the previous call, resulting in corrupted
# percentages (< 0 or > 100).
# I really don't know what to do about that except
# forcing the value to 0 or 100.
if
field_perc
>
100.0
:
field_perc
=
100.0
elif
field_perc
<
0.0
:
field_perc
=
0.0
nums
.
append
(
field_perc
)
if
_ptime_cpu_perc_nt
is
None
:
_ptime_cpu_perc_nt
=
namedtuple
(
'cpupercent'
,
' '
.
join
(
t1
.
_fields
))
return
_ptime_cpu_perc_nt
(
*
nums
)
# system-wide usage
if
not
percpu
:
#if blocking:
#t1 = cpu_times()
#time.sleep(interval)
#else:
#t1 = _last_cpu_times_2
#_last_cpu_times_2 = cpu_times()
#return calculate(t1, _last_cpu_times_2)
return
calculate
(
cpu_times_older
,
cpu_times_younger
)
# per-cpu usage
else
:
ret
=
[]
#if blocking:
#tot1 = cpu_times(percpu=True)
#time.sleep(interval)
#else:
#tot1 = _last_per_cpu_times_2
#_last_per_cpu_times_2 = cpu_times(percpu=True)
for
t1
,
t2
in
zip
(
cpu_times_older
,
cpu_times_younger
):
ret
.
append
(
calculate
(
t1
,
t2
))
return
ret
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment