sripathikrishnan / redis-rdb-tools

Parse Redis dump.rdb files, Analyze Memory, and Export Data to JSON
https://rdbtools.com
MIT License
5.09k stars 743 forks source link

the return value of sizeof_string in memprofiler.py should add robj_overhead()? #134

Closed spccold closed 6 years ago

spccold commented 6 years ago
 def sizeof_string(self, string):
        # https://github.com/antirez/redis/blob/unstable/src/sds.h
        try:
            num = int(string)
            if num < REDIS_SHARED_INTEGERS :
                return 0
            else :
                return 8 + self.robj_overhead()
        except ValueError:
            pass
        l = len(string)
        if self._redis_version < StrictVersion('3.2'):
            return self.malloc_overhead(l + 8 + 1) + self.robj_overhead()
        if l < 2**5:
            return self.malloc_overhead(l + 1 + 1) + self.robj_overhead()
        if l < 2**8:
            return self.malloc_overhead(l + 1 + 2 + 1) + self.robj_overhead()
        if l < 2**16:
            return self.malloc_overhead(l + 1 + 4 + 1) + self.robj_overhead()
        if l < 2**32:
            return self.malloc_overhead(l + 1 + 8 + 1) + self.robj_overhead()
        return self.malloc_overhead(l + 1 + 16 + 1) + self.robj_overhead()