def wrapped(self, *args, **kwargs): FlameProfiler.updateProfileConfig() if FlameProfiler.isRecordingProfile(): with FlameProfiler.profileCall("[SIG] " + self.getName()): func(self, *args, **kwargs) else: func(self, *args, **kwargs)
def __performEmit(self, *args, **kwargs) -> None: # Quickly make some private references to the collections we need to process. # Although the these fields are always safe to use read and use with regards to threading, # we want to operate on a consistent snapshot of the whole set of fields. # The acquire_timeout is here for debugging / profiling purposes, which might help us figure out why certain # people experience slowdowns. At a certain point this can be removed. copy_successful = False while not copy_successful: with acquire_timeout(self.__lock, 0.5) as acquired: if acquired: functions = self.__functions methods = self.__methods signals = self.__signals copy_successful = True else: Logger.log( "w", "Getting lock for signal [%s] took more than 0.5 seconds, this should not happen!", self) if not FlameProfiler.isRecordingProfile(): # Call handler functions for func in functions: func(*args, **kwargs) # Call handler methods for dest, func in methods: func(dest, *args, **kwargs) # Emit connected signals for signal in signals: signal.emit(*args, **kwargs) else: # Call handler functions for func in functions: with FlameProfiler.profileCall(func.__qualname__): func(*args, **kwargs) # Call handler methods for dest, func in methods: with FlameProfiler.profileCall(func.__qualname__): func(dest, *args, **kwargs) # Emit connected signals for signal in signals: with FlameProfiler.profileCall("[SIG]" + signal.getName()): signal.emit(*args, **kwargs)
def _handleProfile(self): profile_data = FlameProfiler.getProfileData() if profile_data is not None: str_data = profile_data.toJSON(root=True) else: # Empty data str_data = """{ "c": { "callStats": { "stack": [ "[app]", "no data", 0, 10 ], "children": [] } "runTime": 10, "totalSamples": 10 } } """ data = bytes(str_data, encoding="utf8") self.send_response(200) self.send_header("Content-type", "text/json") self.send_header("Content-Length", len(data)) self.end_headers() self.wfile.write(data)
def __init__(self, parent=None): QObject.__init__(self, parent) Extension.__init__(self) if FlameProfiler.enabled(): self.addMenuItem("Start BFG", startBFG) self.addMenuItem("Stop BFG", stopBFG) else: self.addMenuItem("<Profiling not activated>", noOp)
def profileEmit(func): if FlameProfiler.enabled(): @functools.wraps(func) def wrapped(self, *args, **kwargs): FlameProfiler.updateProfileConfig() if FlameProfiler.isRecordingProfile(): with FlameProfiler.profileCall("[SIG] " + self.getName()): func(self, *args, **kwargs) else: func(self, *args, **kwargs) return wrapped else: return func
def profileEmit(function): if FlameProfiler.enabled(): @functools.wraps(function) def wrapped(self, *args, **kwargs): FlameProfiler.updateProfileConfig() if FlameProfiler.isRecordingProfile(): with FlameProfiler.profileCall("[SIG] " + self.getName()): function(self, *args, **kwargs) else: function(self, *args, **kwargs) return wrapped else: return function
def __performEmit(self, *args, **kwargs): # Quickly make some private references to the collections we need to process. # Although the these fields are always safe to use read and use with regards to threading, # we want to operate on a consistent snapshot of the whole set of fields. with self.__lock: functions = self.__functions methods = self.__methods signals = self.__signals if not FlameProfiler.isRecordingProfile(): # Call handler functions for func in functions: func(*args, **kwargs) # Call handler methods for dest, func in methods: func(dest, *args, **kwargs) # Emit connected signals for signal in signals: signal.emit(*args, **kwargs) else: # Call handler functions for func in functions: with FlameProfiler.profileCall(func.__qualname__): func(*args, **kwargs) # Call handler methods for dest, func in methods: with FlameProfiler.profileCall(func.__qualname__): func(dest, *args, **kwargs) # Emit connected signals for signal in signals: with FlameProfiler.profileCall("[SIG]" + signal.getName()): signal.emit(*args, **kwargs)
def do_POST(self): if self.path == "/record": FlameProfiler.clearProfileData() FlameProfiler.startRecordingProfileData() self.send_response(200) self.send_header("Content-type", "text/json") self.send_header("Content-Length", 0) self.end_headers() elif self.path == "/stop": FlameProfiler.stopRecordingProfileData() self.send_response(200) self.send_header("Content-type", "text/json") self.send_header("Content-Length", 0) self.end_headers()
def _recordSignalNames(): return FlameProfiler.enabled()
def run(self): FlameProfiler.clearProfileData() server_address = ('', PORT) self._httpd = HTTPServer(server_address, BFGHandler) webbrowser.open("http://localhost:" + str(PORT)) self._httpd.serve_forever()