def generate_profile(filename): cProfile.run('setup_random_dict()', filename=f'{filename}.profile') # Convert the .profile -> .dot sh.gprof2dot('-f', 'pstats', '-o', f'{filename}.dot', f'{filename}.profile') # Convert the .dot -> png sh.dot('-T', 'png', f'{filename}.dot', '-o', f'{filename}.png')
def generate_profile(filename): cProfile.run('json.dumps(raw)', filename=f'{filename}.profile') # Convert the .profile -> .dot sh.gprof2dot('-f', 'pstats', '-o', f'{filename}.dot', f'{filename}.profile') # Convert the .dot -> png sh.dot('-T', 'png', f'{filename}.dot', '-o', f'{filename}.png')
def rel(file_format): ''' outputs relational diagram into rel.png ''' try: from sh import dot, cp desc = sadisplay.describe([ User, Role, Reservation, Room, Timeslot, Weekday, reservations_users, reservations_timeslots ]) with open('schema.dot', 'w', encoding='utf-8') as f: f.write(sadisplay.dot(desc)) dot("-T"+file_format, "schema.dot", "-o", "app/static/rel."+file_format) except ImportError as e: print(str(e))
import sh import os import glob files=glob.glob("./*"); for i in files: if(i.count(".dot") > 0): sh.dot("-Tpng", i, _out=i.replace(".dot", ".png")); sh.kde_open(files[0].replace(".dot", ".png"));
# In[7]: # We can also save to a file and render an image filename = 'json_loads' cProfile.run('json.loads(some_json)', filename=f'{filename}.profile') # In[8]: import sh # Convert the .profile -> .dot sh.gprof2dot('-f', 'pstats', '-o', f'{filename}.dot', f'{filename}.profile') # In[9]: # Convert the .dot -> png sh.dot('-T', 'png', f'{filename}.dot', '-o', f'{filename}.png') # ![profiled image](./json_loads.png) # ![profiled image](./json_loads.png) # ## More Python # ### We only want to measure what we care about. # In[10]: import random import sh
import sh import os import glob files = glob.glob("./*") for i in files: if (i.count(".dot") > 0): sh.dot("-Tpng", i, _out=i.replace(".dot", ".png")) sh.kde_open(files[0].replace(".dot", ".png"))
def draw_to_pdf(self, in_path, out_path): """Input a path to a dot file.""" sh.dot(in_path, '-Tpdf', '-o', out_path)