-
Notifications
You must be signed in to change notification settings - Fork 3
/
lpcpu.sh
executable file
·1348 lines (1137 loc) · 47.5 KB
/
lpcpu.sh
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
#!/bin/bash
#
# LPCPU (Linux Performance Customer Profiler Utility): ./lpcpu.sh
#
# (C) Copyright IBM Corp. 2018
#
# This file is subject to the terms and conditions of the Eclipse
# Public License. See the file LICENSE.TXT in the main directory of the
# distribution for more details.
#
# Linux Performance Customer Profiler Utility (LPCPU)
#
# the overridable options can be specified like:
# lpcpu.sh profilers="vmstat iostat" duration=60
#
# Copyright (c) IBM Corporation, 2014. All rights reserved.
VERSION_STRING="356c8306d2c85f6af89dc2b85c151f4bbd9e9c63 2018-07-25 16:45:06 -0500"
## overridable values (with defaults) ##############################################################
#
# We recommend you override these values on the command line, not by modifying the script
#
################################################
#
# The common parameters to override.
#
# List of profilers to use.
# oprofile: see README for additional options
# perf: See README for additional options
# The following are the default profilers to use
profilers="sar iostat mpstat vmstat top meminfo interrupts"
# list of profilers to add in addition to the defaults
extra_profilers=""
# Duration of the profiler run, in seconds.
duration=120
# A command to run, if this is specified then the command is run and profiled from start
# to finish instead of profiling for the length of $duration
cmd=""
# where to create the output data (a compressed tar ball)
output_dir="/tmp"
# optional directory name to use in the output_dir, otherwise defaults to LPCPU naming scheme
dir_name=""
# Duration between profiler samples (does not apply to some profilers)
interval=5
# Files to include in summary.html
link_files=""
# should the resulting data be packaged into a compress tarball or left alone. valid values are "yes" or "no"
package_results="yes"
################################################
#
# oprofile and perf specific parameters
# Use callgraph on oprofile or perf
callgraph="no"
# use oprofile separate feature
oprofile_separate="yes"
# which flags to pass to oprofile separate
oprofile_separate_flags="lib,kernel"
# specific PID for oprofile to focus on
oprofile_pid=""
# if you absolutely positively cannot find the Linux kernel rpms
# we will of course ask for this later
# oprofile_kernel=--no-vmlinux
oprofile_kernel=""
# specify specific hardware counters to oprofile
# the counters should be specified in the same form as opcontrol accepts them
# for example: oprofile_hw_counters="-e <counter name>:<count>"
# or: oprofile_hw_counters="-e <counter 1 name>:<count> -e <counter 2 name>:<count>"
ARCH=`uname -m`
if [ "$ARCH" == "ppc64" -o "$ARCH" == "ppc64le" ]; then
# http://www.ibm.com/developerworks/opensource/library/l-evaluatelinuxonpower
# the recommended default override
oprofile_hw_counters="-e PM_RUN_CYC_GRP1:500000"
#
# for normal cycles
# oprofile_hw_counters="-e PM_CYC_GRP1:1000000"
#
# for cycles per instruction
# oprofile_hw_counters="-e PM_CYC_GRP1:1000000 -e PM_INST_CMPL_GRP1:1000000"
#
# for cycles per instruction based on run_cycles
# oprofile_hw_counters="-e PM_RUN_CYC_GRP1:500000 -e PM_RUN_INST_CMPL_GRP1:500000"
else
oprofile_hw_counters=""
fi
# control the frequency at which perf samples are collected
perf_frequency=""
# default to all cpus
perf_cpu=""
# create perf annotated report (default is no, "yes" to enable)
perf_annotate=""
################################################
#
# unique special case parameters
# MySQL Account info
MYSQL_USER=""
MYSQL_PASSWORD=""
# data collection flags, used to provide functionality with Autobench postprocessing scripts
id="default"
# no reason to modify this unless you know what you are doing
RUN_NUMBER="001"
# debugfs mount reference count
DEBUGFS_USERS=0
DEBUGFS_UNMOUNT=0
## argument import loop ############################################################################
# This loop takes the command line input variable (CLI) and sets the bash script variables
startup_output_log=""
for arg; do
export "$arg"
startup_output_log="${startup_output_log}Importing CLI variable : $arg\n"
done
## post argument important fixes ###################################################################
profilers="$profilers $extra_profilers"
## fixup configuration conflicts ###################################################################
# pmu conflicts with perf, oprofile, and cmd
if [[ " $profilers " =~ " pmu " && ( " $profilers " =~ " perf " || " $profilers " =~ " oprofile " || "$cmd" != "" ) ]]; then
echo "ERROR: profiler \"pmu\" conflicts with \"perf\", \"oprofile\", and \"cmd\"."
exit 1
fi
# pmu needs to run at least 120 sec or longer
if [[ " $profilers " =~ " pmu " && ( " $duration " -lt " 120 " ) ]]; then
echo "ERROR: profiler \"pmu\" requires a duration of at least 120 seconds."
exit 1
fi
if [ -n "$oprofile_pid" ]; then
startup_output_log="${startup_output_log}\nUsing oprofile_pid=$oprofile_pid [`sed -e 's/\x0/ /g' /proc/$oprofile_pid/cmdline`]\n"
startup_output_log="${startup_output_log}Profiling a specific PID using Oprofile requires --separate=thread => fixing\n"
export "oprofile_separate=yes"
export "oprofile_separate_flags=thread"
fi
## non-overridable defined values ##################################################################
# Location to store output data.
NAME=$(hostname -s)
TODAY=$(date +"%F_%H%M")
if [ -z "${dir_name}" ]; then
LOGDIR_NAME=lpcpu_data.$NAME.$id.$TODAY
else
LOGDIR_NAME=${dir_name}
fi
LOGDIR=$output_dir/$LOGDIR_NAME
mkdir -p $LOGDIR
## utility functions ###############################################################################
function debugfs_mount() {
# checking and mounting debugfs and enabling trace
DEBUGFS=$(awk '($3 == "debugfs") {print $2}' < /proc/mounts)
if [ -z "$DEBUGFS" ]; then
DEBUGFS=/sys/kernel/debug
mount -t debugfs debugfs $DEBUGFS >${LOGDIR}/lpcpu.out 2>&1 && DEBUGFS_UNMOUNT=1
fi
DEBUGFS_USERS=$((DEBUGFS_USERS+1))
}
function debugfs_unmount() {
DEBUGFS_USERS=$((DEBUGFS_USERS-1))
if [ "$DEBUGFS_UNMOUNT" -eq 1 -a "$DEBUGFS_USERS" -eq 0 ]; then
umount "$DEBUGFS"
DEBUGFS_UNMOUNT=0
fi
}
## mysql ###########################################################################################
function setup_mysql() {
echo "Setting up MySQL."
if [ -z "$(which mysql)" ]; then
echo "ERROR: MySQL is not installed."
exit 1
fi
if [ -z "$MYSQL_USER" ]; then
echo "ERROR: Please specify the account to connect to MySQL with by running 'export MYSQL_USER=<username>'"
exit 1
fi
mkdir $LOGDIR/mysql-profiler.$id.$RUN_NUMBER
if ! mysql -u $MYSQL_USER ${MYSQL_PASSWORD:+"--password=$MYSQL_PASSWORD"} -e "show global variables" > $LOGDIR/mysql-profiler.$id.$RUN_NUMBER/variables; then
echo "ERROR: Unable to retrieve MySQL global variables. Is a password required for $MYSQL_USER to connect?"
echo "ERROR: Please specify the password to connect to MySQL with by running 'export MYSQL_PASSWORD=<password>'"
exit 1
fi
}
function mysql_profiler() {
local mysql_profile_counter=0
trap "echo 'mysql_profiler : Received quit signal'; exit" SIGINT SIGTERM
while [ 1 ]; do
local pre=`printf "%06d" $mysql_profile_counter`
mysql -u $MYSQL_USER ${MYSQL_PASSWORD:+"--password=$MYSQL_PASSWORD"} -e "show global status;" \
> $LOGDIR/mysql-profiler.$id.$RUN_NUMBER/status.$pre
sleep $interval
(( mysql_profile_counter += $interval ))
done
}
function start_mysql() {
echo "Starting MySQL."
mysql_profiler &
MYSQL_PROFILER_PID=$!
disown $MYSQL_PROFILER_PID
}
function stop_mysql() {
echo "Stopping MySQL."
kill $MYSQL_PROFILER_PID
}
function report_mysql() {
echo "Postprocessing MySQL."
}
function setup_postprocess_mysql() {
echo '${LPCPUDIR}/postprocess/postprocess-mysql.pl .'" $id.$RUN_NUMBER"
}
## oprofile ########################################################################################
function setup_oprofile() {
echo "Setting up oprofile."
if [ -z "$(which opcontrol)" ]; then
echo "ERROR: Oprofile is not installed."
## Add check here for Advance toolchain.
exit 1
fi
if [ -z "$oprofile_kernel" ]; then
KERNEL="$(uname -r)"
if [ -f "/boot/vmlinux-${KERNEL}" ]; then
VMLINUX="--vmlinux=/boot/vmlinux-${KERNEL}"
elif [ -f "/boot/vmlinux-${KERNEL}.gz" ]; then
# This gunzip step is classically what is done on the SLES distros
gunzip -c "/boot/vmlinux-${KERNEL}.gz" > "/tmp/vmlinux-${KERNEL}"
VMLINUX="--vmlinux=/tmp/vmlinux-${KERNEL}"
elif [ -f "/usr/lib/debug/lib/modules/${KERNEL}/vmlinux" ]; then
VMLINUX="--vmlinux=/usr/lib/debug/lib/modules/${KERNEL}/vmlinux"
else
echo "ERROR: Cannot find the vmlinux file for the running kernel (${KERNEL})."
if [ -f "/etc/redhat-release" ]; then
echo " On RedHat, you should find and install the kernel-debuginfo*.rpm files"
echo " These RPM files are typically on the optional DVD for your hardware platform."
elif [ -f "/etc/SuSE-release" ]; then
echo " On SLES, this should have been caught in the gunzip step."
else
echo " This script expects the symbol enabled vmlinux kernel to be available"
fi
echo " Please do not modify the script to bypass this checking."
exit 1
fi
else
VMLINUX=$oprofile_kernel
fi
opcontrol --deinit
if [ -e /proc/sys/kernel/nmi_watchdog ]; then
# The nmi watchdog uses some resources that oprofile needs
echo 0 >/proc/sys/kernel/nmi_watchdog
fi
modprobe oprofile
opcontrol --shutdown
rm -rf /var/lib/oprofile/samples/current
rm -f /var/lib/oprofile/samples/oprofiled.log
rm -f ~/.oprofile/daemonrc
opcontrol $VMLINUX $oprofile_hw_counters
if [ "$oprofile_separate" == "yes" ]; then
opcontrol --separate=$oprofile_separate_flags
fi
if [ "$callgraph" == "yes" ]; then
opcontrol --callgraph=10
else
opcontrol --callgraph=0
fi
opcontrol --init
opcontrol --status
}
function start_oprofile() {
echo "starting oprofile."$id"" | tee -a $LOGDIR/profile-log.$RUN_NUMBER
opcontrol --start && opcontrol --reset
}
function stop_oprofile() {
echo "Stopping oprofile."
opcontrol --dump
opcontrol --stop
}
function report_oprofile() {
echo "Processing oprofile data."
mkdir $LOGDIR/oprofile.breakout.$id.$RUN_NUMBER
if [ "$oprofile_separate_flag" == "thread" -o -n "$oprofile_pid" ]; then
opreport --merge tgid > $LOGDIR/oprofile-brief.$id.$RUN_NUMBER 2>&1
if [ -n "$oprofile_pid" ]; then
opreport tgid:$oprofile_pid > $LOGDIR/oprofile-brief.pid.$oprofile_pid.$id.$RUN_NUMBER 2>&1
fi
else
opreport > $LOGDIR/oprofile-brief.$id.$RUN_NUMBER 2>&1
fi
OPRPT_PATH="/lib/modules/$(uname -r)/kernel"
if [ -d /lib/modules/$(uname -r)/extra ]; then
OPRPT_PATH="${OPRPT_PATH},/lib/modules/$(uname -r)/extra"
fi
if [ -d /lib/modules/$(uname -r)/updates ]; then
OPRPT_PATH="${OPRPT_PATH},/lib/modules/$(uname -r)/updates"
fi
if [ -d /lib/modules/$(uname -r)/weak-updates ]; then
OPRPT_PATH="${OPRPT_PATH},/lib/modules/$(uname -r)/weak-updates"
fi
if [ "$oprofile_separate_flag" == "thread" -o -n "$oprofile_pid" ]; then
opreport --merge tgid -l -p $OPRPT_PATH > $LOGDIR/oprofile.$id.$RUN_NUMBER 2>&1
if [ -n"$oprofile_pid" ]; then
opreport tgid:$oprofile_pid -l -p $OPRPT_PATH > $LOGDIR/oprofile.pid.$oprofile_pid.$id.$RUN_NUMBER 2>&1
fi
else
opreport -l -p $OPRPT_PATH > $LOGDIR/oprofile.$id.$RUN_NUMBER 2>&1
fi
if [ "$callgraph" == "yes" ]; then
opreport --callgraph -l -p $OPRPT_PATH > $LOGDIR/oprofile-callgraph.$id.$RUN_NUMBER 2>&1
fi
opcontrol --shutdown
opcontrol --version > $LOGDIR/oprofile.breakout.$id.$RUN_NUMBER/oprofiled-log 2>&1
cat /var/lib/oprofile/samples/oprofiled.log >> $LOGDIR/oprofile.breakout.$id.$RUN_NUMBER/oprofiled-log 2>&1
}
function setup_postprocess_oprofile() {
echo '${LPCPUDIR}/postprocess/postprocess-oprofile .'" $id.$RUN_NUMBER"
}
## sar #############################################################################################
function setup_sar() {
echo "Setting up sar."
SAR=$(which sar)
if [ -z "$SAR" ]; then
echo "ERROR: sar is not installed. To correct this problem install the sysstat package for your distribution."
exit 1
fi
}
function start_sar() {
echo "starting sar."$id" ["$interval"]" | tee -a $LOGDIR/profile-log.$RUN_NUMBER
sar -o $LOGDIR/sar.bin.$id.$RUN_NUMBER $interval 100000 > $LOGDIR/sar.STDOUT 2> $LOGDIR/sar.STDERR &
SAR_PID=$!
disown $SAR_PID
}
function stop_sar() {
echo "Stopping sar."
kill $SAR_PID
}
function printsar() {
# Note: Not all of the requested reporting options are available across
# all versions of sar on the various distros and platforms.
# Some permutations may return errors. That's ok.
sar -$1 -f "$LOGDIR/sar.bin.$id.$RUN_NUMBER" > "$LOGDIR/sar.breakout.$id.$RUN_NUMBER/sar.$2" 2> "$LOGDIR/sar.breakout.$id.$RUN_NUMBER/sar.$2.STDERR"
}
function report_sar() {
echo "Processing sar data."
mkdir $LOGDIR/sar.breakout.$id.$RUN_NUMBER
sar -A -f $LOGDIR/sar.bin.$id.$RUN_NUMBER > $LOGDIR/sar.text.$id.$RUN_NUMBER
printsar b io_transfer_rate
printsar c process_creation
printsar w process_creation-context_switching
printsar d block_devices
printsar q run_queue_loadavg
printsar r memory
printsar u cpu_util
printsar v fs_tables
printsar w context_switching
printsar y tty_device
printsar B paging_stats
printsar R memory_rates
printsar W swapping
printsar "I SUM" irq_sum
# Some versions of sar have "FULL" as a value for the -n option,
# others use "ALL". Rather than doing tedious version checking
# to figure out which value should be used, just do both and send
# the error output to /dev/null. One will fail; the other will work.
printsar "n FULL" netdev 2>/dev/null
printsar "n ALL" netdev 2>/dev/null
if grep -q "processor\s[0-9]" /proc/cpuinfo; then
# this works on s390
ONLINE_PROCS=$(grep "^processor" /proc/cpuinfo | awk '{ print $2 }' | awk -F: '{ print $1 }')
else
# this works on x86 and PPC
ONLINE_PROCS=$(grep "^processor" /proc/cpuinfo | awk '{ print $3 }')
fi
if [ -n "${ONLINE_PROCS}" ]; then
for ivar in ${ONLINE_PROCS}; do
printsar "P ${ivar}" cpu_util_${ivar}
done
else
NR_CPUS=`cat /proc/cpuinfo | grep -c ^processor`
for ((ivar=0;ivar<NR_CPUS;ivar++)); do
printsar "P ${ivar}" cpu_util_${ivar}
done
fi
}
function setup_postprocess_sar() {
echo '${LPCPUDIR}/postprocess/postprocess-sar .'" $RUN_NUMBER $id"
}
## iostat ##########################################################################################
function setup_iostat() {
echo "Setting up iostat."
IOSTAT=$(which iostat)
if [ -z "$IOSTAT" ]; then
echo "ERROR: iostat is not installed. To correct this problem install the sysstat package for your distribution."
exit 1
fi
}
function start_iostat() {
echo "starting iostat."$id" ["$interval"] [mode=disks]" | tee -a $LOGDIR/profile-log.$RUN_NUMBER
iostat -x -k -t $interval > $LOGDIR/iostat.$id.$RUN_NUMBER &
IOSTAT_PID=$!
disown $IOSTAT_PID
}
function stop_iostat() {
echo "Stopping iostat."
kill $IOSTAT_PID
}
function report_iostat() {
echo "Processing iostat data."
}
function setup_postprocess_iostat() {
echo -n '${LPCPUDIR}/postprocess/postprocess-iostat --dir=.'" --run-number=$RUN_NUMBER --id=$id"
if [ -e "${LPCPUDIR}/tools/block-device-hierarchy.pl" ]; then
echo -n " --bdh=block-device-hierarchy.dat"
fi
echo
}
## proc-interrupts ##########################################################################################
function setup_interrupts() {
echo "Setting up proc-interrupts."
if [ ! -e "${LPCPUDIR}/tools/proc-interrupts.pl" ]; then
echo "ERROR: proc-interrupts.pl is not available. To correct this problem ensure that you have the entire LPCPU distribution or disable the interrupts profiler."
exit 1
fi
}
function start_interrupts() {
echo "starting proc-interrupts."$id" ["$interval"]" | tee -a $LOGDIR/profile-log.$RUN_NUMBER
${LPCPUDIR}/tools/proc-interrupts.pl $interval > $LOGDIR/proc-interrupts.$id.$RUN_NUMBER &
INTERRUPTS_PID=$!
disown $INTERRUPTS_PID
}
function stop_interrupts() {
echo "Stopping interrupts."
kill $INTERRUPTS_PID
}
function report_interrupts() {
echo "Processing interrupts data."
}
function setup_postprocess_interrupts() {
echo 'if [ -f ./system-topology.dump ]; then'
echo '${LPCPUDIR}/postprocess/postprocess-proc-interrupts .'" $RUN_NUMBER $id ./system-topology.dump"
echo 'else'
echo 'PROC_INTERRUPTS_NO_NUMA=1 ${LPCPUDIR}/postprocess/postprocess-proc-interrupts .'" $RUN_NUMBER $id"
echo 'fi'
}
## KVM ###############################################################################################
function setup_kvm() {
echo "Setting up KVM host profilers."
if [ ! -e "${LPCPUDIR}/tools/proc-cpu" -o ! -e "${LPCPUDIR}/tools/kvm-stat" -o ! -e "${LPCPUDIR}/tools/ksm.pl" ]; then
echo "ERROR: One the KVM related profilers requires a script that is not available. To correct this problem ensure that you have the entire LPCPU distribution or disable the KVM profiler."
exit 1
fi
debugfs_mount
if [ -n "`which virsh`" ]; then
echo " Capturing Libvirt XML for running guests"
mkdir ${LOGDIR}/libvirt-xml
for guest in `virsh list | grep running | awk '{ print $2 }'`; do
virsh dumpxml ${guest} > ${LOGDIR}/libvirt-xml/${guest}.xml
done
fi
}
function start_kvm() {
echo "Starting KVM host profilers"
echo "starting process-cpu.KVM-guests ["$interval"]" | tee -a $LOGDIR/profile-log.$RUN_NUMBER
${LPCPUDIR}/tools/proc-cpu -d $interval -r -i --qemu-guest-mode > $LOGDIR/process-cpu.KVM-guests.$RUN_NUMBER &
PROC_CPU_PID=$!
disown $PROC_CPU_PID
echo "starting kvmstat."$id" ["$interval"]" | tee -a $LOGDIR/profile-log.$RUN_NUMBER
${LPCPUDIR}/tools/kvm-stat log=yes timestamps=yes interval=${interval} >> $LOGDIR/kvmstat.$id.$RUN_NUMBER &
KVM_STAT_PID=$!
disown $KVM_STAT_PID
echo "starting ksm."$id" ["$interval"]" | tee -a $LOGDIR/profile-log.$RUN_NUMBER
${LPCPUDIR}/tools/ksm.pl $interval > $LOGDIR/ksm.$id.$RUN_NUMBER &
KSM_PID=$!
disown $KSM_PID
}
function stop_kvm() {
echo "Stopping KVM host profilers."
kill $PROC_CPU_PID
kill $KVM_STAT_PID
kill $KSM_PID
debugfs_unmount
}
function report_kvm() {
echo "Processing KVM host profiler data."
}
function setup_postprocess_kvm() {
echo '${LPCPUDIR}/postprocess/postprocess-process-cpu .'" $RUN_NUMBER KVM-guests"
echo '${LPCPUDIR}/postprocess/postprocess-kvmstat .'" $RUN_NUMBER $id"
echo '${LPCPUDIR}/postprocess/postprocess-ksm .'" $RUN_NUMBER $id"
}
## meminfo ##########################################################################################
function setup_meminfo() {
echo "Setting up meminfo."
}
function start_meminfo() {
echo "starting meminfo."$id" ["$interval"] " | tee -a $LOGDIR/profile-log.$RUN_NUMBER
MEMINFO_WATCH_OUTPUT_FILE=$LOGDIR/meminfo-watch.$id.$RUN_NUMBER
while [ 1 ]; do
echo "============================= SAMPLE =============================" >> ${MEMINFO_WATCH_OUTPUT_FILE}
date >> ${MEMINFO_WATCH_OUTPUT_FILE}
echo >> ${MEMINFO_WATCH_OUTPUT_FILE}
cat /proc/meminfo >> ${MEMINFO_WATCH_OUTPUT_FILE}
for i in `ls -1d /sys/devices/system/node/node* 2>/dev/null`; do
echo "--" >> ${MEMINFO_WATCH_OUTPUT_FILE}
cat $i/meminfo >> ${MEMINFO_WATCH_OUTPUT_FILE}
done
echo >> ${MEMINFO_WATCH_OUTPUT_FILE}
sleep $interval
done &
MEMINFO_PID=$!
disown $MEMINFO_PID
}
function stop_meminfo() {
echo "Stopping meminfo."
kill $MEMINFO_PID
}
function report_meminfo() {
echo "Processing meminfo data."
}
function setup_postprocess_meminfo() {
echo '${LPCPUDIR}/postprocess/postprocess-meminfo-watch .'" $RUN_NUMBER $id"
}
## vmstat ##########################################################################################
function setup_vmstat() {
echo "Setting up vmstat."
VMSTAT=$(which vmstat)
if [ -z "$VMSTAT" ]; then
echo "ERROR: vmstat is not installed."
exit 1
fi
}
function start_vmstat() {
echo "starting vmstat."$id" ["$interval"]" | tee -a $LOGDIR/profile-log.$RUN_NUMBER
vmstat $interval | ${LPCPUDIR}/tools/output-timestamp.pl > $LOGDIR/vmstat.$id.$RUN_NUMBER &
VMSTAT_PID=$!
disown $VMSTAT_PID
}
function stop_vmstat() {
echo "Stopping vmstat."
kill $VMSTAT_PID
}
function report_vmstat() {
echo "Processing vmstat data."
}
function setup_postprocess_vmstat() {
echo '${LPCPUDIR}/postprocess/postprocess-vmstat .'" $RUN_NUMBER $id"
}
## top #############################################################################################
function setup_top() {
echo "Setting up top."
TOP=$(which top)
if [ -z "$TOP" ]; then
echo "ERROR: top is not installed."
exit 1
fi
}
function start_top() {
echo "Starting top."
top -b -d $interval -H > $LOGDIR/top.$id.$RUN_NUMBER &
TOP_PID=$!
disown $TOP_PID
}
function stop_top() {
echo "Stopping top."
kill $TOP_PID
}
function report_top() {
echo "Processing top data."
}
function setup_postprocess_top() {
link_files="top.$id.$RUN_NUMBER $link_files"
echo
}
## mpstat ##########################################################################################
function setup_mpstat() {
echo "Setting up mpstat."
MPSTAT=$(which mpstat)
if [ -z "$MPSTAT" ]; then
echo "ERROR: mpstat is not installed. To correct this problem install the sysstat package for your distribution."
exit 1
fi
if mpstat --help 2>&1 | grep -q "\[ -P { <cpu>.*ON.* ALL } \]"; then
MPSTAT_PROCESSOR_SELECTION="ON"
else
MPSTAT_PROCESSOR_SELECTION="ALL"
fi
}
function start_mpstat() {
echo "starting mpstat.$id ["$interval"]" | tee -a $LOGDIR/profile-log.$RUN_NUMBER
mpstat -P ${MPSTAT_PROCESSOR_SELECTION} $interval > $LOGDIR/mpstat.$id.$RUN_NUMBER &
MPSTAT_PID=$!
disown $MPSTAT_PID
}
function stop_mpstat() {
echo "Stopping mpstat."
kill $MPSTAT_PID
}
function report_mpstat() {
echo "Processing mpstat data."
}
function setup_postprocess_mpstat() {
echo 'if [ -f ./system-topology.dump ]; then'
echo '${LPCPUDIR}/postprocess/postprocess-mpstat . '" $RUN_NUMBER $id ./system-topology.dump"
echo 'else'
echo 'MPSTAT_NO_NUMA=1 ${LPCPUDIR}/postprocess/postprocess-mpstat .'" $RUN_NUMBER $id"
echo 'fi'
}
## perf ##########################################################################################
function setup_perf() {
echo "Setting up perf."
PERF=$(which perf)
if [ -z "$PERF" ]; then
echo "ERROR: perf is not installed."
exit 1
fi
echo $profilers | grep oprofile > /dev/null
if [ $? == 0 ]; then
echo "ERROR: perf and oprofile can not run at same time."
exit 1
fi
}
function start_perf() {
local perf_cmd
echo "starting perf" | tee -a $LOGDIR/profile-log.$RUN_NUMBER
perf_cpu_arg="-a"
if [ -n "$perf_cpu" ]; then
perf_cpu_arg="--cpu=$perf_cpu"
fi
perf_cmd="perf record $perf_cpu_arg -o $LOGDIR/perf_data.$RUN_NUMBER"
if [ "$callgraph" = "yes" ]; then
perf_cmd="$perf_cmd -g"
echo "perf using callgraph" | tee -a $LOGDIR/profile-log.$RUN_NUMBER
fi
if [ -n "$perf_frequency" ]; then
perf_cmd="$perf_cmd -F $perf_frequency"
echo "perf using user specified frequency of [$perf_frequency]" | tee -a $LOGDIR/profile-log.$RUN_NUMBER
fi
echo "using perf command [$perf_cmd]" | tee -a $LOGDIR/profile-log.$RUN_NUMBER
$perf_cmd &
PERF_PID=$!
disown $PERF_PID
}
function stop_perf() {
echo "Stopping perf."
kill -SIGINT $PERF_PID
}
function report_perf() {
echo "Processing perf data."
if [ "$callgraph" = "yes" ]; then
perf report -n -g flat,100 -i $LOGDIR/perf_data.$RUN_NUMBER > $LOGDIR/perf_report.$RUN_NUMBER
perf report -n -g -i $LOGDIR/perf_data.$RUN_NUMBER > $LOGDIR/perf_report-callgraph.$RUN_NUMBER
else
perf report -n -i $LOGDIR/perf_data.$RUN_NUMBER > $LOGDIR/perf_report.$RUN_NUMBER
fi
if [ "$perf_annotate" = "yes" ]; then
perf annotate -i $LOGDIR/perf_data.$RUN_NUMBER > $LOGDIR/perf_annotated.$RUN_NUMBER
fi
}
function setup_postprocess_perf() {
echo "mkdir perf-processed.$RUN_NUMBER"
echo "pushd perf-processed.$RUN_NUMBER > /dev/null"
echo "echo \"<html><head><title>Perf files for $RUN_NUMBER</title></head><body>\" > chart.html"
echo "counter=1"
echo "for file in \`find ../perf_report*.$RUN_NUMBER -maxdepth 0 -type f\`; do"
echo " echo \"\$counter : <a href='\$file'>\" >> chart.html"
echo " echo \$file | sed -e 's|../||' >> chart.html"
echo " echo \"</a><br/>\" >> chart.html"
echo " (( counter += 1 ))"
echo "done"
echo "echo \"</body></html>\" >> chart.html"
echo "popd > /dev/null"
}
## iotop #############################################################################################
function setup_iotop() {
echo "Setting up iotop."
TOP=$(which iotop)
if [ -z "$TOP" ]; then
echo "ERROR: iotop is not installed."
exit 1
fi
}
function start_iotop() {
echo "Starting iotop."
iotop -bto -d $interval > $LOGDIR/iotop.$id.$RUN_NUMBER &
IOTOP_PID=$!
disown $IOTOP_PID
}
function stop_iotop() {
echo "Stopping iotop."
kill $IOTOP_PID
}
function report_iotop() {
echo "Processing iotop data."
}
function setup_postprocess_iotop() {
link_files="iotop.$id.$RUN_NUMBER $link_files"
echo
}
## secfs ##########################################################################################
## Thales/Vormetric Transparent Encryption Agent (VTE) Support
function setup_secfs() {
echo "Setting up secfs profiling."
SECFSD=$(which secfsd)
if [ -z "$SECFSD" ]; then
echo "ERROR: VTE is not installed."
exit 1
fi
}
function start_secfs() {
echo "starting secfs."$id" ["$interval"] " | tee -a $LOGDIR/profile-log.$RUN_NUMBER
secfsd -status guard > $LOGDIR/secfs-guards
secfsd -status guard -v > $LOGDIR/secfs-guards_v
voradmin cmd profile_on
SECFS_WATCH_OUTPUT_FILE=$LOGDIR/secfs-watch.$id.$RUN_NUMBER
SECFS_IO_OUTPUT_FILE=$LOGDIR/secfs-io.$id.$RUN_NUMBER
SECFS_READ_OUTPUT_FILE=$LOGDIR/secfs-read.$id.$RUN_NUMBER
SECFS_WRITE_OUTPUT_FILE=$LOGDIR/secfs-write.$id.$RUN_NUMBER
while [ 1 ]; do
echo "============================= SAMPLE =============================" >> ${SECFS_WATCH_OUTPUT_FILE}
date >> ${SECFS_WATCH_OUTPUT_FILE}
echo >> ${SECFS_WATCH_OUTPUT_FILE}
secfsd -profile show | cat >> ${SECFS_WATCH_OUTPUT_FILE}
secfsd -profile clear
echo >> ${SECFS_WATCH_OUTPUT_FILE}
echo "============================= SAMPLE =============================" >> ${SECFS_IO_OUTPUT_FILE}
date >> ${SECFS_IO_OUTPUT_FILE}
echo >> ${SECFS_IO_OUTPUT_FILE}
cat /proc/fs/secfs/io_op_counters >> ${SECFS_IO_OUTPUT_FILE}
echo >> ${SECFS_IO_OUTPUT_FILE}
echo "============================= SAMPLE =============================" >> ${SECFS_READ_OUTPUT_FILE}
date >> ${SECFS_READ_OUTPUT_FILE}
echo >> ${SECFS_READ_OUTPUT_FILE}
cat /proc/fs/secfs/read_histograms >> ${SECFS_READ_OUTPUT_FILE}
echo >> ${SECFS_READ_OUTPUT_FILE}
echo "============================= SAMPLE =============================" >> ${SECFS_WRITE_OUTPUT_FILE}
date >> ${SECFS_WRITE_OUTPUT_FILE}
echo >> ${SECFS_WRITE_OUTPUT_FILE}
cat /proc/fs/secfs/write_histograms >> ${SECFS_WRITE_OUTPUT_FILE}
echo >> ${SECFS_WRITE_OUTPUT_FILE}
sleep $interval
done &
SECFS_PID=$!
disown $SECFS_PID
}
function stop_secfs() {
echo "Stopping secfs profiling."
kill $SECFS_PID
voradmin cmd profile_off
}
function report_secfs() {
echo "Processing secfs data."
}
function setup_postprocess_secfs() {
echo ""
}
## tcpdump ##########################################################################################
function setup_tcpdump() {
echo "Setting up tcpdump."
}
function start_tcpdump() {
echo "Starting tcpdump."
tcpdump -s256 -c500000 -B130000 -w $LOGDIR/tcpdump.pcap -nnvvi any &
TCPDUMP_PID=$!
disown $TCPDUMP_PID
}
function stop_tcpdump() {
echo "Stopping tcpdump."
kill -9 $TCPDUMP_PID
}
function report_tcpdump() {
echo "processing tcpdump."
}
function setup_postprocess_tcpdump() {
echo "echo Postprocessing tcpdump."
echo "/usr/sbin/tcpdump -r ./tcpdump.pcap"
}
## ftrace ##########################################################################################
function setup_ftrace() {
echo "Setting up ftrace."
debugfs_mount
> "$DEBUGFS"/tracing/trace # zero out trace buffer
#end of trace enabling
}
function start_ftrace() {
echo "Starting ftrace."
DEFAULT_BUFFER_SIZE=$(awk '{print $1}' < $DEBUGFS/tracing/buffer_size_kb)
echo 1 > $DEBUGFS/tracing/events/enable #enable all trace events
echo 256000 > $DEBUGFS/tracing/buffer_size_kb
echo 1 > $DEBUGFS/tracing/tracing_on #turn on tracing
}
function stop_ftrace() {
echo "Stopping ftrace."
#clean up after tracing
echo 0 > $DEBUGFS/tracing/tracing_on #turn off tracing
echo 0 > $DEBUGFS/tracing/events/enable #disable all trace events
}
function report_ftrace() {
echo "processing ftrace."
cat $DEBUGFS/tracing/trace >> $LOGDIR/ftrace.out
> $DEBUGFS/tracing/trace # zero out trace buffer
echo $DEFAULT_BUFFER_SIZE > $DEBUGFS/tracing/buffer_size_kb
debugfs_unmount
}
function setup_postprocess_ftrace() {
echo "echo Postprocessing ftrace."
}
## pmu ##########################################################################################
function setup_pmu() {
echo "Setting up pmu."
cmd="${LPCPUDIR}/tools/pmcount.sh ${duration} ${pmusets} > $LOGDIR/pmu.out 2>&1"
}
function start_pmu() {
echo "Starting pmu."
# pmu collection will be run as the lpcpu "cmd"
}
function stop_pmu() {
echo "Stopping pmu."
}
function report_pmu() {
echo "processing pmu."
}
function setup_postprocess_pmu() {
echo "echo Postprocessing pmu."
}
## Generic Functions ###############################################################################
# in normal SIGINT handling just log the signal and exit
function sigint_normal_trap() {
echo -e "\n\nCaught SIGINT --> exiting\n"
exit 1
}
# when the profilers are running and a SIGINT is received we log the
# SIGNAL but continue running to allow the profilers to be cleanly
# shutdown
# NOTE: This means that when profilers are running and a SIGINT is
# received the script continues to run
function sigint_running_trap() {
echo -e "\n\nCaught SIGINT --> stopping data collection\n"
}
####################################################################################################