]> granicus.if.org Git - python/commitdiff
- add a dump_stats() method similar to that of the profile.Profile class
authorFred Drake <fdrake@acm.org>
Wed, 14 May 2003 14:28:09 +0000 (14:28 +0000)
committerFred Drake <fdrake@acm.org>
Wed, 14 May 2003 14:28:09 +0000 (14:28 +0000)
- don't use "file" as the name of local variables

Lib/pstats.py

index 62854a8f0c6026b868bba491a86271d2548c538a..9e202e91bf922a268a35148034ad0c11029533f4 100644 (file)
@@ -158,6 +158,14 @@ class Stats:
             self.stats[func] = add_func_stats(old_func_stat, stat)
         return self
 
+    def dump_stats(self, filename):
+        """Write the profile data to a file we know how to load back."""
+        f = file(filename, 'wb')
+        try:
+            marshal.dump(self.stats, f)
+        finally:
+            f.close()
+
     # list the tuple indices and directions for sorting,
     # along with some printable description
     sort_arg_dict_default = {
@@ -440,8 +448,8 @@ class TupleComp:
 # func_name is a triple (file:string, line:int, name:string)
 
 def func_strip_path(func_name):
-    file, line, name = func_name
-    return os.path.basename(file), line, name
+    filename, line, name = func_name
+    return os.path.basename(filename), line, name
 
 def func_get_function_name(func):
     return func[2]