MCPcopy Create free account
hub / github.com/python/cpython / _build_profile

Method _build_profile

Lib/profiling/sampling/gecko_collector.py:726–793  ·  view source on GitHub ↗

Build the complete profile structure in processed format.

(self)

Source from the content-addressed store, hash-verified

724 return schema
725
726 def _build_profile(self):
727 """Build the complete profile structure in processed format."""
728 # Convert thread data to final format
729 threads = []
730
731 for tid, thread_data in self.threads.items():
732 # Update lengths
733 samples = thread_data["samples"]
734 stack_table = thread_data["stackTable"]
735 frame_table = thread_data["frameTable"]
736 func_table = thread_data["funcTable"]
737 resource_table = thread_data["resourceTable"]
738
739 samples["length"] = len(samples["stack"])
740 stack_table["length"] = len(stack_table["frame"])
741 frame_table["length"] = len(frame_table["func"])
742 func_table["length"] = len(func_table["name"])
743 resource_table["length"] = len(resource_table["name"])
744 thread_data["markers"]["length"] = len(thread_data["markers"]["name"])
745
746 # Clean up internal caches
747 del thread_data["_stackCache"]
748 del thread_data["_frameCache"]
749 del thread_data["_funcCache"]
750 del thread_data["_resourceCache"]
751
752 threads.append(thread_data)
753
754 # Main profile structure in processed format
755 profile = {
756 "meta": {
757 "interval": self.interval,
758 "startTime": self.start_time,
759 "abi": platform.machine(),
760 "misc": "Python profiler",
761 "oscpu": platform.machine(),
762 "platform": platform.system(),
763 "processType": PROCESS_TYPE_MAIN,
764 "categories": GECKO_CATEGORIES,
765 "stackwalk": STACKWALK_DISABLED,
766 "toolkit": "",
767 "version": GECKO_FORMAT_VERSION,
768 "preprocessedProfileVersion": GECKO_PREPROCESSED_VERSION,
769 "appBuildID": "",
770 "physicalCPUs": os.cpu_count() or 0,
771 "logicalCPUs": os.cpu_count() or 0,
772 "CPUName": "",
773 "product": "Python",
774 "symbolicated": True,
775 "markerSchema": self._build_marker_schema(),
776 "importedFrom": "Tachyon Sampling Profiler",
777 "extensions": {
778 "id": [],
779 "name": [],
780 "baseURL": [],
781 "length": 0,
782 },
783 },

Calls 4

_build_marker_schemaMethod · 0.95
cpu_countMethod · 0.80
itemsMethod · 0.45
appendMethod · 0.45