Skip to content

Commit

Permalink
make dbm the default store for visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
jhellerstein committed Apr 13, 2011
1 parent 56adcb1 commit 7387e12
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 29 deletions.
18 changes: 8 additions & 10 deletions bin/budvis
@@ -1,11 +1,10 @@
#!/usr/bin/env ruby
require 'rubygems'
require 'tokyocabinet'
require 'dbm'
require 'bud'
require 'bud/graphs'
include TokyoCabinet

BUD_TC_DIR = "#{ARGV[0]}/bud_"
BUD_DBM_DIR = "#{ARGV[0]}/bud_"

class VizHelper
include Bud
Expand Down Expand Up @@ -123,9 +122,9 @@ end

def usage
puts "Usage:"
puts "Running a Bud program with option :trace => true will cause a TC directory TC_dir to be created (Class_ObjectId_Port)"
puts "> budvis TC_dir"
puts "This will create a series of svg files in TC_dir, the root of which will be named tm_0_expanded.svg. Open in a browser.\n"
puts "Running a Bud program with option :trace => true will cause a DBM directory DVM_dir to be created (Class_ObjectId_Port)"
puts "> budvis DBM_dir"
puts "This will create a series of svg files in DBM_dir, the root of which will be named tm_0_expanded.svg. Open in a browser.\n"
puts "e.g."
puts "> ruby test/tc_carts.rb"
puts "> budvis BCS_2159661360_"
Expand All @@ -137,13 +136,12 @@ usage unless ARGV[0]

@tables = {}

Dir.new(BUD_TC_DIR).entries.each do |file|
Dir.new(BUD_DBM_DIR).entries.each do |file|
next if file =~ /^\./
puts "FILE is #{file}"
hdb = TokyoCabinet::HDB.new
ret = hdb.open("#{BUD_TC_DIR}/#{file}", HDB::OREADER)
ret = DBM.open("#{BUD_DBM_DIR}/#{file}", DBM::O_RDONLY)
raise "db not found" unless ret
@tables[file] = hdb
@tables[file] = ret
end

# let's try to do a visualization
Expand Down
1 change: 0 additions & 1 deletion bud.gemspec
Expand Up @@ -29,7 +29,6 @@ Gem::Specification.new do |s|
s.add_dependency 'sexp_path'
s.add_dependency 'superators'
s.add_dependency 'syntax'
s.add_dependency 'tokyocabinet'
s.add_dependency 'uuid'

# Optional dependencies -- if we can't find these libraries, certain features
Expand Down
7 changes: 7 additions & 0 deletions docs/cheat.md
Expand Up @@ -81,6 +81,13 @@ System-provided attributes: `[:line] => []`
Statements with stdio on lhs must use async merge (`<~`).<br>
To capture `$stdin` on rhs, instantiate Bud with `:read_stdin` option.<br>

