Skip to content

Commit

Permalink
fix #106 - reinstate python 2.6 long type
Browse files Browse the repository at this point in the history
looks like both the original code, and the one in the following commit:
d796525
assumed a simple int type is 64bit (8 bytes), and a long int is 128bit (16 bytes).
this was wrong, but besides we now have the architecture flag that tells us the
size of an int on the target platform.
  • Loading branch information
oranagra committed Dec 11, 2017
1 parent bd08e80 commit 03f53ed
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions rdbtools/memprofiler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import codecs
from collections import namedtuple
import random
Expand Down Expand Up @@ -184,7 +185,7 @@ def set(self, key, value, expiry, info):
self._current_encoding = info['encoding']
size = self.top_level_object_overhead(key, expiry) + self.sizeof_string(value)

length = element_length(value)
length = self.element_length(value)
self.emit_record("string", key, size, self._current_encoding, length, length)
self.end_key()

Expand All @@ -202,10 +203,10 @@ def start_hash(self, key, length, expiry, info):
self._current_size = size

def hset(self, key, field, value):
if(element_length(field) > self._len_largest_element) :
self._len_largest_element = element_length(field)
if(element_length(value) > self._len_largest_element) :
self._len_largest_element = element_length(value)
if(self.element_length(field) > self._len_largest_element) :
self._len_largest_element = self.element_length(field)
if(self.element_length(value) > self._len_largest_element) :
self._len_largest_element = self.element_length(value)

if self._current_encoding == 'hashtable':
self._current_size += self.sizeof_string(field)
Expand All @@ -224,8 +225,8 @@ def start_set(self, key, cardinality, expiry, info):
self.start_hash(key, cardinality, expiry, info)

def sadd(self, key, member):
if(element_length(member) > self._len_largest_element) :
self._len_largest_element = element_length(member)
if(self.element_length(member) > self._len_largest_element) :
self._len_largest_element = self.element_length(member)

if self._current_encoding == 'hashtable':
self._current_size += self.sizeof_string(member)
Expand Down Expand Up @@ -265,8 +266,8 @@ def rpush(self, key, value):
self._current_length += 1
size = self.sizeof_string(value) if type(value) != int else 4

if(element_length(value) > self._len_largest_element):
self._len_largest_element = element_length(value)
if(self.element_length(value) > self._len_largest_element):
self._len_largest_element = self.element_length(value)

if self._current_encoding == "ziplist":
self._list_items_zipped_size += self.ziplist_entry_overhead(value)
Expand Down Expand Up @@ -325,8 +326,8 @@ def start_sorted_set(self, key, length, expiry, info):
self._current_size = size

def zadd(self, key, score, member):
if(element_length(member) > self._len_largest_element):
self._len_largest_element = element_length(member)
if(self.element_length(member) > self._len_largest_element):
self._len_largest_element = self.element_length(member)

if self._current_encoding == 'skiplist':
self._current_size += 8 # score (double)
Expand Down Expand Up @@ -489,16 +490,12 @@ def zset_random_level(self):
else:
return ZSKIPLIST_MAXLEVEL

MAXINT = 2**63 - 1


def element_length(element):
if isinstance(element, int):
if element < - MAXINT - 1 or element > MAXINT:
return 16
else:
return 8
else:
def element_length(self, element):
if isinstance(element, int):
return self._long_size
if sys.version_info < (3,):
if isinstance(element, long):
return self._long_size
return len(element)


Expand Down

0 comments on commit 03f53ed

Please sign in to comment.