看板 Perl 關於我們 聯絡資訊
已經將原始log中透過Perl處理成以下格式 09:11:06.845,33066845,Send: msg_length, 73,cQ694,0, 09:11:06.860,33066860,Recv: msg_length, 130,cQ694,0, 09:11:09.355,33069355,Send: msg_length, 73,cQ694,4, 09:11:09.369,33069369,Recv: msg_length, 130,cQ694,4, 其中利用最後一欄數字與Send/Recv做以下判別: ====================================== 發送狀態1:ExecType=0 發送狀態2:ExecType=4 發送狀態3:ExecType=5 -------------------------------------- 回報狀態1:ExecType=0 或ExecType=6 回報狀態2:ExecType=4 回報狀態3:ExecType=5 ====================================== if ( $val_type eq 'Send' && $svals->{ExecType} eq '4' ) { $buf->{$ordno}{SS}{tp} = $val_ts; $buf->{$ordno}{SS}{ms} = $val_ms; } elsif ( $val_type eq 'Recv' && ( $svals->{ExecType} eq '4') ) { if ( !defined $buf->{$ordno}{RR} ) { $buf->{$ordno}{RR}{tp} = $val_ts; $buf->{$ordno}{RR}{ms} = $val_ms; } } 09:11:06.845,33066845,Send: msg_length, 73,cQ694,0, 09:11:06.860,33066860,Recv: msg_length, 130,cQ694,0, 09:11:09.355,33069355,Send: msg_length, 73,cQ694,4, 09:11:09.369,33069369,Recv: msg_length, 130,cQ694,4, 執行Perl分析後產生結果如下: cQ694, 09:11:09.355 => 09:11:09.369 ( 14) 第4筆-第3筆,Type都是4的 , Recv-Send計算時間差 OK! ========================================================= 09:11:06.845,33066845,Send: msg_length, 73,cQ694,0, 09:11:06.860,33066860,Recv: msg_length, 130,cQ694,0, 09:11:09.355,33069355,Send: msg_length, 73,cQ694,4, 09:11:09.369,33069369,Recv: msg_length, 130,cQ694,4, **但是要同時區別以下送單 0和4的送單, 改寫成目前寫法就會出錯 if ( ($val_type eq 'Send' && $svals->{ExecType} eq '4') || ($val_type eq 'Send' && $svals->{ExecType} eq '0') ) { $buf->{$ordno}{SS}{tp} = $val_ts; $buf->{$ordno}{SS}{ms} = $val_ms; } elsif ( ($val_type eq 'Recv' && $svals->{ExecType} eq '4') || ($val_type eq 'Recv' && $svals->{ExecType} eq '0') ) { if ( !defined $buf->{$ordno}{RR} ) { $buf->{$ordno}{RR}{tp} = $val_ts; $buf->{$ordno}{RR}{ms} = $val_ms; } } cQ694, 09:11:09.355 => 09:11:06.860 ( -2495) 第3筆-第2筆 ,但是Type不同,錯了 且時間不應該負的 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.63.31.120
herculus6502:在減的時候要不要順便判斷一下ExecType是否相同呢 11/11 13:10
herculus6502:這樣說好了,你的鍵值現在要多了ExecType,不然會有 11/12 08:30
herculus6502:0跟4被你當成同一筆拿來減的情況。為何不用SQL? 11/12 08:31
turnmood:意思是在Perl中加一段SQL判別? 11/12 08:51
herculus6502:應該是說當初這些資料就要先塞到資料庫去處理 11/12 09:16
herculus6502:邏輯寫成STORED PROCEDURES懂的人也比較多 11/12 09:16
herculus6502:邏輯改變時改SP就好,不需要動到主程式 11/12 09:18
herculus6502:$net=$buf->{$key}{RR}{ms} - $buf->{$key}{SS}{ms} 11/12 09:25
herculus6502:這一行並不會幫你抓出同ExecType的,前面也沒有作 11/12 09:29
herculus6502:外面的迴圈也沒有用foreach,寫法並不太perlish 11/12 09:31
herculus6502:眼前的解法就再加一層迴圈iterate各種ExecType 11/12 09:36
herculus6502:好奇問一下公司的性質是…? 11/12 09:37