def run_command(self, cmd): """A wrapper to run_command to handle errors""" logger.debug(" ".join(cmd)) response = run_command(cmd, quiet=self.quiet) if not response["return_code"] == 0: logger.exit("Error with %s, %s" % (" ".join(cmd), response["lines"])) return response["lines"]
def _find_metrics(self): """Find metrics based on listing folders under the metrics collection folder. """ # Create a metric lookup dictionary metrics = {} for metric_name in os.listdir(self.metrics_path): metric_dir = os.path.join(self.metrics_path, metric_name) metric_file = os.path.join(metric_dir, "metric.py") # Skip files in collection folder if os.path.isfile(metric_dir): continue # Continue if the file doesn't exist if not os.path.exists(metric_file): logger.debug( "%s does not appear to have a metric.py, skipping." % metric_dir) continue # The class name means we split by underscore, capitalize, and join class_name = "".join( [x.capitalize() for x in metric_name.split("_")]) metrics[ metric_name] = "caliper.metrics.collection.%s.metric.%s" % ( metric_name, class_name, ) return metrics
def __init__(self, workers=None, show_progress=True): # Set a conservative number of workers self.workers = workers or int(multiprocessing.cpu_count() / 2) - 1 logger.debug("Using %s workers for multiprocess." % self.workers) self.tasks = {} self.show_progress = show_progress
def _extract(self, commit): # We will return the lookup lookup = {} # Add the temporary directory to the PYTHONPATH sys.path.insert(0, self.git.folder) # Keep track of counts count = 0 issue_count = 0 for filename in recursive_find(self.git.folder, "*.py"): # Skip files that aren't a module dirname = os.path.dirname(filename) if not os.path.exists(os.path.join(dirname, "__init__.py")): continue # The module path is needed for a script calling the function count += 1 modulepath = ".".join( os.path.dirname(filename).replace(self.git.folder, "").strip("/").split("/")) # Remove purelib or platlib # https://www.python.org/dev/peps/pep-0427/#what-s-the-deal-with-purelib-vs-platlib modulepath = re.sub("^(purelib|platlib)[.]", "", modulepath) # Ignore any scripts that ast cannot parse try: lookup = add_functions(filename, modulepath, lookup) except: logger.debug("Issue parsing %s, skipping" % filename) issue_count += 1 pass logger.debug("Successfully parsed %s files. %s were skipped." % (count, issue_count)) return lookup
def end(self): self.end_time = time.time() self.runtime = self.runtime = self.end_time - self.start_time logger.debug("Ending analysis workers, runtime: %s sec" % (self.runtime))
def start(self): logger.debug("Starting analysis workers!") self.start_time = time.time()