Skip to content
Permalink
Browse files

Don't hardcode minimal brightness for dev_extents

To be able to visually distinguish an empty block group and unallocated
space, the minimal brightness value of allocated space starts at 16
instead of 0.

But, if a user wants the difference to be bigger, for example to debug
chunk allocation behaviour, make it possible to increase that value.

Setting it to 255 will cause any allocated space to show up as bright
white, regardless of usage.

This option is only meant to be used for dev_extent level images and is
only accessible when scripting against heatmap.py:

Example:

    import btrfs
    import heatmap

    fs = btrfs.FileSystem('/')
    grid = heatmap.walk_dev_extents(fs, min_brightness=255)
    grid.write_png('all-or-nothing.png')
  • Loading branch information
knorrie committed Dec 18, 2016
1 parent 095412e commit 12483cedb287331afcf0e3ef076d7ba3c5ec7966
Showing with 6 additions and 4 deletions.
  1. +6 −4 heatmap.py
@@ -57,7 +57,8 @@ def parse_args():


class Grid(object):
def __init__(self, order, size, total_bytes, default_granularity, verbose):
def __init__(self, order, size, total_bytes, default_granularity, verbose,
min_brightness=None):
self.order, self.size = choose_order_size(order, size, total_bytes, default_granularity)
self.verbose = verbose
self.curve = hilbert.curve(self.order)
@@ -69,6 +70,7 @@ def __init__(self, order, size, total_bytes, default_granularity, verbose):
self.bytes_per_pixel = total_bytes / self.pos.num_steps
self._grid = [[0 for x in xrange(self.width)] for y in xrange(self.height)]
self._finished = False
self._min_brightness = 16 if min_brightness is None else min_brightness
print("grid order {} size {} height {} width {} total_bytes {} bytes_per_pixel {}".format(
self.order, self.size, self.height, self.width,
total_bytes, self.bytes_per_pixel, self.pos.num_steps))
@@ -84,7 +86,7 @@ def _add_to_pixel(self, used_pct):
self._dirty = True

def _brightness(self, used_pct):
return 16 + int(round(used_pct * (255 - 16)))
return self._min_brightness + int(round(used_pct * (255 - self._min_brightness)))

def _set_pixel_brightness(self, brightness):
self._grid[self.pos.y][self.pos.x] = brightness
@@ -157,7 +159,7 @@ def write_png(self, pngfile):


def walk_dev_extents(fs, devices=None, order=None, size=None,
default_granularity=33554432, verbose=0):
default_granularity=33554432, verbose=0, min_brightness=None):
if devices is None:
devices = list(fs.devices())
dev_extents = fs.dev_extents()
@@ -175,7 +177,7 @@ def walk_dev_extents(fs, devices=None, order=None, size=None,
device_grid_offset[device.devid] = total_bytes
total_bytes += device.total_bytes

grid = Grid(order, size, total_bytes, default_granularity, verbose)
grid = Grid(order, size, total_bytes, default_granularity, verbose, min_brightness)
block_group_cache = {}
for dev_extent in dev_extents:
if dev_extent.vaddr in block_group_cache:

0 comments on commit 12483ce

Please sign in to comment.
You can’t perform that action at this time.