~gz/juju-ci-tools/jes_no_upload

« back to all changes in this revision

Viewing changes to jujupy.py

  • Committer: John George
  • Date: 2015-07-29 21:31:26 UTC
  • mfrom: (1048.2.4 juju-timing)
  • Revision ID: john.george@canonical.com-20150729213126-x3ox0extbuifo9zk
Capture duration of juju commands run from EnvJujuClient.juju().

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
from shutil import rmtree
18
18
import subprocess
19
19
import sys
 
20
import time
20
21
import tempfile
21
22
 
22
23
import yaml
233
234
        if juju_home is None:
234
235
            juju_home = get_juju_home()
235
236
        self.juju_home = juju_home
 
237
        self.juju_timings = {}
236
238
 
237
239
    def _shell_environ(self):
238
240
        """Generate a suitable shell environment.
370
372
            call_func = subprocess.check_call
371
373
        else:
372
374
            call_func = subprocess.call
373
 
        return call_func(args, env=env)
 
375
        start_time = time.time()
 
376
        rval = call_func(args, env=env)
 
377
        self.juju_timings.setdefault(args, []).append(
 
378
            (time.time() - start_time))
 
379
        return rval
 
380
 
 
381
    def get_juju_timings(self):
 
382
        stringified_timings = {}
 
383
        for command, timings in self.juju_timings.items():
 
384
            stringified_timings[' '.join(command)] = timings
 
385
        return stringified_timings
374
386
 
375
387
    @contextmanager
376
388
    def juju_async(self, command, args, include_e=True, timeout=None):