Class: SysBench::IO

Inherits:
Object
  • Object
show all
Defined in:
lib/sysbench/io.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ IO

Returns a new instance of IO.



10
11
12
13
14
15
16
# File 'lib/sysbench/io.rb', line 10

def initialize(file)
    if not File.exists? file then
        puts "File '#{file}' does not exist!"
        exit
    end
    parse(File.new(file).read)
end

Instance Attribute Details

#avgObject

Returns the value of attribute avg.



8
9
10
# File 'lib/sysbench/io.rb', line 8

def avg
  @avg
end

#block_sizeObject

Returns the value of attribute block_size.



6
7
8
# File 'lib/sysbench/io.rb', line 6

def block_size
  @block_size
end

#byte_rateObject

Returns the value of attribute byte_rate.



7
8
9
# File 'lib/sysbench/io.rb', line 7

def byte_rate
  @byte_rate
end

#maxObject

Returns the value of attribute max.



8
9
10
# File 'lib/sysbench/io.rb', line 8

def max
  @max
end

#minObject

Returns the value of attribute min.



8
9
10
# File 'lib/sysbench/io.rb', line 8

def min
  @min
end

#request_rateObject

Returns the value of attribute request_rate.



7
8
9
# File 'lib/sysbench/io.rb', line 7

def request_rate
  @request_rate
end

#testObject

Returns the value of attribute test.



5
6
7
# File 'lib/sysbench/io.rb', line 5

def test
  @test
end

#threadsObject

Returns the value of attribute threads.



5
6
7
# File 'lib/sysbench/io.rb', line 5

def threads
  @threads
end

#topObject

Returns the value of attribute top.



8
9
10
# File 'lib/sysbench/io.rb', line 8

def top
  @top
end

#total_sizeObject

Returns the value of attribute total_size.



6
7
8
# File 'lib/sysbench/io.rb', line 6

def total_size
  @total_size
end

#versionObject

Returns the value of attribute version.



5
6
7
# File 'lib/sysbench/io.rb', line 5

def version
  @version
end

Instance Method Details

#parse(str) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sysbench/io.rb', line 18

def parse(str)
    str.split(/\n/).each do |l|
       
       l.strip!
       if l =~ /^sysbench (.+?):/
           @version = $1
           
       elsif l =~ /^Number of threads: (\d+)$/
           @threads = $1
           
       elsif l =~ /^Doing (.+?) test$/
           @test = $1
           
       elsif l =~ /^(.+?) total file size$/
           @total_size = $1
        
       elsif l =~ /^Block size (.+?)$/
           @block_size = $1
           
       elsif l =~ /Read [\dKMGTb.]+  Written [\dKMGTb.]+  Total transferred [\dKMGTb.]+  \((.+?)\)/
           @byte_rate = $1
           
       elsif l =~ /^(.+?) Requests\/sec executed$/
           @request_rate = $1
           
       elsif l =~ /min:\s+(.+?)$/
           @min = $1
           
       elsif l =~ /max:\s+(.+?)$/
           @max = $1
       elsif l =~ /avg:\s+(.+?)$/
           @avg = $1
           
       elsif l =~ /approx.*?:\s+(.+?)$/
           @top = $1
       end

    end # each    
end

#to_s(delim = "\t") ⇒ Object

parse



58
59
60
# File 'lib/sysbench/io.rb', line 58

def to_s(delim = "\t")
    [@test, @threads, @total_size, @block_size, @byte_rate, @request_rate, @min, @max, @avg, @top].join("\t")
end