@@ -74,6 +74,7 @@ def __enter__(self):
7474 initally_registered = scorep .instrumenter .get_instrumenter ().get_registered ()
7575 with scorep .instrumenter .disable ():
7676 if (self .user_region_name ):
77+ # The user did specify a region name, so its a user_region
7778 self .module_name = "user"
7879 frame = inspect .currentframe ().f_back
7980 file_name = frame .f_globals .get ('__file__' , None )
@@ -85,46 +86,53 @@ def __enter__(self):
8586
8687 scorep .instrumenter .get_instrumenter ().region_begin (
8788 self .module_name , self .region_name , full_file_name , line_number )
88- elif (callable (self .func )):
89- """
90- looks like the decorator is invoked
91- """
92- if not initally_registered :
93- self .region_name = self .func .__name__
94- self .module_name = self .func .__module__
95- file_name = self .func .__code__ .co_filename
96- line_number = self .func .__code__ .co_firstlineno
97-
98- if file_name is not None :
99- full_file_name = os .path .abspath (file_name )
100- else :
101- full_file_name = "None"
102-
103- scorep .instrumenter .get_instrumenter ().region_begin (
104- self .module_name , self .region_name , full_file_name , line_number )
89+ elif callable (self .func ) and not initally_registered :
90+ # The user did not specify a region name, and it's a callable, so it's a semi instrumented region
91+ self .region_name = self .func .__name__
92+ self .module_name = self .func .__module__
93+ self .code_obj = self .func .__code__
94+ file_name = self .func .__code__ .co_filename
95+ line_number = self .func .__code__ .co_firstlineno
96+
97+ if file_name is not None :
98+ full_file_name = os .path .abspath (file_name )
10599 else :
106- """
107- do not need to decorate a function, when we are registerd. It is instrumented any way.
108- """
109- pass
100+ full_file_name = "None"
101+
102+ scorep .instrumenter .get_instrumenter ().region_begin (
103+ self .module_name , self .region_name , full_file_name , line_number , self .code_obj )
104+ elif callable (self .func ) and initally_registered :
105+ # The user did not specify a region name, and it's a callable, so it's a
106+ # semi instrumented region. However, the instrumenter is active, so there
107+ # is nothing to do.
108+ pass
110109 else :
111- raise RuntimeError ("a region name needs to be specified" )
110+ # The user did not specify a region name, and it's not a callable. So it
111+ # is a context region without a region name. Throw an error.
112+ raise RuntimeError ("A region name needs to be specified." )
112113
113114 return self
114115
115116 def __exit__ (self , exc_type , exc_value , traceback ):
116- if (callable (self .func )
117- and scorep .instrumenter .get_instrumenter ().get_registered ()
118- and not self .user_region_name ):
119- """
120- looks like there is a decorator, we are registered and the name is not specified by the user,
121- so we do not need to do anything. The Instrumentation will take care.
122- """
123- return False
124- else :
117+ initally_registered = scorep .instrumenter .get_instrumenter ().get_registered ()
118+ if self .user_region_name :
119+ # The user did specify a region name, so its a user_region
125120 scorep .instrumenter .get_instrumenter ().region_end (
126121 self .module_name , self .region_name )
127- return False
122+ elif callable (self .func ) and not initally_registered :
123+ # The user did not specify a region name, and it's a callable, so it's a semi instrumented region
124+ scorep .instrumenter .get_instrumenter ().region_end (
125+ self .module_name , self .region_name , self .code_obj )
126+ elif callable (self .func ) and initally_registered :
127+ # The user did not specify a region name, and it's a callable, so it's a
128+ # semi instrumented region. However, the instrumenter is active, so there
129+ # is nothing to do.
130+ pass
131+ else :
132+ # The user did not specify a region name, and it's not a callable. So it
133+ # is a context region without a region name. Throw an error.
134+ raise RuntimeError ("Something wen't wrong. Please do a Bug Report." )
135+ return False
128136
129137
130138def rewind_begin (name , file_name = None , line_number = None ):
0 commit comments