33
44import threading
55import datetime as datetime_module
6+ import marshal
67import abc
78import os .path
89import pstats
1819class BaseProfileHandler (object ):
1920 __metaclass__ = abc .ABCMeta
2021
22+ def __call__ (self , profile ):
23+ self .profile = profile
24+ self .profile_data = marshal .dumps (profile .stats )
25+ return self .handle ()
26+
2127 @abc .abstractmethod
22- def __call__ (self ):
28+ def handle (self ):
2329 pass
2430
2531 default_file_name = caching .CachedProperty (
@@ -32,7 +38,7 @@ class AuxiliaryThreadProfileHandler(BaseProfileHandler):
3238
3339 thread = None
3440
35- def __call__ (self ):
41+ def handle (self ):
3642 self .thread = threading .Thread (target = self .thread_job )
3743 self .thread .start ()
3844
@@ -54,13 +60,13 @@ def __init__(self, email_address, smtp_server, smtp_user, smtp_password,
5460 self .smtp_password = smtp_password
5561 self .use_tls = use_tls
5662
57- def thread_job (self , profile_data ):
63+ def thread_job (self ):
5864 envelope = envelopes .Envelope (
5965 to_addr = self .email_address ,
6066 subject = 'Profile data' ,
6167 )
6268
63- envelope .add_attachment_from_memory (profile_data ,
69+ envelope .add_attachment_from_memory (self . profile_data ,
6470 self .default_file_name ,
6571 'application/octet-stream' )
6672
@@ -75,10 +81,10 @@ class FolderProfileHandler(AuxiliaryThreadProfileHandler):
7581 def __init__ (self , folder_path ):
7682 self .folder_path = folder_path
7783
78- def thread_job (self , profile_data ):
84+ def thread_job (self ):
7985 with open (os .path .join (self .folder_path , self .default_file_name ), \
8086 'wb' ) as output_file :
81- output_file .write (profile_data )
87+ output_file .write (self . profile_data )
8288
8389
8490
@@ -87,9 +93,9 @@ class PrintProfileHandler(BaseProfileHandler):
8793 def __init__ (self , sort_order ):
8894 self .sort_order = sort_order
8995
90- def __call__ (self , profile_data ):
91- pstats . Stats ( self ). strip_dirs (). sort_stats (self .sort_order ). \
92- print_stats ()
96+ def handle (self ):
97+ self . profile . print_stats (self .sort_order )
98+
9399
94100
95101
0 commit comments