jthornber / blk-archive

Dedup and compress your device mapper devices. Works especially well with thin provisioning.
8 stars 3 forks source link

Add json output for dump-stream and add tests #4

Closed tasleson closed 1 year ago

tasleson commented 1 year ago

This PR add json output for dump-stream, e.g.

# target/debug/blk-archive -j dump-stream -a /fubar -s 12f00387fb67abfc
{
  "instructions": [
    {
      "entry": 0,
      "instruction": "Dup { index: 0 }",
      "stack": "0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 "
    },
    {
      "entry": 1,
      "instruction": "SlabDelta12 { delta: 1458 }",
      "stack": "1458:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 "
    },
    {
      "entry": 2,
      "instruction": "Emit4 { len: 1 }",
      "stack": "1458:1 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 "
    }
  ],
  "stats": {
    "dup": 1,
    "emit12": 0,
    "emit20": 0,
    "emit4": 1,
    "fill16": 0,
    "fill32": 0,
    "fill64": 0,
    "fill8": 0,
    "next": 0,
    "offset12": 0,
    "offset20": 0,
    "offset4": 0,
    "offset_delta12": 0,
    "offset_delta4": 0,
    "pos32": 0,
    "pos64": 0,
    "rot": 0,
    "set-fill": 0,
    "slab16": 0,
    "slab32": 0,
    "slab_delta12": 1,
    "slab_delta4": 0,
    "unmapped16": 0,
    "unmapped32": 0,
    "unmapped64": 0,
    "unmapped8": 0
  }
}

It also adds a file I forgot to add with previous commit: 49072407d57cf11548eb7f9bf159e88284a27a38 which is simply

use thinp::report::*;
use std::sync::Arc;

// A structure to encapsulate related output options and output formattting.
pub struct Output {
    pub report: Arc<Report>,
    pub json: bool,
}

It also adds a test/test.py script for running some tests. Before I spend more time on extending this, I would like to make sure this direction is OK. I'm using python and the python unittest library instead of writing a bunch of bash script, but we could go that route or perhaps try to leverage the rust unit tests to do the same. The script leverages the following external binaries for testing in addition to blk-archive itself:

LB_BIN = os.getenv('BLK_ARCHIVE_UT_LOSETUP', "/usr/sbin/losetup")
UMOUNT_BIN = os.getenv('BLK_ARCHIVE_UT_UMOUNT', "/usr/bin/umount")
FS_MAKE_BIN = os.getenv("BLK_ARCHIVE_UT_FS_MAKE", "/usr/sbin/mkfs.xfs")
MOUNT_BIN = os.getenv("BLK_ARCHIVE_UT_MOUNT", "/usr/bin/mount")
LVM_BIN = os.getenv("BLK_ARCHIVE_UT_LVM", "/usr/sbin/lvm")
CMP_BIN = os.getenv("BLK_ARCHIVE_UT_CMP", "/usr/bin/cmp")

Thoughts?