From 689eae37c5aa442c63f29bc53009cbe659e7a3fc Mon Sep 17 00:00:00 2001 From: Kevin Lyda <kevin@ie.suberic.net> Date: Thu, 9 Feb 2017 14:51:45 +0000 Subject: [PATCH] More test changes. --- peek.py | 35 +++++++++++++++++++++++++++++++++++ ruby/Gemfile | 5 +++++ ruby/Gemfile.lock | 19 +++++++++++++++++++ ruby/test.rb | 8 ++++++++ 4 files changed, 67 insertions(+) create mode 100755 peek.py create mode 100644 ruby/Gemfile create mode 100644 ruby/Gemfile.lock create mode 100644 ruby/test.rb diff --git a/peek.py b/peek.py new file mode 100755 index 0000000..1e9100a --- /dev/null +++ b/peek.py @@ -0,0 +1,35 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +# vim:fenc=utf-8 + +from __future__ import unicode_literals + +""" +Test script to peek in db files. +""" + +import struct +import os +import mmap + +filename = 'metrics/gauge_livesum_40272.db' +f = open(filename, 'a+b') +capacity = os.fstat(f.fileno()).st_size +m = mmap.mmap(f.fileno(), capacity) +used = struct.unpack_from(b'i', m, 0)[0] + +pos = 8 +while pos < used: + encoded_len = struct.unpack_from(b'i', m, pos)[0] + pos += 4 + encoded = struct.unpack_from('{0}s'.format(encoded_len).encode(), m, pos)[0] + padded_len = encoded_len + (8 - (encoded_len + 4) % 8) + pos += padded_len + value = struct.unpack_from(b'd', m, pos)[0] + print("Entry: %s = %d" % (encoded, value)) + pos += 8 + +f.close() + +print("Capacity %s" % capacity) +print("Used %d" % used) diff --git a/ruby/Gemfile b/ruby/Gemfile new file mode 100644 index 0000000..65ed30d --- /dev/null +++ b/ruby/Gemfile @@ -0,0 +1,5 @@ +# frozen_string_literal: true +source "https://rubygems.org" + +gem 'mmap', git: 'https://github.com/lyda/mmap.git', :branch => 'non-global-version' +#gem 'mmap', :path => '/Users/kevin/src/p4g/mmap' diff --git a/ruby/Gemfile.lock b/ruby/Gemfile.lock new file mode 100644 index 0000000..40d0620 --- /dev/null +++ b/ruby/Gemfile.lock @@ -0,0 +1,19 @@ +GIT + remote: https://github.com/lyda/mmap.git + revision: 379bdbd2c848e96d8f89e954663b8c26529b8919 + branch: non-global-version + specs: + mmap (0.2.7) + +GEM + remote: https://rubygems.org/ + specs: + +PLATFORMS + ruby + +DEPENDENCIES + mmap! + +BUNDLED WITH + 1.14.3 diff --git a/ruby/test.rb b/ruby/test.rb new file mode 100644 index 0000000..9d5ef2d --- /dev/null +++ b/ruby/test.rb @@ -0,0 +1,8 @@ +require 'mmap' + +mmap = Mmap.new(__FILE__) +mmap.advise(Mmap::MADV_SEQUENTIAL) + +mmap.each do |line| + puts line +end -- GitLab