()
| 753 | |
| 754 | |
| 755 | def plot_action(): |
| 756 | def xlim_type(value): |
| 757 | try: |
| 758 | newvalue = [float(x) for x in value.split(',')] |
| 759 | except: |
| 760 | raise ArgumentError("'%s' option must contain two numbers separated with a comma" % value) |
| 761 | if len(newvalue) != 2: |
| 762 | raise ArgumentError("'%s' option must contain two numbers separated with a comma" % value) |
| 763 | return newvalue |
| 764 | |
| 765 | desc = """Plots using matplotlib the data file `file.dat` generated |
| 766 | using `mprof run`. If no .dat file is given, it will take the most recent |
| 767 | such file in the current directory.""" |
| 768 | parser = ArgumentParser(usage="mprof plot [options] [file.dat]", description=desc) |
| 769 | parser.add_argument('--version', action='version', version=mp.__version__) |
| 770 | parser.add_argument("--title", "-t", dest="title", default=None, |
| 771 | type=str, action="store", |
| 772 | help="String shown as plot title") |
| 773 | parser.add_argument("--no-function-ts", "-n", dest="no_timestamps", action="store_true", |
| 774 | help="Do not display function timestamps on plot.") |
| 775 | parser.add_argument("--output", "-o", |
| 776 | help="Save plot to file instead of displaying it.") |
| 777 | parser.add_argument("--window", "-w", dest="xlim", type=xlim_type, |
| 778 | help="Plot a time-subset of the data. E.g. to plot between 0 and 20.5 seconds: --window 0,20.5") |
| 779 | parser.add_argument("--flame", "-f", dest="flame_mode", action="store_true", |
| 780 | help="Plot the timestamps as a flame-graph instead of the default brackets") |
| 781 | parser.add_argument("--slope", "-s", dest="slope", action="store_true", |
| 782 | help="Plot a trend line and its numerical slope") |
| 783 | parser.add_argument("--backend", |
| 784 | help="Specify the Matplotlib backend to use") |
| 785 | parser.add_argument("profiles", nargs="*", |
| 786 | help="profiles made by mprof run") |
| 787 | args = parser.parse_args() |
| 788 | |
| 789 | try: |
| 790 | if args.backend is not None: |
| 791 | import matplotlib |
| 792 | matplotlib.use(args.backend) |
| 793 | |
| 794 | import pylab as pl |
| 795 | except ImportError as e: |
| 796 | print("matplotlib is needed for plotting.") |
| 797 | print(e) |
| 798 | sys.exit(1) |
| 799 | pl.ioff() |
| 800 | |
| 801 | filenames = get_profiles(args) |
| 802 | |
| 803 | fig = pl.figure(figsize=(14, 6), dpi=90) |
| 804 | if not args.flame_mode: |
| 805 | ax = fig.add_axes([0.1, 0.1, 0.6, 0.75]) |
| 806 | else: |
| 807 | ax = fig.add_axes([0.1, 0.1, 0.8, 0.8]) |
| 808 | if args.xlim is not None: |
| 809 | pl.xlim(args.xlim[0], args.xlim[1]) |
| 810 | |
| 811 | if len(filenames) > 1 or args.no_timestamps: |
| 812 | timestamps = False |
nothing calls this directly
no test coverage detected