### dbm_table ###
Table collection mapped to a [DBM] (http://en.wikipedia.org/wiki/Dbm) store.<br>
Default attributes: `[:key] => [:val]`

dbm_table :t1
dbm_table :t2, [:k1, :k2] => [:v1, :v2]

### tctable ###
Table collection mapped to a [Tokyo Cabinet](http://fallabs.com/tokyocabinet/) store.<br>
Default attributes: `[:key] => [:val]`
Expand Down
3 changes: 1 addition & 2 deletions docs/getstarted.md
Expand Up @@ -2,9 +2,8 @@
In this document we'll do a hands-on tour of Bud and its Bloom DSL for Ruby. We'll start with some examples, and introduce concepts as we go.

## Installation ##
Bud depends on two libraries that need to be installed separately:
Bud depends on one library that needs to be installed separately:

* [TokyoCabinet](http://fallabs.com/tokyocabinet/) (1.4.47 recommended)
* [GraphViz](http://www.graphviz.org/Download.php) (2.26.3 recommended)

Once that's done, you know the drill!
Expand Down
14 changes: 7 additions & 7 deletions docs/visualizations.md
Expand Up @@ -54,7 +54,7 @@ dataflow.

To enable tracing, we need to set `:trace => true` in the `Bud` constructor, and
optionally provide a `:tag` to differentiate between traces by a human-readable
name (rather than by `object_id`). I modified the unit test `test/tc_kvs.rb` as
name (rather than by `object_id`). I modified the unit test `test/DBM_kvs.rb` as
follows:

- v = BestEffortReplicatedKVS.new(@opts.merge(:port => 12345))
Expand All @@ -69,19 +69,19 @@ Then I ran the unit test:
$ ruby test/tc_kvs.rb
Loaded suite test/tc_kvs
Started
.Created directory: TC_BestEffortReplicatedKVS_dist_primary_2160259460_
Created directory: TC_BestEffortReplicatedKVS_dist_primary_2160259460_/bud_
Created directory: TC_BestEffortReplicatedKVS_dist_backup_2159579740_
Created directory: TC_BestEffortReplicatedKVS_dist_backup_2159579740_/bud_
.Created directory: DBM_BestEffortReplicatedKVS_dist_primary_2160259460_
Created directory: DBM_BestEffortReplicatedKVS_dist_primary_2160259460_/bud_
Created directory: DBM_BestEffortReplicatedKVS_dist_backup_2159579740_
Created directory: DBM_BestEffortReplicatedKVS_dist_backup_2159579740_/bud_
..
Finished in 4.366793 seconds.

3 tests, 14 assertions, 0 failures, 0 errors

Then I ran the visualization utility:

$ budvis TC_BestEffortReplicatedKVS_dist_primary_2160259460_/
$ budvis DBM_BestEffortReplicatedKVS_dist_primary_2160259460_/

And finally opened the (chronological) first output file:

$ open -a /Applications/Google\ Chrome.app/ TC_BestEffortReplicatedKVS_dist_primary_2160259460_/tm_0_expanded.svg
$ open -a /Applications/Google\ Chrome.app/ DBM_BestEffortReplicatedKVS_dist_primary_2160259460_/tm_0_expanded.svg
2 changes: 1 addition & 1 deletion lib/bud/storage/dbm.rb
@@ -1,7 +1,7 @@
require 'dbm'

module Bud
# Persistent table implementation based on TokyoCabinet.
# Persistent table implementation based on ndbm.
class BudDbmTable < BudCollection # :nodoc: all
def initialize(name, bud_instance, given_schema)
dbm_dir = bud_instance.options[:dbm_dir]
Expand Down
18 changes: 13 additions & 5 deletions test/tc_wc.rb
Expand Up @@ -13,8 +13,8 @@ def initialize(pattern)
end

state do
file_reader :txt, 'text/ulysses.txt'
# file_reader :txt, 'shaks12.txt'
# file_reader :txt, 'text/ulysses.txt'
file_reader :txt, 'shaks12.txt'

This comment has been minimized.

Copy link
@neilconway

neilconway Apr 13, 2011

Member

shaks12.txt is not checked into Git.

This comment has been minimized.

Copy link
@jhellerstein

jhellerstein Apr 13, 2011

Author Member

fixed

scratch :wc, [:word] => [:cnt]
end

Expand All @@ -27,8 +27,12 @@ def initialize(pattern)

class TestWC1 < Test::Unit::TestCase
def test_wc1
@t = 0
@u = 0
program = WordCount1.new(/[Bb]loom/)
assert_nothing_raised { program.tick }
assert_nothing_raised { @t = Time.now ; program.tick; @u = Time.now }
puts "wc1: #{(@u-@t).to_f}"
require 'ruby-debug'; debugger
assert_equal(23, program.wc[["yes"]].cnt)
end
end
Expand All @@ -45,7 +49,8 @@ def initialize(pattern)
end

state do
file_reader :txt, 'text/ulysses.txt'
# file_reader :txt, 'text/ulysses.txt'
file_reader :txt, 'shaks12.txt'
scratch :words, [:lineno, :wordno] => [:word]
scratch :wc, [:word] => [:cnt]
end
Expand All @@ -64,8 +69,11 @@ def initialize(pattern)

class TestWC2 < Test::Unit::TestCase
def test_wc2
@t = 0
@u = 0
program = WordCount2.new(/[Bb]loom/)
assert_nothing_raised { program.tick }
assert_nothing_raised { @t = Time.now ; program.tick; @u = Time.now }
puts "wc2: #{(@u-@t).to_f}"
assert_equal(23, program.wc[["yes"]].cnt)
end
end
5 changes: 2 additions & 3 deletions test/ts_bud.rb
Expand Up @@ -6,6 +6,7 @@
require 'tc_channel'
require 'tc_collections'
require 'tc_coverage'
require 'tc_dbm'
require 'tc_delta'
require 'tc_errors'
require 'tc_exists'
Expand All @@ -21,9 +22,7 @@
require 'tc_rebl'
require 'tc_schemafree'
require 'tc_semistructured'
require 'tc_tc'
require 'tc_temp'
require 'tc_terminal'
require 'tc_timer'
require 'tc_wc1'
require 'tc_wc2'
require 'tc_wc'

0 comments on commit 7387e12

Please sign in to comment.