-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathvmguest-stats
executable file
·130 lines (105 loc) · 4.31 KB
/
vmguest-stats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/python
### This program is free software; you can redistribute it and/or
### modify it under the terms of the GNU General Public License
### as published by the Free Software Foundation; either version 2
### of the License, or (at your option) any later version.
###
### This program is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
### GNU General Public License for more details.
###
### You should have received a copy of the GNU General Public License
### along with this program; if not, write to the Free Software
### Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
### Copyright 2013-2014 Dag Wieers <dag@wieers.com>
import vmguestlib
import optparse
import time
__version__ = vmguestlib.__version__
delay = 2
count = -1
parser = optparse.OptionParser(usage='usage: %prog [-a] [-c] [-m] delay count', version='%prog ' + __version__)
parser.add_option( '-a', '--all', action='store_true',
dest='all', help='show all statistics (default)' )
parser.add_option( '-c', '--cpu', action='store_true',
dest='cpu', help='show cpu statistics' )
parser.add_option( '-m', '--mem', action='store_true',
dest='memory', help='show memory statistics' )
(options, args) = parser.parse_args()
try:
if len(args) > 0:
delay = int(args[0])
if len(args) > 1:
count = int(args[1])
except:
parser.error('incorrect argument, try -h for the correct syntax')
if options.all or (not options.cpu and not options.memory):
options.cpu = True
options.memory = True
gl = vmguestlib.VMGuestLib()
gl.UpdateInfo()
if options.cpu:
OldElapsedMs = gl.GetElapsedMs()
OldStolenMs = gl.GetCpuStolenMs()
OldUsedMs = gl.GetCpuUsedMs()
while count == -1 or count > 0:
time.sleep(delay)
gl.UpdateInfo()
print time.asctime()
# TODO: Add clearscreen and bold/underline escape sequences
if options.cpu:
NewElapsedMs = gl.GetElapsedMs()
NewStolenMs = gl.GetCpuStolenMs()
NewUsedMs = gl.GetCpuUsedMs()
# Make sure that if time stands still we don't end up in infinity
if NewElapsedMs == OldElapsedMs:
UsedCpu = 0
StolenCpu = 0
EffectiveMhz = 0
else:
UsedCpu = (NewUsedMs - OldUsedMs) * 100.0 / (NewElapsedMs - OldElapsedMs)
StolenCpu = (NewStolenMs - OldStolenMs) * 100.0 / (NewElapsedMs - OldElapsedMs)
EffectiveMhz = gl.GetHostProcessorSpeed() * (NewUsedMs - OldUsedMs) / (NewElapsedMs - OldElapsedMs)
CpuLimit = gl.GetCpuLimitMHz()
print 'VM Processor'
print ' Processor Time: %.2f %%' % UsedCpu
print ' CPU stolen time: %.2f %%' % StolenCpu
print ' Effective VM Speed: %d MHz' % EffectiveMhz
print ' Host processor speed: %d MHz' % gl.GetHostProcessorSpeed()
print
if CpuLimit == -1 & 0xFFFFFFFF:
print ' Limit: unlimited'
else:
print ' Limit: %d MHz' % gl.GetCpuLimitMHz()
print ' Reservation: %d MHz' % gl.GetCpuReservationMHz()
print ' Shares: %d' % gl.GetCpuShares()
OldElapsedMs = NewElapsedMs
OldStolenMs = NewStolenMs
OldUsedMs = NewUsedMs
if options.cpu and options.memory:
print
if options.memory:
MemLimit = gl.GetMemLimitMB()
print 'VM Memory'
print ' Active: %d MB' % gl.GetMemActiveMB()
print ' Ballooned: %d MB' % gl.GetMemBalloonedMB()
print ' Mapped: %d MB' % gl.GetMemMappedMB()
print ' Overhead: %d MB' % gl.GetMemOverheadMB()
print ' Shared: %d MB' % gl.GetMemSharedMB()
print ' Shared Saved: %d MB' % gl.GetMemSharedSavedMB()
print ' Swapped: %d MB' % gl.GetMemSwappedMB()
print ' Target Size: %d MB' % gl.GetMemTargetSizeMB()
print ' Used: %d MB' % gl.GetMemUsedMB()
print
if MemLimit == -1 & 0xFFFFFFFF:
print ' Limit: unlimited'
else:
print ' Limit: %d MB' % MemLimit
print ' Reservation: %d MB' % gl.GetMemReservationMB()
print ' Shares: %d' % gl.GetMemShares()
print
if count > 0:
count = count - 1
gl.CloseHandle()
# vim:ts=4:sw=4:et