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 131 132 133 134
|
#!/usr/bin/env python3
"""
Copyright 2012 NetApp, Inc. All Rights Reserved,
contribution by Weston Andros Adamson <dros@netapp.com>
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.
"""
import posix
import sys
import os
#import six
from nfsometerlib import trace
from nfsometerlib import options
from nfsometerlib.cmd import *
from nfsometerlib.config import *
from nfsometerlib.workloads import *
from nfsometerlib.report import ReportSet
from nfsometerlib.collection import TraceCollection
def check_idle_before_start(opts):
try:
trace.idle_check(wait=False)
except:
res = cmd('mount | grep " type nfs "',
raiseerrorout=False, raiseerrorcode=False)
mounts = '\n'.join(res[0])
res = cmd('mount | grep " type nfs4 "',
raiseerrorout=False, raiseerrorcode=False)
mounts += '\n'.join(res[0])
if not mounts.strip():
opts.error("NFS client not idle (check /proc/fs/nfsfs/servers)")
else:
opts.error("nfsometer cannot run with any active NFS mounts:\n\n%s" % mounts)
def mode_notes(opts):
collection = TraceCollection(opts.resultdir)
collection.notes_edit()
print('Saved notes for results %s' % (opts.resultdir))
def mode_list(opts):
collection = TraceCollection(opts.resultdir)
print('Result directory \'%s\' contains:\n\n%s' % \
(opts.resultdir, '\n'.join(collection.show_contents(pre=''))))
def mode_workloads(opts):
print("Available workloads:")
print(" %s" % '\n '.join(available_workloads()))
print("Unavailable workloads:")
print(" %s" % '\n '.join(unavailable_workloads()))
def mode_loadgen(opts):
# XXX check idle?
trace.loadgen(opts)
def mode_help(opts):
opts.usage()
def mode_examples(opts):
opts.examples()
def mode_fetch_trace(opts, fetch_only=False):
check_idle_before_start(opts)
collection = TraceCollection(opts.resultdir)
trace.run_traces(collection, opts, fetch_only=fetch_only)
print('')
def mode_report(opts):
collection = TraceCollection(opts.resultdir)
if not collection.empty():
rpt = ReportSet(collection, opts.serial_graph_gen)
rpt.generate_reports()
else:
print("No tracedirs found")
def main():
opts = options.Options()
opts.parse()
if not os.path.isdir(opts.resultdir):
try:
os.mkdir(opts.resultdir)
except:
opts.usage("Can't make result directory: %s" % opts.resultdir)
inform("Using results directory: %s" % opts.resultdir)
if opts.mode == 'list':
mode_list(opts)
elif opts.mode == 'workloads':
mode_workloads(opts)
elif opts.mode == 'notes':
mode_notes(opts)
elif opts.mode == 'loadgen':
mode_loadgen(opts)
elif opts.mode == 'help':
mode_help(opts)
elif opts.mode == 'examples':
mode_examples(opts)
elif opts.mode in ('all', 'fetch', 'trace', 'report'):
if opts.mode in ('all', 'trace', 'fetch'):
fetch_only = False
if opts.mode == 'fetch':
fetch_only = True
mode_fetch_trace(opts, fetch_only=fetch_only)
if opts.mode in ('all', 'report'):
mode_report(opts)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print("\nCancelled by user...\n", file=sys.stderr)
|