Esempio n. 1
0
    def reportMemory(self):
        """
        Report on memory usage from this CatalogsZone.
        @returns {dict} memory usage; keys are the paths, values are a dict of
            "amount" -> number
            "units" -> "bytes" | "count"
            "desc" -> str description
        """
        log.debug("CatalogsZone: reporting memory")
        import memutils

        total_mem_usage = 0
        result = {}
        for lang, blob_and_atime_from_blobname in list(
                self._blob_and_atime_from_blobname_from_lang_cache.items()):
            for blobname, [blob, atime
                           ] in list(blob_and_atime_from_blobname.items()):
                result[
                    "explicit/python/codeintel/%s/catalog/%s" %
                    (lang, blobname)] = {
                        "amount":
                        memutils.memusage(blob),
                        "units":
                        "bytes",
                        "desc":
                        "The number of bytes of %s codeintel %s catalog blobs."
                        % (lang, blobname),
                    }
        return result
Esempio n. 2
0
 def reportMemory(self, reporter, closure=None):
     """
     Report on memory usage from this StdLib. See nsIMemoryMultiReporter
     """
     log.debug("%s StdLib %s: reporting memory", self.lang, self.name)
     import memutils
     from xpcom import components
     total_mem_usage = memutils.memusage(self._blob_from_blobname)
     total_mem_usage += memutils.memusage(self._blob_imports_from_prefix_cache)
     reporter.callback("", # process id
                       "explicit/python/codeintel/%s/stdlib/%s" % (self.lang, self.name),
                       components.interfaces.nsIMemoryReporter.KIND_HEAP,
                       components.interfaces.nsIMemoryReporter.UNITS_BYTES,
                       total_mem_usage,
                       "The number of bytes of %s codeintel stdlib %s blobs." % (self.lang, self.name),
                       closure)
     return total_mem_usage
Esempio n. 3
0
 def reportMemory(self):
     """
     Report on memory usage from this StdLib.
     @returns {dict} memory usage; keys are the paths, values are a dict of
         "amount" -> number
         "units" -> "bytes" | "count"
         "desc" -> str description
     """
     log.debug("%s StdLib %s: reporting memory", self.lang, self.name)
     import memutils
     return {
         "explicit/python/codeintel/%s/stdlib/%s" % (self.lang, self.name): {
             "amount": memutils.memusage(self._blob_from_blobname) +
                       memutils.memusage(self._blob_imports_from_prefix_cache),
             "units": "bytes",
             "desc": "The number of bytes of %s codeintel stdlib %s blobs." % (self.lang, self.name),
         }
     }
     return total_mem_usage
Esempio n. 4
0
 def reportMemory(self, reporter, closure=None):
     """
     Report on memory usage from this StdLib. See nsIMemoryMultiReporter
     """
     log.debug("%s StdLib %s: reporting memory", self.lang, self.name)
     import memutils
     from xpcom import components
     total_mem_usage = memutils.memusage(self._blob_from_blobname)
     total_mem_usage += memutils.memusage(
         self._blob_imports_from_prefix_cache)
     reporter.callback(
         "",  # process id
         "explicit/python/codeintel/%s/stdlib/%s" % (self.lang, self.name),
         components.interfaces.nsIMemoryReporter.KIND_HEAP,
         components.interfaces.nsIMemoryReporter.UNITS_BYTES,
         total_mem_usage,
         "The number of bytes of %s codeintel stdlib %s blobs." %
         (self.lang, self.name),
         closure)
     return total_mem_usage
    def _get_memory_report(self, driver):
        import gc
        import memutils
        gc.collect()
        total = memutils.memusage(gc.get_objects())

        def try_call(method):
            try:
                return method()
            except Exception as ex:
                log.exception(ex)
                return None

        results = {}
        for zone in driver.mgr.db.get_all_zones():
            try:
                results.update(zone.reportMemory())
            except:
                log.exception("Failed to report memory for zone %r", zone)

        for path, data in list(results.items()):
            if path.startswith("explicit/python"):
                if data["units"] == "bytes":
                    total -= data["amount"]

        results["explicit/python/unclassified-objects"] = {
            "amount": total,
            "units": "bytes",
            "desc": "Total bytes used by Python objects.",
        }
        results["vsize"] = {
            "amount": try_call(self._get_virtual_size),
            "units": "bytes",
            "desc": "Memory mapped by the code intelligence process.",
        }
        results["resident"] = {
            "amount": try_call(self._get_resident_size),
            "units": "bytes",
            "desc": "Resident set size in the code intelligence process.",
        }
        results["heap-allocated"] = {
            "amount": try_call(self._get_heap_size),
            "units": "bytes",
            "desc": "The total size of the heap."
        }

        return results
