forked from joewilliams/strace_analyzer_ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strace_analyzer_ng_0.09.pl
2951 lines (2628 loc) · 107 KB
/
strace_analyzer_ng_0.09.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl -w
#
# Copyright 2008-2009 Jeffrey B. Layton
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# Assumptions in code:
# (1) Units are not reused for different file names (i.e. one-to-one
# mapping between unit and filename
#
#
# Notes:
# (1) Need to add the ability for the simulator to create data files
# for when a unit is opened and immediately read from (not written)
#
# strace -e trace=open,close,_llseek,read,write -ttt -o strace.out
#
# strace -T -e trace=open,close,_llseet,read,write -ttt
#
# Add ability to track file offset on a per file basis (9/2/2009)
# - Do lseek offset computations (watch "offset" in lseek - parse constants)
# - Need to add some defensive programming as well
#
use strict;
use Getopt::Long;
use POSIX qw(ceil floor);
# Other Variables:
my ($LineNum, $time, $cmd, $cmdtmp);
my ($cmd_unit, $sec);
my ($elapsed_time); # elapsed time of function
my $Numlines;
my ($lineOutput);
my (%CmdCounter);
my $lineCount;
# ============
# IO Variables
# ============
# Time Variables
my ($BeginTime, $EndTime);
# "Open" sys call variables
# -------------------------
# Array of hash for Open syscalls
my (@Open);
# $Open[syscall number]->{line_number} = $LineNum; # Line number in strace of syscall call
# $Open[syscall number]->{sec} = $epoch_sec; # Seconds since epoch for syscall call
# $Open[syscall number]->{file} = $filename; # filename in open syscall call
# $Open[syscall number]->{unit} = $unit; # unit (file descriptor) associated with file
# $Open[syscall number]->{elapsed_time} = $elapsed_time # elapsed time of syscall call
my (%OpenMax); # Hash of slowest open syscall
# $OpenMax{"line"} = line number of strace where slowest open occurred
# $OpenMax{"MaxTime"} = elapsed time for slowest open syscall
my (@Open_Filename); # Array of currently opened units
my ($oflags, $mode);
# "Write" syscalls variables and arrays:
# --------------------------------------
my (@Write);
# $Write[syscall number]->{line_number} = Line Number
# $Write[syscall number]->{sec} = $epoch_sec; # Seconds since epoch for syscall
# $Write[syscall number]->{elapsed_time} = elepased time for syscall number
# $Write[syscall number]->{byte_sec} = Write throughput for syscall number
# $Write[syscall number]->{bytes} = Number of bytes in syscall
# $Write[syscall number]->{unit} = file descriptor for write syscall number
my ($WriteBytesTotal); # Total number of bytes written (all fd's and files)
my (%WriteMax); # Hash of slowest write syscall
# $WriteMax{"line"} = line number of strace where slowest write occurred
# $WriteMax{"MaxTime"} = elapsed time for slowest write syscall
my ($WriteLarge); # Largest Write syscall
my ($WriteSmall); # Smallest Write syscall
# "Write" Statistics
# ------------------
my (@Local_Write_Array);
my ($My_Median, $Test_Average, $Std_Dev);
# "Read" syscalls variables and arrays:
# -------------------------------------
my (@Read);
# $Read[syscall number]->{line_number} = Line Number
# $Read[syscall number]->{sec} = $epoch_sec; # Seconds since epoch for syscall
# $Read[syscall number]->{elapsed_time} = elpased time for syscall number
# $Read[syscall number]->{byte_sec} = Read throughput for syscall number
# $Read[syscall number]->{bytes} = Number of bytes in syscall
# $Read[syscall number]->{unit} = file descriptor for read syscall number
my ($ReadBytesTotal); # Total number of bytes read by all files
my (%ReadMax); # Hash of slowest read syscall
# $ReadMax{"line"} = line number of strace where slowest read occurred
# $ReadMax{"MaxTime"} = elapsed time for slowest read syscall
my ($ReadLarge); # Largest Read syscall
my ($ReadSmall); # Smallest Read syscall
# "Read" Statistics
# -----------------
my (@Local_Read_Array);
# "Close" syscalls variables and arrays
# -------------------------------------
my (@Close);
# $Close[syscall number]->{line_number} = line number in strace file
# $Close[syscall number]->{sec} = time of syscall (seconds since epoch)
# $Close[syscall number]->{unit} = file descriptor for close syscall
# $Close[syscall number]->{elapsed_time} = elapsed time (secs) for syscall
my (%CloseMax); # Hash of slowest close syscall
# $CloseMax{"line"} = line number of strace where slowest close occurred
# $CloseMax{"MaxTime"} = elapsed time for slowest close syscall
my (@Close_Unit_Ops);
# Open variables and arrays
# "lseek" syscall variables and arrays
# ------------------------------------
my (%LseekMax); # Hash of slowest lseek syscall
# $LseekMax{"line"} = line number in strace where slowest syscall occurred
# $LseekMax{"MaxTime"} = elapsed time for slowest lseek syscall
my (@lseek_activity);
my ($offset, $whence, $offset_success, $offset_junk, $offset_results);
my ($current_offset, $parts_length, $ip);
my (@lseek_activity_counter, @lseek_unit);
# Hash and array for file sizes
my (@FileSizes, %FileSizeCounter);
# IOPS variables and arrays (hashes)
# ----------------------------------
# Variables for computing IOPS
my (@IOPS_Total, @IOPS_Read, @IOPS_Write);
my (@IOPS_Read_Unit);
# $IOPS_Read_Unit[unit][time interval] = number of read IOPS
my (@IOPS_Write_Unit);
# $IOPS_Write_Unit[unit][time interval] = number of write IOPS
my ($IOPS_Total_Avg, $IOPS_Read_Avg, $IOPS_Write_Avg);
my ($IOPS_Write_Final, $IOPS_Read_Final, $IOPS_Total_Final);
# Offsets Tracking
# ----------------
my (@Offset); # Offset hash array (2D array)
# $Offset[unit][timestep]->{time} = time of syscall relative to beginning of run
# $Offset[unit][timestep]->{offset} = offset in bytes of syscall
my (@Offset_point);
# $Offset[$unit] = current file pointer location of $unit (in bytes)
# Hash for storing data on a per file basis:
my (@File_Stats);
# $File_Stats[$unit]->{file} = $filename;
# $File_Stats[$unit]->{read_bytes} += $byte;
# $File_Stats[$unit]->{write_bytes} += $byte;
# $File_Stats[$iloop]->{read_rate_count}
# $File_Stats[$iloop]->{read_rate_sum}
# $File_Stats[$iloop]->{write_rate_sum}
# $File_Stats[$iloop]->{write_rate_count
my (@File_Stats_2);
# @File_Stats_2[$unit]->{read_bytes} = Number of bytes read (total) per unit
# @File_Stata_2[$unit]->{write_bytes} = number of bytes written (total) per unit
# @File_Stats_2[$unit]->{file} = filename
# @File_Stats_2[$unit]->{read_rate_sum} = sum of read throughput per unit
# @File_Stats_2[$unit]->{read_rate_count} = total number of read functions per unit
# @File_Stats_2[$unit]->{write_rate_sum} = sum or write throughtput per unit
# @File_Stats_2[$unit]->{write_rate_count} = tota number of write functions per unit
# Temporary variables and arrays:
# -------------------------------
my (@parts);
my ($temp);
my ($junk, $junk1, $junk2, $junk3, $junk4, $junk5, $junk6, $junk7, $sum, $unit, $byte);
my ($ielement, $size, $size_2, $size_3);
my ($zero, $equal);
my ($before, $filename, $after, $index);
my ($iloop, $jloop, $kloop, $icount, $key);
my ($IOTimeSum, $IOTime_count);
my ($IOPS_max_temp, $index_max, $sec_begin);
my ($sec_local);
my ($jwalker, $kwalker);
# Command line arguments
my ($base_directory);
my ($filesizeinput, $debug, $helpflag, $shortflag, $datflag);
my ($open_sim_flag);
# Define IO functions we are interested in
my $OPEN = "open"; # done
my $READ = "read"; # done
my $WRITE = "write"; # done
my $CLOSE = "close"; # done
my $LSEEK = "lseek"; # done
my $LLSEEK = "llseek"; # done
my $LSEEK64 = "lseek64"; # done
my $STAT = "stat"; # counter only done
my $STAT64 = "stat64"; # counter only done
my $FSTAT = "fstat"; # counter only done
my $CHMOD = "chmod"; # counter only done
my $ACCESS = "access"; # counter only done
my $RENAME = "rename"; # counter only done
my $MKDIR = "mkdir"; # counter only done
my $GETDENTS = "getdents"; # counter only done
my $FCNTL = "fcntl"; # counter only done
my $UNLINK = "unlink"; # counter only done
my $FSEEK = "fseek"; # counter only done
my $REWIND = "rewind"; # counter only done
my $FTELL = "ftell"; # counter only done
my $FGETPOS = "fgetpos"; # counter only done
my $FSETPOS = "fsetpos"; # counter only done
my $FCLOSE = "fclose"; # counter only done
my $FSYNC = "fsync"; # counter only done
my $CREAT = "creat"; # counter only done
my $READDIR = "readdir"; # counter only done
my $OPENDIR = "opendir"; # counter only done
my $REWINDDIR = "rewinddir"; # counter only done
my $SCANDIR = "scandir"; # counter only done
my $SEEKDIR = "seekdir"; # counter only done
my $TELLDIR = "telldir"; # counter only done
my $FLOCK = "flock"; # counter only done
my $LOCKF = "lockf"; # counter only done
#
# Intialization
#
$debug = 0;
$filesizeinput = 0;
$helpflag = 0;
$shortflag = 0;
$datflag = 0;
$Numlines = 0;
$LineNum = 0;
$zero = 0.0;
$CloseMax{"line"} = 0;
$CloseMax{"MaxTime"} = -1.0;
$ReadMax{"line"} = 0;
$ReadMax{"MaxTime"} = -1.0;
$WriteMax{"line"} = 0;
$WriteMax{"MaxTime"} = -1.0;
$OpenMax{"line"} = 0;
$OpenMax{"MaxTime"} = -1.0;
$LseekMax{"line"} = -1.0;
$LseekMax{"MaxTime"} = -1.0;
$BeginTime = -1.0;
$EndTime = -1.0;
$IOTimeSum = 0.0;
$IOTime_count = 0;
$WriteBytesTotal = 0.0;
$base_directory = '.';
$open_sim_flag = 0;
$equal = "=";
$WriteLarge = 0;
$WriteSmall = 100000000000;
$ReadLarge = 0;
$ReadSmall = 100000000000;
$jwalker = 0;
$kwalker = 0;
GetOptions('f|file=s' => \$filesizeinput,
"debug" => \$debug,
"h|help" => \$helpflag,
"dat" => \$datflag,
"short" => \$shortflag );
if ($helpflag > 0)
{
helpoutput();
exit;
}
open(STRACE_LOG, '>strace_analyzer.log');
printf(STRACE_LOG "Diagnostic Output: \n");
printf(STRACE_LOG "================== \n");
printf(STRACE_LOG " \n");
#
# Loop over lines in file
#
while(<>) {
chomp;
# Split current line using spaces
($sec, $cmdtmp, @parts) = split;
# Increment Line Number
$LineNum++;
# Echo input line to output
$lineOutput = $sec . " " . $cmdtmp . " ";
foreach my $specific_part (@parts) {
if (defined $specific_part) {
$lineOutput = $lineOutput . $specific_part . " ";
}
}
if ($debug > 0) {
printf(STRACE_LOG "(%d)\t%s \n",$LineNum, $lineOutput);
}
# Split the temporary command ($cmdtmp) to get the correct "syscall"
($cmd, $cmd_unit) = split(/\(/,$cmdtmp);
$cmd =~ s/^_{1,}(\S+)/$1/;
if ($debug > 0) {
printf(STRACE_LOG " cmd: %s cmd_unit: %s LineNum: %s \n",$cmd, $cmd_unit, $LineNum);
printf(STRACE_LOG " sec = %s \n",$sec);
}
# Extract elapsed time from end of line (stored in parts array)
$junk1 = @parts; # length of parts array
$junk4 = $parts[$junk1-1]; # The last element of @parts is elapsed time
$junk2 = length($junk4); # Length of elapsed time string
$elapsed_time = substr($junk4, 1, $junk2-2); # Extract value dropping leading and trailing "<>"
# This is the elapsed time
if ($debug > 0) {
printf(STRACE_LOG " real elapsed time: %s \n", $elapsed_time);
}
# Store beginning time
if ($LineNum == 1) {
$BeginTime = $sec;
$sec_begin = $sec;
}
$Numlines++;
# =========================
# If ladder to process data
# =========================
if ($cmd eq $OPEN){
if ($debug > 0) {
printf(STRACE_LOG " Found an OPEN function call \n");
#printf(STRACE_LOG " setting iopen to 1 \n");
}
# Increment total IO time and syscall counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
# initialization
$ielement = $#Open; # Number of elements in @Open hash
$oflags = "";
$mode = "";
# file name is contained in cmdtemp
# opening options are contained in @parts - usually parts(1) with a comma or ")" at the end
# Unit is contained after the "=" in the @parts
&Open_Processing();
} elsif ($cmd eq $STAT) {
if ($debug > 0) {
printf(STRACE_LOG "FOUND A STAT!!!\n");
}
$CmdCounter{"stat"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $FSTAT) {
if ($debug > 0) {
printf(STRACE_LOG "FOUND A FSTAT!!!\n");
}
$CmdCounter{"fstat"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $STAT64) {
if ($debug > 0) {
printf(STRACE_LOG "FOUND A STAT64!!!\n");
}
$CmdCounter{"stat64"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $LSEEK){
if ($debug > 0) {
printf(STRACE_LOG "FOUND AN LSEEK!!!\n");
}
$CmdCounter{"lseek"}++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
&Lseek_Processing();
} elsif ($cmd eq $LLSEEK){
if ($debug > 0) {
printf(STRACE_LOG "FOUND AN LLSEEK!!!\n");
}
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
&LLseek_Processing();
} elsif ($cmd eq $LSEEK64) {
if ($debug > 0) {
printf(STRACE_LOG "FOUND AN LSEEK64!!!\n");
}
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
&Lseek_Processing();
} elsif ($cmd eq $CHMOD){
$CmdCounter{"chmod"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $ACCESS){
$CmdCounter{"access"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $RENAME){
$CmdCounter{"rename"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $MKDIR){
$CmdCounter{"mkdir"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $GETDENTS){
$CmdCounter{"getdents"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $FCNTL){
$CmdCounter{"fcntl"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $UNLINK){
$CmdCounter{"unlink"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $FSEEK){
$CmdCounter{"fseek"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $REWIND){
$CmdCounter{"rewind"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $FTELL){
$CmdCounter{"ftell"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $FGETPOS){
$CmdCounter{"fgetpos"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $FCLOSE){
$CmdCounter{"fclose"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $FSYNC){
$CmdCounter{"fsync"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $CREAT){
$CmdCounter{"creat"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $READDIR){
$CmdCounter{"readdir"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $OPENDIR){
$CmdCounter{"opendir"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $REWINDDIR){
$CmdCounter{"rewinddir"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $SCANDIR){
$CmdCounter{"scandir"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $SEEKDIR){
$CmdCounter{"seekdir"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $TELLDIR){
$CmdCounter{"telldir"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $FLOCK){
$CmdCounter{"flock"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $LOCKF){
$CmdCounter{"lockf"}++;
$temp = floor($sec - $BeginTime) + 1; # Time in second referenced to beginning time
$IOPS_Total[$temp]++;
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
} elsif ($cmd eq $READ) {
$ielement = $#Read;
if ($debug > 0) {
printf(STRACE_LOG " ** Found a READ function call \n");
}
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
&Read_Processing();
} elsif ($cmd eq $WRITE) {
$ielement = $#Write;
if ($debug > 0) {
printf(STRACE_LOG " ** Found a WRITE function call \n");
}
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
&Write_Processing();
} elsif ($cmd eq $CLOSE) {
$ielement = $#Close;
if ($debug > 0) {
printf(STRACE_LOG " ** Found a CLOSE function call \n");
printf(STRACE_LOG " Calling Close_Processing \n");
}
# Increment total IO time and command counters
$IOTimeSum = $IOTimeSum + $elapsed_time;
$IOTime_count++;
&Close_Processing();
} else {
#$CmdStore[$LineNum] = $cmd;
}
}
$EndTime = $sec;
# ============================================================================
# ============================================================================
# ============================ Output Summary ============================
# ============================================================================
# ============================================================================
printf(" \n \n");
printf("Analysis Output \n");
printf("=============== \n");
printf("\nNumber of Lines in strace file: %d \n",$Numlines);
printf("\n");
# Initialize file sizes (used for summary of read/write functions)
$FileSizes[0] = 1000; # 1KB
$FileSizes[1] = 8000; # 8KB
$FileSizes[2] = 32000; # 32KB
$FileSizes[3] = 128000; # 128KB
$FileSizes[4] = 256000; # 256KB
$FileSizes[5] = 512000; # 512KB
$FileSizes[6] = 1000000; # 1MB
$FileSizes[7] = 10000000; # 10MB
$FileSizes[8] = 100000000; # 100MB
$FileSizes[9] = 1000000000; # 1GB
$FileSizes[10] = 10000000000; # 10GB
$FileSizes[11] = 100000000000; # 100GB
$FileSizes[12] = 1000000000000; # 1TB
$FileSizes[13] = 10000000000000; # 10TB
#$FileSizes[4] = $FileSizes[3]*1024;
#$FileSizes[5] = $FileSizes[4]*1024;
# Initialize File size counters
$FileSizeCounter{1000} = 0;
$FileSizeCounter{8000} = 0;
$FileSizeCounter{32000} = 0;
$FileSizeCounter{128000} = 0;
$FileSizeCounter{256000} = 0;
$FileSizeCounter{512000} = 0;
$FileSizeCounter{1000000} = 0;
$FileSizeCounter{10000000} = 0;
$FileSizeCounter{100000000} = 0;
$FileSizeCounter{1000000000} = 0;
$FileSizeCounter{10000000000} = 0;
$FileSizeCounter{100000000000} = 0;
$FileSizeCounter{1000000000000} = 0;
$FileSizeCounter{10000000000000} = 0;
# ===============
# Time statistics
# ===============
# Elapsed Time for run length
printf("----------------\n");
printf("-- Time Stats --\n");
printf("----------------\n");
printf("Elapsed Time for run: %f (secs) \n", ($EndTime - $BeginTime) );
printf("Total IO Time: %f (secs) \n", $IOTimeSum);
printf("Total IO Time Counter: %d \n",$IOTime_count);
printf(" Percentage of Total Time = %f%% \n", (($IOTimeSum/($EndTime - $BeginTime))*100.0) );
# =====================
# IO Command statistics
# =====================
printf(" \n\n");
printf("---------------------- \n");
printf("-- IO Command Count -- \n");
printf("---------------------- \n");
printf("%-9s\t\t%6s\n",
"Command", "Count");
printf("==============================\n");
foreach my $key (keys %CmdCounter) {
printf("%-9s\t\t%6d \n", $key, $CmdCounter{$key} );
}
printf(" \n\n");
# ================
# Write statistics
# ================
if (defined $CmdCounter{"write"} ) {
&Write_Statistics();
}
# ===============
# Read statistics
# ===============
#
if (defined $CmdCounter{"read"} ) {
&Read_Statistics();
}
# ================
# Close statistics
# ================
if (defined $CmdCounter{"close"} ) {
&Close_Statistics();
}
# ===============
# Open statistics
# ===============
if (defined $CmdCounter{"open"} ) {
&Open_Statistics();
}
# ==============================
# lseek unit activity statistics
# ==============================
if (defined $CmdCounter{"lseek"} ) {
&Lseek_Activity();
}
# ===============
# IOPS statistics
# ===============
$IOPS_Read_Final = 0;
$IOPS_Write_Final = 0;
$IOPS_Total_Final = 0;
printf("--------------------- \n");
printf("-- IOPS Statistics -- \n");
printf("--------------------- \n\n");
if (defined $CmdCounter{"write"} ) {
&IOPS_write_summary();
}
if (defined $CmdCounter{"read"} ) {
&IOPS_read_summary();
}
&IOPS_output();
# ===================
# Per File Statistics
# ===================
# Write Summary on a per unit basis
#if ( (defined $CmdCounter{"open"} ) && ($shortflag == 0) ) {
# &Per_File_Stats();
#}
if ( defined $CmdCounter{"open"} ) {
&Per_File_Stats();
}
# ==========
# ==========
# Data Files
# ==========
# ==========
&Data_File_Output();
#####################################################################################################################
#####################################################################################################################
#####################################################################################################################
################################################### Functions ###################################################
#####################################################################################################################
#####################################################################################################################
#####################################################################################################################
sub commify {
local $_ = shift;
1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
return $_;
}
sub commify2 {
# commify a number. Perl Cookbook, 2.17, p. 64
my $text = reverse $_[0];
$text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
return scalar reverse $text;
}
sub FileSizeStr {
my ($junk) = @_;
my $junk_str;
#printf("FileSizeStr function: junk = %s \n", $junk);
if ($junk < 1048576) {
$junk_str = sprintf("%3d",($junk/1000) );
$junk_str = $junk_str . "KB";
} elsif ($junk >= 1000000 && $junk < 1000000000 ) {
$junk_str = sprintf("%3d", ($junk/1000000) );
$junk_str = $junk_str . "MB";
} elsif ($junk >= 1000000000 && $junk < 1000000000000 ) {
$junk_str = sprintf("%3d", ($junk/1000000000) );
$junk_str = $junk_str . "GB";
} elsif ($junk >= 1000000000000) {
$junk_str = sprintf("%3d", ($junk/1000000000000) );
$junk_str = $junk_str . "TB";
} else {
$junk_str = sprintf("Are you sure that is correct? That is a huge file size");
}
return $junk_str;
}
sub helpoutput {
printf("Usage: strace-analyze [OPTION]... [FILE] \n");
printf("Analyzes strace output for IO functions. It creates statistics \n");
printf("on IO functions and performance of the read and write functions.\n");
printf("The strace file should have been run with 'strace -T -ttt [PROGRAM] \n");
printf(" \n");
printf(" -d Debug - echo the input lines to stdout and provide debugging information\n");
printf(" -debug same as -d \n");
printf(" --d same as -d \n");
printf(" --debug same as -d \n");
printf(" -h Produces help output (this message) \n");
printf(" -help same as -h \n");
printf(" --h same as -h \n");
printf(" --help same as -h \n");
printf(" -dat Produce .dat files for plotting \n");
printf(" --dat same as -dat \n");
printf(" -short Short version of output \n");
printf(" --short same as -short \n");
}
sub Open_Processing {
# Sample:
# 1252621029.776202 open("/etc/ld.so.cache", O_RDONLY) = 3 <0.000017>
# **** Split $cmdtmp to get the file name
($before, $filename, $after) = split('"', $cmdtmp);
if ($debug > 0) {
foreach my $specific_part (@parts) {
printf(STRACE_LOG " specific_part: %s \n",$specific_part);
}
}
# **** Find unit associated with open function (after "=")
$iloop = 0;
foreach my $specific_part (@parts) {
if ($iloop == 1) {
$junk = $specific_part;
$iloop = 0;
}
if ($specific_part eq "=") { $iloop = 1; }
}
$unit = $junk;
# If $unit is negative, then open function was not successful
if ($debug > 0) {
if ($unit < 0) {
printf(STRACE_LOG " Open did not succeed on fd: %d So not adding fd to statistics \n", $unit);
} else {
printf(STRACE_LOG " unit: %d \n",$unit);
}
}
# If unit is positive (i.e. it was successfully opened)
if ($unit > 0)
{
# Increment the open counter (number of open function calls)
$CmdCounter{"open"}++;
# Update Maxmimum open time (if necessary)
if ($elapsed_time > $OpenMax{"MaxTime"} ) {
$OpenMax{"MaxTime"} = $elapsed_time;
$OpenMax{"line"} = $LineNum - 1;
}
# **** Check if filename already exists (stored by unit):
# @Open_Filename[$unit] = $filename;
if (defined $Open_Filename[$unit]) {
if ($Open_Filename[$unit] eq $filename) {
printf(STRACE_LOG "*** Warning: Filename %s for unit %s already exists \n",$filename, $unit);
} else {
printf(STRACE_LOG "*** Comment: unit %s is being reused for new file name %s \n", $unit, $filename);
}
} else {
# File name doesn't exist so add it to hash
$Open_Filename[$unit] = $filename;
}
if ($debug > 0) {
printf(STRACE_LOG " filename: %s \n",$filename);
}
# **** File open options (oflags)
if ($parts[1] eq "=") {
($junk1, $junk2)=split(/\)/,$parts[0]);
$oflags = $junk1;
$mode = "";
} elsif ($parts[2] eq "=") {
#printf(" second option \n");
($junk1, $junk2)=split(/,/,$parts[0]);
$oflags = $junk1;
($junk1, $junk2)=split(/\)/,$parts[1]);
$mode = $junk1;
}
if ($debug > 0) {
printf(STRACE_LOG " oflags: %s \n",$oflags);
printf(STRACE_LOG " mode: %s \n",$mode);
}
# Add data to Open hash
$Open[$ielement+1]->{line_number} = $LineNum;
$Open[$ielement+1]->{sec} = $sec;
$Open[$ielement+1]->{file} = $filename;
$Open[$ielement+1]->{unit} = $unit;
$Open[$ielement+1]->{elapsed_time} = $zero;
$temp = floor($sec - $BeginTime) + 1;
$IOPS_Total[$temp]++;
$File_Stats[$unit]->{file} = $filename;
$File_Stats[$unit]->{read_bytes} = 0;
$File_Stats[$unit]->{write_bytes} = 0;
$File_Stats[$iloop]->{read_rate_count} = 0;
$File_Stats[$iloop]->{read_rate_sum} = 0;
$File_Stats[$iloop]->{write_rate_sum} = 0;
$File_Stats[$iloop]->{write_rate_count} = 0;
# Add line to simulator output
# Check if number of cols in $unit is greater than zero
# If so, then $unit has been used before - write warning to log
# but don't do anything else (just now).
#
# Current length of the $unit-th row
$junk1 = $#{$Offset[$unit]} + 1; # Number of Cols.
if ($junk1 > 0) {
printf(STRACE_LOG "*** WARNING: In open_processing. unit = %d has been used before \n", $unit);
printf(STRACE_LOG " Number of columns in Offset array is = %d \n", $junk1);
printf(STRACE_LOG " It should be zero \n");
}