Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyrasite
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
pyrasite
Commits
05b3c47c
Commit
05b3c47c
authored
Feb 14, 2012
by
Luke Macken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Humanize bytes
parent
5769d6a7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
5 deletions
+27
-5
pyrasite/tools/gui.py
pyrasite/tools/gui.py
+5
-5
pyrasite/utils.py
pyrasite/utils.py
+22
-0
No files found.
pyrasite/tools/gui.py
View file @
05b3c47c
...
@@ -33,7 +33,7 @@ from meliae import loader
...
@@ -33,7 +33,7 @@ from meliae import loader
from
gi.repository
import
GLib
,
GObject
,
Pango
,
Gtk
,
WebKit
from
gi.repository
import
GLib
,
GObject
,
Pango
,
Gtk
,
WebKit
import
pyrasite
import
pyrasite
from
pyrasite.utils
import
setup_logger
,
run
from
pyrasite.utils
import
setup_logger
,
run
,
humanize_bytes
log
=
logging
.
getLogger
(
'pyrasite'
)
log
=
logging
.
getLogger
(
'pyrasite'
)
...
@@ -306,12 +306,12 @@ class PyrasiteWindow(Gtk.Window):
...
@@ -306,12 +306,12 @@ class PyrasiteWindow(Gtk.Window):
cpu_user
=
cputimes
.
user
,
cpu_user
=
cputimes
.
user
,
cpu_sys
=
cputimes
.
system
,
cpu_sys
=
cputimes
.
system
,
mem
=
p
.
get_memory_percent
(),
mem
=
p
.
get_memory_percent
(),
mem_rss
=
meminfo
.
rss
,
mem_rss
=
humanize_bytes
(
meminfo
.
rss
)
,
mem_vms
=
meminfo
.
vms
,
mem_vms
=
humanize_bytes
(
meminfo
.
vms
)
,
read_count
=
io
.
read_count
,
read_count
=
io
.
read_count
,
read_bytes
=
io
.
read_bytes
,
read_bytes
=
humanize_bytes
(
io
.
read_bytes
)
,
write_count
=
io
.
write_count
,
write_count
=
io
.
write_count
,
write_bytes
=
io
.
write_bytes
,
write_bytes
=
humanize_bytes
(
io
.
write_bytes
)
,
)
)
open_files
=
p
.
get_open_files
()
open_files
=
p
.
get_open_files
()
...
...
pyrasite/utils.py
View file @
05b3c47c
# http://code.activestate.com/recipes/577081-humanized-representation-of-a-number-of-bytes/
from
__future__
import
division
def
humanize_bytes
(
bytes
,
precision
=
1
):
"""Return a humanized string representation of a number of bytes."""
abbrevs
=
(
(
1
<<
50L
,
'PB'
),
(
1
<<
40L
,
'TB'
),
(
1
<<
30L
,
'GB'
),
(
1
<<
20L
,
'MB'
),
(
1
<<
10L
,
'kB'
),
(
1
,
'bytes'
)
)
if
bytes
==
1
:
return
'1 byte'
for
factor
,
suffix
in
abbrevs
:
if
bytes
>=
factor
:
break
return
'%.*f %s'
%
(
precision
,
bytes
/
factor
,
suffix
)
# Some useful functions based on code from Will Maier's 'ideal Python script'
# Some useful functions based on code from Will Maier's 'ideal Python script'
# https://github.com/wcmaier/python-script
# https://github.com/wcmaier/python-script
#
#
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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