Esempio n. 6
0
    def _get_memory_report(self, driver):
        import gc
        import memutils
        gc.collect()
        total = memutils.memusage(gc.get_objects())

        def try_call(method):
            try:
                return method()
            except Exception as ex:
                log.exception(ex)
                return None

        results = {}
        for zone in driver.mgr.db.get_all_zones():
            try:
                results.update(zone.reportMemory())
            except:
                log.exception("Failed to report memory for zone %r", zone)

        for path, data in results.items():
            if path.startswith("explicit/python"):
                if data["units"] == "bytes":
                    total -= data["amount"]

        results["explicit/python/unclassified-objects"] = {
            "amount": total,
            "units": "bytes",
            "desc": "Total bytes used by Python objects.",
        }
        results["vsize"] = {
            "amount": try_call(self._get_virtual_size),
            "units": "bytes",
            "desc": "Memory mapped by the code intelligence process.",
        }
        results["resident"] = {
            "amount": try_call(self._get_resident_size),
            "units": "bytes",
            "desc": "Resident set size in the code intelligence process.",
        }
        results["heap-allocated"] = {
            "amount": try_call(self._get_heap_size),
            "units": "bytes",
            "desc": "The total size of the heap."
        }

        return results
Esempio n. 7
0
    def collectReports(self, reportHandler, closure):
        log.info("collectReports")

        process = ""
        kind_heap = components.interfaces.nsIMemoryReporter.KIND_HEAP
        kind_other = components.interfaces.nsIMemoryReporter.KIND_OTHER
        units_bytes = components.interfaces.nsIMemoryReporter.UNITS_BYTES
        units_count = components.interfaces.nsIMemoryReporter.UNITS_COUNT

        reportHandler.callback(
            process,
            "komodo python active threads",
            kind_other,
            units_count,
            threading.activeCount(),  # amount
            "The number of active Python threads that are currently running.",  # tooltip description
            closure)

        import gc
        gc.collect()
        gc_objects = gc.get_objects()

        import memutils
        total = memutils.memusage(gc_objects)

        # Get the Python memory reporters, generate reports and find out how
        # much memory they are using - and deduct it from the total.
        catman = components.classes["@mozilla.org/categorymanager;1"].\
                        getService(components.interfaces.nsICategoryManager)
        category = 'python-memory-reporter'
        names = catman.enumerateCategory(category)
        while names.hasMoreElements():
            nameObj = names.getNext()
            nameObj.QueryInterface(components.interfaces.nsISupportsCString)
            name = nameObj.data
            cid = catman.getCategoryEntry(category, name)
            log.info("Generating report for %r: %r", name, cid)
            try:
                reporter = components.classes[cid].\
                    getService(components.interfaces.koIPythonMemoryReporter)
                total -= reporter.reportMemory(reportHandler, closure)
            except Exception, e:
                log.exception("Unable to report memory for %r: %r", name, cid)
Esempio n. 8
0
    def collectReports(self, reportHandler, closure):
        log.info("collectReports")

        process = ""
        kind_heap = components.interfaces.nsIMemoryReporter.KIND_HEAP
        kind_other = components.interfaces.nsIMemoryReporter.KIND_OTHER
        units_bytes = components.interfaces.nsIMemoryReporter.UNITS_BYTES
        units_count = components.interfaces.nsIMemoryReporter.UNITS_COUNT

        reportHandler.callback(process,
                               "komodo python active threads",
                               kind_other,
                               units_count,
                               threading.activeCount(), # amount
                               "The number of active Python threads that are currently running.", # tooltip description
                               closure)

        import gc
        gc.collect()
        gc_objects = gc.get_objects()

        import memutils
        total = memutils.memusage(gc_objects)

        # Get the Python memory reporters, generate reports and find out how
        # much memory they are using - and deduct it from the total.
        catman = components.classes["@mozilla.org/categorymanager;1"].\
                        getService(components.interfaces.nsICategoryManager)
        category = 'python-memory-reporter'
        names = catman.enumerateCategory(category)
        while names.hasMoreElements():
            nameObj = names.getNext()
            nameObj.QueryInterface(components.interfaces.nsISupportsCString)
            name = nameObj.data
            cid = catman.getCategoryEntry(category, name)
            log.info("Generating report for %r: %r", name, cid)
            try:
                reporter = components.classes[cid].\
                    getService(components.interfaces.koIPythonMemoryReporter)
                total -= reporter.reportMemory(reportHandler, closure)
            except Exception, e:
                log.exception("Unable to report memory for %r: %r", name, cid)
Esempio n. 9
0
    def reportMemory(self):
        """
        Report on memory usage from this CatalogsZone.
        @returns {dict} memory usage; keys are the paths, values are a dict of
            "amount" -> number
            "units" -> "bytes" | "count"
            "desc" -> str description
        """
        log.debug("CatalogsZone: reporting memory")
        import memutils

        total_mem_usage = 0
        result = {}
        for lang, blob_and_atime_from_blobname in self._blob_and_atime_from_blobname_from_lang_cache.items():
            for blobname, [blob, atime] in blob_and_atime_from_blobname.items():
                result["explicit/python/codeintel/%s/catalog/%s" % (lang, blobname)] = {
                    "amount": memutils.memusage(blob),
                    "units": "bytes",
                    "desc": "The number of bytes of %s codeintel %s catalog blobs." % (lang, blobname),
                }
        return result