]> git.cryptolib.org Git - avr-crypto-lib.git/blob - host/get_performance.rb
performance tools
[avr-crypto-lib.git] / host / get_performance.rb
1 #!/usr/bin/ruby 
2 # get_performance.rb
3 =begin
4     This file is part of the AVR-Crypto-Lib.
5     Copyright (C) 2008, 2009  Daniel Otte (daniel.otte@rub.de)
6
7     This program is free software: you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation, either version 3 of the License, or
10     (at your option) any later version.
11
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 =end
20
21 require 'serialport'
22
23 def read_line(error_msg=true)
24   s = $sp.gets()
25   if s==nil
26     puts("ERROR: read timeout!\n") if error_msg
27         return nil
28   end   
29   s.gsub(/\006/, '');   
30 end
31
32 def readPerformanceVector(param)
33   lb=""
34   buffer=""
35   fname=""
36   fout=0
37   begin
38     lb = read_line()
39     if lb.match(/End of performance figures/)
40       return false
41         end
42         if m=lb.match(/=== (.*) performance ===/) 
43           fout.close if fout!=0
44           fname=$dir+m[1]
45           fname+="."+param if param != ""
46           fname+=".txt"
47           fout = File.open(fname, "w+")
48           printf("> %s \n", fname)      
49           fout.write(lb)
50     else
51           if fout!=0 && lb!=""
52             fout.write(lb)
53           end   
54         end
55   end while true
56 end
57
58
59 if ARGV.size < 5
60   STDERR.print <<EOF
61   Usage: ruby #{$0} port bps nbits stopb command [target_dir] [additional specifier]
62 EOF
63   exit(1)
64 end
65
66 command=ARGV[4]+"\r";
67 $dir=(ARGV.size>=6)?ARGV[5]:"";
68 param=(ARGV.size>=7)?ARGV[6]:"";
69
70 puts("\nPort: "+ARGV[0]+ "@"+ARGV[1]+" "+ARGV[2]+"N"+ARGV[3]+"\n");
71 $linewidth = 16
72 $sp = SerialPort.new(ARGV[0], ARGV[1].to_i, ARGV[2].to_i, ARGV[3].to_i, SerialPort::NONE);
73 $sp.read_timeout=1000; # 1 secound
74 $extended_wait=100;
75 $sp.write(command);
76
77 while(readPerformanceVector(param))
78 end
79
80 exit(0);
81
82