Exemple #1
0
 def run_code(self, args: ScaleneArguments, code: str) -> None:
     # Create a temporary file to hold the supplied code.
     tmpfile = tempfile.NamedTemporaryFile(mode="w+",
                                           delete=False,
                                           prefix="scalene_profile_",
                                           suffix=".py")
     tmpfile.write(code)
     tmpfile.close()
     args.cpu_only = True  # full Scalene is not yet working, force to use CPU-only mode
     scalene_profiler.Scalene.run_profiler(args, [tmpfile.name])
Exemple #2
0
 def run_code(self, args: ScaleneArguments, code: str) -> None:
     # Create a file to hold the supplied code.
     # We encode the cell number in the string for later recovery.
     # The length of the history buffer lets us find the most recent string (this one).
     filename = f"<ipython-input-{len(get_ipython().history_manager.input_hist_raw)-1}-profile>"
     # Drop the first line (%%scalene).
     newcode = '\n' + code
     with open(filename, "w+") as tmpfile:
         tmpfile.write(newcode)
     args.cpu_only = True  # full Scalene is not yet working, force to use CPU-only mode
     scalene_profiler.Scalene.run_profiler(args, [filename])