cli: add time command

This commit is contained in:
Brandon Heller
2012-05-25 16:34:05 -07:00
parent 6c947bca07
commit f509ae282d
+8
View File
@@ -30,6 +30,7 @@ from cmd import Cmd
from os import isatty from os import isatty
from select import poll, POLLIN from select import poll, POLLIN
import sys import sys
import time
from mininet.log import info, output, error from mininet.log import info, output, error
from mininet.term import makeTerms from mininet.term import makeTerms
@@ -278,6 +279,13 @@ class CLI( Cmd ):
output( '*** ' + sw.name + ' ' + ('-' * 72) + '\n' ) output( '*** ' + sw.name + ' ' + ('-' * 72) + '\n' )
output( sw.dpctl( *args ) ) output( sw.dpctl( *args ) )
def do_time( self, line ):
"Measure time taken for any command in Mininet."
start = time.time()
self.onecmd(line)
elapsed = time.time() - start
self.stdout.write("*** Elapsed time: %0.6f secs\n" % elapsed)
def default( self, line ): def default( self, line ):
"""Called on an input line when the command prefix is not recognized. """Called on an input line when the command prefix is not recognized.
Overridden to run shell commands when a node is the first CLI argument. Overridden to run shell commands when a node is the first CLI argument.