| 1 | |
| 2 | == Perl Script to Dump Database == |
| 3 | |
| 4 | Here we provide a script to dump desirable information from the database. |
| 5 | |
| 6 | The script did: |
| 7 | * dump the sender-side table and receiver-side table from one or more OML database |
| 8 | * count how many records are in each table |
| 9 | * put those number pairs in a file |
| 10 | |
| 11 | The comparison of those two numbers could give an indication of the packet loss of OTG/OTR application |
| 12 | |
| 13 | The program take database names as input arguments and save the result in "tempres" file |
| 14 | |
| 15 | {{{ |
| 16 | |
| 17 | #!/usr/bin/perl |
| 18 | |
| 19 | # this script read one or more databases and extract how many packets are sent and received respectively. |
| 20 | # |
| 21 | |
| 22 | use Mysql; |
| 23 | |
| 24 | $hostname = 'idb1.orbit-lab.org'; |
| 25 | $user = 'orbit'; |
| 26 | $database = 'none'; |
| 27 | $password = 'orbit'; |
| 28 | $resultfile ='tempres'; |
| 29 | |
| 30 | |
| 31 | $table1 = "temp/tx_table"; |
| 32 | $table2 = "temp/rx_table"; |
| 33 | |
| 34 | $driver = 'mysql'; |
| 35 | |
| 36 | my $noiselevel = 18; |
| 37 | my $now = localtime time; |
| 38 | open(res, ">>$resultfile") |
| 39 | || die "Can't open result file: $!\n"; |
| 40 | print res "$now test with noise level set in $noiselevel dbm \n"; |
| 41 | close res; |
| 42 | |
| 43 | foreach(@ARGV) |
| 44 | { |
| 45 | dumpDB($_,$table1,$table2); |
| 46 | system("awk 'BEGIN {cnt=0} {cnt =cnt+1} END {printf(\"%d \", cnt) >> \"$resultfile\" }' $table2"); |
| 47 | system("awk 'BEGIN {cnt=0} {cnt =cnt+1} END {printf(\"%d \\n\", cnt) >> \"$resultfile\" }' $table1"); |
| 48 | } |
| 49 | |
| 50 | print "Done. check tempres file! \n"; |
| 51 | |
| 52 | #we need a subfunction to read 1 database 2 table and dump to two files |
| 53 | sub dumpDB |
| 54 | { |
| 55 | my ($dbname,$f1, $f2) = @_; |
| 56 | open (OUTFILE1, "> $f1"); |
| 57 | open (OUTFILE2, "> $f2"); |
| 58 | my $dbh = Mysql->connect($hostname, $dbname, $user, $password); |
| 59 | my $sql_query1="SELECT sequence_no, pkt_seqno, pkt_size_sample_sum, tx_timestamp from sender_otg_senderport"; |
| 60 | my $sql_query2="SELECT sequence_no, pkt_seqno, rcvd_pkt_size_sample_sum, xmitrate, rx_timestamp from receiver_otr_receiverport"; |
| 61 | my $sth1 = $dbh->query($sql_query1); |
| 62 | while(my @record1 = $sth1->FetchRow) { |
| 63 | print OUTFILE1 "@record1 \n"; |
| 64 | } |
| 65 | |
| 66 | my $sth2 = $dbh->query($sql_query2); |
| 67 | while(my @record2 = $sth2->FetchRow) { |
| 68 | print OUTFILE2 "@record2 \n"; |
| 69 | } |
| 70 | close OUTFILE1; |
| 71 | close OUTFILE2; |
| 72 | } |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | }}} |