Commits

Remi Meier  committed fa95d03

stm: add a pdf compress option to plot_log.py

  • Participants
  • Parent commits 5cf3aa2
  • Branches stm-logging

Comments (0)

Files changed (1)

File pypy/tool/plot_log.py

 """ TODO: print thread-descriptor info on commit/abort """
 ##########################################################
 
-import matplotlib
+import matplotlib, os
 matplotlib.use('gtkagg')
 
+
 args = None
 import matplotlib.pyplot as plt
 # import pprint - slow as hell
                         bbox_inches='tight')
         else:
             plt.savefig(args.pdf, format='pdf', bbox_inches='tight')
+            
+        if args.compress:
+            try:
+                splitted = args.pdf.split(".")
+                if len(splitted) > 1:
+                    splitted[-2] += "_comp"
+                else:
+                    splitted[0] += "_comp"
+                outfile = ".".join(splitted)
+                command = ('gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 '
+                           '-dPDFSETTINGS=/prepress -dNOPAUSE -dQUIET '
+                           '-dBATCH -sOutputFile="%s" "%s"' % (outfile, args.pdf))
+                print command
+                os.system(command)
+            except:
+                print "Could not compress pdf, missing 'gs' command?"
 
 
 if __name__ == "__main__":
                         const=True, default=False,
                         help="also draw the legend")
     parser.add_argument('--pdf', help='write a pdf file instead of showing graph')
+    parser.add_argument('--compress', action='store_const',
+                        const=True, default=False,
+                        help='create _comp version of the pdf')
     parser.add_argument('--title', help='set a title for the graph')