devtools/stresstester.py
changeset 10589 7c23b7de2b8d
parent 8695 358d8bed9626
child 10614 57dfde80df11
equal deleted inserted replaced
10588:fdaa0e4b7eaf 10589:7c23b7de2b8d
    39      Write profiler report into <filename> rather than on stdout
    39      Write profiler report into <filename> rather than on stdout
    40 
    40 
    41 Copyright (c) 2003-2011 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
    41 Copyright (c) 2003-2011 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
    42 http://www.logilab.fr/ -- mailto:contact@logilab.fr
    42 http://www.logilab.fr/ -- mailto:contact@logilab.fr
    43 """
    43 """
       
    44 from __future__ import print_function
    44 
    45 
    45 import os
    46 import os
    46 import sys
    47 import sys
    47 import threading
    48 import threading
    48 import getopt
    49 import getopt
    82                     self._reporter.add_proftime(clock() - start, index)
    83                     self._reporter.add_proftime(clock() - start, index)
    83             times -= 1
    84             times -= 1
    84 
    85 
    85 def usage(status=0):
    86 def usage(status=0):
    86     """print usage string and exit"""
    87     """print usage string and exit"""
    87     print __doc__ % basename(sys.argv[0])
    88     print(__doc__ % basename(sys.argv[0]))
    88     sys.exit(status)
    89     sys.exit(status)
    89 
    90 
    90 
    91 
    91 class ProfileReporter:
    92 class ProfileReporter:
    92     """a profile reporter gathers all profile informations from several
    93     """a profile reporter gathers all profile informations from several
   131     try:
   132     try:
   132         opts, args = getopt.getopt(args, 'hn:t:u:p:P:o:', ['help', 'user=', 'password=',
   133         opts, args = getopt.getopt(args, 'hn:t:u:p:P:o:', ['help', 'user=', 'password=',
   133                                                            'nb-times=', 'nb-threads=',
   134                                                            'nb-times=', 'nb-threads=',
   134                                                            'profile', 'report-output=',])
   135                                                            'profile', 'report-output=',])
   135     except Exception as ex:
   136     except Exception as ex:
   136         print ex
   137         print(ex)
   137         usage(1)
   138         usage(1)
   138     repeat = 100
   139     repeat = 100
   139     threads = 1
   140     threads = 1
   140     user = os.environ.get('USER', os.environ.get('LOGNAME'))
   141     user = os.environ.get('USER', os.environ.get('LOGNAME'))
   141     password = None
   142     password = None
   164     if password is None:
   165     if password is None:
   165         password = getpass('password: ')
   166         password = getpass('password: ')
   166     from cubicweb.cwconfig import instance_configuration
   167     from cubicweb.cwconfig import instance_configuration
   167     config = instance_configuration(args[0])
   168     config = instance_configuration(args[0])
   168     # get local access to the repository
   169     # get local access to the repository
   169     print "Creating repo", prof_file
   170     print("Creating repo", prof_file)
   170     repo = Repository(config, prof_file)
   171     repo = Repository(config, prof_file)
   171     cnxid = repo.connect(user, password=password)
   172     cnxid = repo.connect(user, password=password)
   172     # connection to the CubicWeb repository
   173     # connection to the CubicWeb repository
   173     repo_cnx = Connection(repo, cnxid)
   174     repo_cnx = Connection(repo, cnxid)
   174     repo_cursor = repo_cnx.cursor()
   175     repo_cursor = repo_cnx.cursor()