-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtimep.bash
More file actions
3920 lines (3320 loc) · 354 KB
/
timep.bash
File metadata and controls
3920 lines (3320 loc) · 354 KB
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/env bash
if shopt extglob &>/dev/null; then
timep_extglobState='-s'
else
timep_extglobState='-u'
fi
shopt -s extglob
timep() {
## TIME Profile - timep efficiently produces an accurate per-command execution time profile for shell scripts and functions using DEBUG, EXIT and RETURN traps.
# timep logs command times+metadata hierarchically based on both function and subshell nesting depth, recreating the complete call-stack tree in its logs.
#
# USAGE: timep [-s|-f|-c] [-k] [-F|+F] [-o <type>] [--] _______ --OR--
# [...] | timep [-s|-f|-c] [-k] [-F|+F] [-o <type>] [--] _______ | [...]
#
# OUTPUT: timep generates 2 profiles of the code and, when enabled, several flamegraphs. These will be saved to disk in the "profiles" dir in timep's tmpdir directory (by default: /dev/shm/.timep/timep-XXXXXXXX -- printed to stderr at the end):
# 2 time profiles: "out.profile.full" and "out.profile"
# out.profile.full: contains all individual commands and metadata info like the chain of FUNCNAME's and the chain of subshell PIDs || [[ "${nn}" == *$'\n' ]]
# out.profile: commands repeated by loops have been collapsed into combined entries that show the number of times the command was repeated and the total run time from all of them
# if flamegraph generation is enabled, you will also get
# 2 flamegraph SVGs: "flamegraph.ALL.svg" and "flamegraph.ALL.R.svg"
# these are both "quad-stack" 4-in-1 flamegraphs. They contain the same information but are arranged/grouped differently.
# the flamegraphs that were used to build these quad-stacked ones are also available in the "flamegraphs" sub-directory in the "profiles" dir.
# 2 stack traces intended to be passed to "timep_flamegraph.pl": "out.flamegraph.full" and "out.flamegraph"
# out.flamegraph.full: contains stack traces from all commands
# out.flamegraph: contains "folded" stack traces where the times from otherwise identical stack traces have been summed together in a single stack trace
# ("timep_flamegraph.pl" is a modified version of "flamegraph.pl" from Brendan Gregg's "FlameGraph" repo at "https://github.com/brendangregg/FlameGraph")
#
# NOTE: timep will create a symbolic link to the "profiles" dir in your PWD called 'timep.profiles'
#
# FLAGS: Flags must be given before the command being profiled. All flags are optional.
# -s | --script : force timep to treat the code being profiled as a bash script
# -f | --function : force timep to treat the code being profiled as a bash function
# -c | --command : force timep to treat the code being profiled as raw bash command[s]
# NOTE: If multiple [-s|-f|-c] flags are given, the last one is used.
#
# DEFAULT: Attempt to detect type automatically. Detection roughly follows the following decision tree:
# 1. if $1 matches a loaded function (tested via declare -F), then treat as a function (f)
# 2. if $1 is not a function but exists as a file in the filestystem that ut executable and containsa ascii text, then treat as a script (s)
# 3. if neither of the above are true, then treat as raw command[s] (c)
#
# -k | --keep : do not remove all the intermediate logs and scripts in timep's trmpdir (everything except the "profiles" dir) after timep is finished running. (DEFAULT is to delete everything except the final output profiles + flamegraph files)
#
# -t | --time : Run the code being profiled through `time` to get the standard wallclock / user / sys times for the code that was profiles (in addition to all the timep-generated profiles)
#
# -F | --flame | --flamegraph : automatically generate a flamegraph using Flamegraph.pl and save them in the "profiles" dir
# +F | ++flame | ++flamegraph : do NOT automatically generate a flamegraph using Flamegraph.pl and save them in the "profiles" dir
#
# NOTE: you can choose whether or not to generate flamegraphs by default by setting the timep_GENERATE_FLAMEGRAPHS_BY_DEFAULT variable at the very top of thje script.
# If this is set to any non-empty value, flamegraphs will be generated automatically unless the +F | ++flame | ++flamegraph flag is passed (the [+=]F flag, if passed, will always override the timep_GENERATE_FLAMEGRAPHS_BY_DEFAULT var)
#
# -- : stop arg parsing (allows profiling something with the same name as a flag)
#
# -o <type> | --output=<type> : tell timep which type of profile(s) to print to stdout.
# pass a comma-seperated list to output more than one profile type.
# set <type> as empty ('') to not print any profiles.
# <type> : p --> out.profile (DEFAULT) pf --> out.profile.full f --> out.flamegraph ff -> out.flamegraph.full
# NOTE: all 4 profiles will always be available on disk after profiling is finished in timep's tmpdir
#
# --setup[="<flag>[,<flag>]"] : alias for `_timep_setup [<flags>]`. this will set up the timep.so loadable and the timep_flamegraph.pl script. valid <flag>s (passed in quoted comma-seperated list) are '--download[=[local,]<branch>]', '--output[=<path>]', and '--force' .
# --extract[="<flag>[,<flag>]"] : same as `--setup`, except that it will additionally copy the timep.so loadable and the timep_flamegraph.pl script to $PWD. NOTE: default install path is under /dev/shm/.timep/lib/$USER-$EUID/ . See the _timep_setup header (bottom of this script) for more info.
#
# RUNTIME CONDITIONS/REQUIREMENTS:
# timep adds a several variables (all which start with "timep_") + function(s) to the runtime env of whatever is being profiled. The code being profiled must NOT modify these.
# FUNCTIONS: _timep_* trap
# VARIABLES: timep_*
#
# timep works by using DEBUG, EXIT and RETURN traps.
#
# To allow profiling bash code which *also* sets these traps, timep defines a `trap` function to overload the builtin `trap` and will automatically change any `builtin trap ...` commands into `trap ...`
# This function will incorporate the traps required by timep into the traps set by the bash code.
# For timep to work correctly, any EXIT/RETURN/DEBUG traps set by the code being profiled must NOT be set using `builtin trap` - the overloaded `trap` function must be used
#
# for timep to properly reconstruct the true call-stack tree, job control (set -m) MUST be enabled.
# timep will automaticaly enable job control and, should the code being profiled disable it, timep will automatically re-enable it.
# Codes that require job control to be disabled cannot be profiled with timep.
#
# DEPENDENCIES:
# 1) bash 5.0+ (required to support the $EPOCHREALTIME variable)
# 2) mounted proc filesystem at '/proc'
# 3) REQUIRED binaries: cat chmod find grep mkdir mv rm sed sort uniq
# 4) OPTIONAL binaries (needed for extra/enhanced/optional functionality): ln file [realpath|readlink] [wget|curl]
# 5) accurate cpu time measrements require the use of a loadable builtin. currently, this is supported on x86_64, aarch64, armv7, ppc64le, s390x, and riscv. timep will try to use /proc/stat when this loadable builtin is not available, but the quality of the timing result will be significantly worse.
#
# NOTES:
# 1. timep attempts to find the raw source code for functions being profiled, but in some instances (example: functions defined via `. <(...)` or functions defined in terminal when history is off) this isnt possible...In these cases, `declare -f <func>` will be treated as the source, and the line numbers may not correspond exactly to the line numbers in the original code. Commamds are, however, still ordered correctly.
# 2. To define a custom TMPDIR (other than /dev/shm/.timep.XXXXXX), pass `TIMEP_TMPDIR` as an environment variable. e.g., TIMEP_TMPDIR=/path/to/tmpdir timep [...]
# 3. timep uses a loadable builtin to get accurate cpu time measureements. This loadable builtin's .so file is included in this timep.bash file as a compressed base64-encoded string. When timep.bash is sourced, this .so file will automatically be extracted and the loadable builtin will be enabled automatically.
#
# KNOWN LIMITATIONS / BUGS: timep handles virtually every aspect of the bash execution model, but there are a few edge cases where, due to the limitations of trap-based profiling, the output is slightly off.
# 1. In some deeply nested chains of combined subshells + background forks with multiple subshells + forks before the 1st command in the sequence, some commands may have an incorrect nesting level. That said, commands should still be grouped together roughly correctly, and will still have accurate timing info.
# 2. the times for tcommands that set traps is inflated. This is becausetimep overloads the trap command with a function to allow user-set traps to coexist with the traps used by timep, and the time you see is the time it takes the overloaded trap function to run.
#
################################################################################################################################################################
(
local timep_GENERATE_FLAMEGRAPHS_BY_DEFAULT=1
# check that basic requirements to run timep are met
# to disable this check, call timep via 'timep_DISABLE_CHECKS=1 timep <...>'
[[ ${timep_DISABLE_CHECKS} ]] || { [[ -f /proc/self/stat ]] && (( BASH_VERSINFO[0]>= 5 )) && [[ "$(uname)" == 'Linux' ]]; } || { printf '\n\nERROR: timep requires a Linux system with mounted procfs and bash 5+. ABORTING!\n\n' >&2; return 1; }
local -a missingA=(sed grep sort uniq perl cat chmod rm mkdir mv)
for nn in "${missingA[@]}"; do
type -p "$nn" &>/dev/null || { printf '\n\nERROR: timep requires %s. Please install it (or add it to your PATH if already installed) before running timep. ABORTING!\n\n' "$nn" >&2; return 1; }
done
unset missingA
shopt -s extglob
local IFS IFS0 nn nn0 nn1 jj kk kk0 kk1 kkd a a0 b u logPathCur nCPU nWorker nWorkerMax REPLY timep_coprocSrc timep_DEBUG_FLAG timep_DEBUG_IDS_FLAG timep_DEBUG_TRAP_STR_0 timep_DEBUG_TRAP_STR_1 timep_deleteFlag timep_EXIT_TRAP_STR timep_fd_done timep_LOCK_FD timep_fd_logID timep_flameGraphPath timep_LOG_NUM timep_noOutFlag timep_outType timep_PPID timep_PTY_FD_TEST timep_PTY_FLAG timep_PTY_PATH timep_RETURN_TRAP_STR timep_runCmd timep_runCmdPath timep_runSetupSrc timep_runVarsSrc timep_runMainSrc timep_wtimeALL timep_wTimeCur timep_runType timep_timeFlag timep_TITLE timep_TTY_NR timep_TTY_NR_TEST timep_CLOCK_GETTIME_FLAG timep_TITLE timep_funcName timep_wtimeALL timep_ctimeALL spacerN spacerN0 headerTXT a00 p1w p1c logPathCur jj0 a0 t n wTime cTime wTimeP cTimeP logCurTmp clktck svgCombineInd titlePad subtitlePad logHeader logCurTmp lineOrig tw pw tc pc cnt nd cind cmd wTime0 cTime0 d6 depthCur timep_flameGraphFlag trapAddCur timep_SIGNAL_RELAY_TRAP_STR
local -gx timep_TMPDIR timep_TMPDIR0 timep_FD0 timep_FD1 timep_FD2 fd_sleep timep_CPU_TIME_MULT timep_LOG_NESTING_CUR timep_LOG_NESTING_MAX timep_WTIME_CORRECTION timep_CTIME_CORRECTION timep_WTIME_DONE timep_CTIME_DONE logOut logOutL logOutLL
local -a pAll_PID timep_outTypeA kkNeed kkNeed0 timep_LOG_DELETE_CUR timep_setupFuncFlags flameGraphLogA
local -agx timep_LOG_NAME timep_LOG_NESTING timep_LOG_NESTING_IND
SECONDS=0
_timep_SETUP
unset a
getCPUtime a &>/dev/null || timep_CLOCK_GETTIME_FLAG=false
if [[ "${a}" = *[0-9]* ]] && (( a > 0 )); then
timep_CLOCK_GETTIME_FLAG=true
else
timep_CLOCK_GETTIME_FLAG=false
fi
if [[ ${timep_DEBUG} ]] && { [[ "${timep_DEBUG}" == '1' ]] || [[ "${timep_DEBUG}" == 'true' ]]; }; then
timep_DEBUG_FLAG=true
else
timep_DEBUG_FLAG=false
fi
case "${timep_DEBUG_IDS_FLAG,,}" in
true|1|y|yes|on) timep_DEBUG_IDS_FLAG=true ;;
*) timep_DEBUG_IDS_FLAG=false ;;
esac
if [[ ${timep_GENERATE_FLAMEGRAPHS_BY_DEFAULT} ]] && { [[ "${timep_GENERATE_FLAMEGRAPHS_BY_DEFAULT}" == '1' ]] || [[ "${timep_GENERATE_FLAMEGRAPHS_BY_DEFAULT}" == 'true' ]] || [[ "${timep_GENERATE_FLAMEGRAPHS_BY_DEFAULT%[Ee][Ss]}" == [Yy] ]]; }; then
timep_flameGraphFlag=true
else
timep_flameGraphFlag=false
fi
if [[ ${timep_ALLOW_ORPHANS_FLAG} ]] && { [[ "${timep_ALLOW_ORPHANS_FLAG}" == '1' ]] || [[ "${timep_ALLOW_ORPHANS_FLAG}" == 'true' ]] || [[ "${timep_ALLOW_ORPHANS_FLAG%[Ee][Ss]}" == [Yy] ]]; }; then
timep_ALLOW_ORPHANS_FLAG=true
else
timep_ALLOW_ORPHANS_FLAG=false
fi
export timep_ALLOW_ORPHANS_FLAG="${timep_ALLOW_ORPHANS_FLAG}"
# parse flags
timep_deleteFlag=true
timep_noOutFlag=false
timep_timeFlag=false
while true; do
case "${1}" in
-s|--shell) timep_runType=s ;;
-f|--function) timep_runType=f ;;
-c|--command) timep_runType=c ;;
-k|--keep) timep_deleteFlag=false ;;
-t|--time) timep_timeFlag=true ;;
-F|-[Ff]lame|--[Ff]lame|--[Ff]lame[Gg]raph) timep_flameGraphFlag=true ;;
+F|+[Ff]lame|+[+-][Ff]lame|+[+-][Ff]lame[Gg]raph) timep_flameGraphFlag=false ;;
-o|--output) shift 1; IFS0="${IFS@Q}"; IFS0="${IFS0/["'"\$]/IFS\=&}"; IFS=',' read -r -a timep_outTypeA <<<"${1}"; eval "${IFS0:-unset IFS}"; unset IFS0; (( ${#timep_outTypeA[@]} == 0 )) && timep_noOutFlag=true ;;
-o=*|--output=*) IFS0="${IFS@Q}"; IFS0="${IFS0/["'"\$]/IFS\=&}"; IFS=',' read -r -a timep_outTypeA <<<"${1#*=}"; eval "${IFS0:-unset IFS}"; unset IFS0; (( ${#timep_outTypeA[@]} == 0 )) && timep_noOutFlag=true ;;
--setup|--extract) _timep_setup; [[ "${1}" == '--extract-scripts' ]] && { \cp "${timep_TMPDIR0}/lib/${USER}-${EUID}"/{timep.so,timep_flamegraph.pl} "${PWD}"; printf '\nThe extracted "timep.so" and "timep_flamegraph.pl" files have been extracted to "${timep_TMPDIR0}/lib/%s-%s"\n' "${USER}" "${EUID}"; }; return 0 ;;
--setup=*|--extract=*) mapfile -t -d ',' timep_setupFuncFlags <<<"${1#*=}"; _timep_setup "${timep_setupFuncFlags[@]}"; [[ "${1}" == '--extract-scripts' ]] && { \cp "${timep_TMPDIR0}/lib/${USER}-${EUID}"/{timep.so,timep_flamegraph.pl} "${PWD}"; printf '\nThe extracted "timep.so" and "timep_flamegraph.pl" files have been extracted to "${timep_TMPDIR0}/lib/%s-%s"\n' "${USER}" "${EUID}"; }; return 0 ;;
--) shift 1 && break ;;
*) break ;;
esac
shift 1
done
(( ${#timep_outTypeA[@]} > 0 )) && for kk in "${!timep_outTypeA[@]}"; do
[[ "${timep_outTypeA[$kk]}" == [pf] ]] || [[ "${timep_outTypeA[$kk]}" == [pf]f ]] || unset "timep_outTypeA[$kk]"
done
(( ${#timep_outTypeA[@]} > 0 )) || ${timep_noOutFlag} || {
if ${timep_DEBUG_FLAG}; then
timep_outTypeA=('p' 'pf' 'f' 'ff')
else
timep_outTypeA=('p')
fi
}
printf -v timep_outType ' %s ' "${timep_outTypeA[@]}"
timep_TMPDIR="${timep_TMPDIR0}/timep.$(printf '%0.4X' "${RANDOM}" "${RANDOM}")"
until ! [[ -d "$timep_TMPDIR" ]]; do
timep_TMPDIR="${timep_TMPDIR0}/timep.$(printf '%0.4X' "${RANDOM}" "${RANDOM}")"
done
mkdir -p "${timep_TMPDIR}"/.log/.{starttimes,endtimes,runtimes,selftimes,times,hash}
mkdir -p "${timep_TMPDIR}"/{profiles,.needs_merge,.pid_used}
mkdir -p "${timep_TMPDIR}/.worker/delete"
printf '%s\n' '0' >"${timep_TMPDIR}/.log/.count.bg_pid"
# determine if command being profiled is a shell script or not
if [[ "${timep_runType}" == [sfc] ]]; then
[[ "${timep_runType}" == 's' ]] && {
# see if input is a path to something in the filesystem
if type realpath &>/dev/null; then
timep_runCmdPath="$(realpath "${1}")"
elif type readlink &>/dev/null && [[ $(readlink "${1}") ]]; then
timep_runCmdPath="$(readlink "${1}")"
else
timep_runCmdPath="$1"
fi
timep_runCmdPath="$(type -p "${timep_runCmdPath}")"
}
else
if declare -F "$1" &>/dev/null; then
# command is a function, which takes precedence over a script
timep_runType=f
else
if type realpath &>/dev/null; then
timep_runCmdPath="$(realpath "${1}")"
elif type readlink &>/dev/null && [[ $(readlink "${1}") ]]; then
timep_runCmdPath="$(readlink "${1}")"
else
timep_runCmdPath="$1"
fi
timep_runCmdPath="$(type -p "${timep_runCmdPath}")"
if [[ ${timep_runCmdPath} ]]; then
if type file &>/dev/null && { [[ "$(file "${timep_runCmdPath}")" == *shell\ script*executable* ]] || { [[ "$(file "${timep_runCmdPath}")" == *text ]] && [[ -x "${timep_runCmdPath}" ]]; }; }; then
# file is text and either starts with a shebang or is executeable. Assume it is a script.
timep_runType=s
elif [[ "${timep_runCmdPath}" == *.*sh ]] && read -r <"${timep_runCmdPath}" && [[ "${REPLY}" == '#!'* ]]; then
# file name ends in .*sh (e.g., .sh or .bash) and file begins with a shebang. Assume shell script.
timep_runType=s
else
# for all other cases treat it as a raw command
timep_runType=c
fi
else
# type -p didnt give a path and isnt a function. Treat it as a raw command.
timep_runType=c
fi
fi
fi
# helper function to get src code from functions
_timep_getFuncSrc() {
## Finds the original function source code for a currently loaded bash function
# USAGE: _timep_getFuncSrc [-q] [-r] <funcname>
#
# will pull the original source out of a file or, if available, out of the bash history
# if unable to retrieve original function source code, will instead return its `declare -f`
# if passed the path to a script file instead of a function, it will print the contents of the script file (e.g., `cat $file`)
#
# NOTE: cannot get the original source for functions defined interactively by sourcing a process substitutiion (e.g. `. <( ... )`)
#
# FLAGS: all flags must come before <funcname> and mmust be given seperately (use '-q -r', not '-qr')
# -q: dont print definition from primary input (inputs from dependencies may still be printed)
# -r: recursively find source for dependent functions too (requires that your bash binary has the --rpm-requires flag))
# make vars local
local out FF kk nn quietFlag recursionFlag
local -a F
# parse any flags
quietFlag=false
recursionFlag=false
while [[ "$1" == -[qr] ]] || [[ "$1" == --[qr]* ]]; do
case "$1" in
-q|--quiet) quietFlag=true ;;
-r|--recursion) recursionFlag=true ;;
*) break ;;
esac
shift 1
done
_timep_getFuncSrc0() {
local m mm n p kk off funcDef0 validFuncDefFlag
local -a A off_A
# get where the function was sourced from using extdebug + declare -F
# NOTE: this will tell us where the function definition started, but not where it ends.
read -r _ n p < <(shopt -s extdebug; declare -F "${1}")
((n--))
if [[ "${p}" == 'main' ]]; then
# try to pull function definition out of the bash history
# NOTE: the LINENO returned by extdebug + declare -F is unreliable when using the history
# instead grep the history for the function header and find all possible start lines
[[ $(history) ]] || { declare -f "${1}"; return; }
mapfile -t off_A < <( history | grep -n '' | grep -E '^[0-9]+:[[:space:]]*[0-9]*.*((function[[:space:]]+'"${1}"')|('"${1}"'[[:space:]]*\(\)))' | sed -E s/'\:.*$'//)
off=$(history | grep -n '' | tail -n 1 | sed -E s/'\:.*$'// )
for kk in "${!off_A[@]}"; do
(( off_A[$kk] = 1 + off - off_A[$kk] ))
done
off=$(printf '%s\n' "${off_A[@]}" | sort -n | tail -n 1)
for kk in "${!off_A[@]}"; do
(( off_A[$kk] = off - off_A[$kk] ))
done
mapfile -t off_A < <(printf '%s\n' "${off_A[@]}" | sort -nr)
mapfile -t A < <(history | tail -n "$off" | sed -E s/'^[[:space:]]*[0-9]*[[:space:]]*'//)
elif [[ -f "${p}" ]]; then
# pull function definition from file
mapfile -t A <"${p}"
until grep -qE '^[[:space:]]*((function[[:space:]]+'"${1}"')|('"${1}"'[[:space:]]*\(\)))' <<<"${A[@]:$n:1}"; do
((n--))
done
A=("${A[@]:$n}")
off_A=(0)
else
# cant extract original source. use declare -f.
declare -f "${1}"
return
fi
# return declare -f if A is empty
(( ${#A[@]} == 0 )) && { declare -f "${1}"; return; }
# our text blob *should* now start at the start of a function definition, but goes all the way to the EOF.
# try sourcing (with set -n) just the 1st line, then the first 2, then the first 3, etc. until the function sources correctly.
# if pulling the function definition out of the history, repeat this for all possible start lines until one gives a function with the same declare -f
# NOTE: "extra" commands need tro be removed from the 1st + last line before sourcing without set -n to check the declare -f
# get the declare -f for the loaded function
funcDef0="$(declare -f "${1}")"
validFuncDefFlag=false
# loop over all possible start locations
for mm in "${off_A[@]}"; do
# remove any preceeding commands on first history line
mapfile -t -d '' cmd_rm < <(. /proc/self/fd/0 <<<"trap 'set +n; printf '\"'\"'%s\0'\"'\"' \"\${BASH_COMMAND}\"; set -n' DEBUG; ${A[$mm]}" 2>/dev/null)
for nn in "${cmd_rm[@]}"; do
A[$mm]="${A[$mm]//"$nn"//}"
done
while [[ "${A[$mm]}" =~ ^[[:space:]]*\;+.*$ ]]; do
A[$mm]="${A[$mm]#*\;}"
done
# find history line the function ends on by attempting to source (with set -n) progressively larger chunks of the history
m=$(kk=1; IFS=$'\n'; set -n; until . /proc/self/fd/0 <<<"${A[*]:${mm}:${kk}}" &>/dev/null || (( ( mm + kk ) > ${#A[@]} )); do ((kk++)); done; echo "$kk")
# remove any trailing commands on last history line
(( mmm = mm + m - 1 ))
mapfile -t -d '' cmd_rm < <(. /proc/self/fd/0 <<<"IFS=$'\n'; trap 'set +n; printf '\"'\"'%s\0'\"'\"' \"\${BASH_COMMAND}\"; set -n' DEBUG; ${A[*]:${mm}:${m}}" 2>/dev/null)
for nn in "${cmd_rm[@]}"; do
A[$mmm]="${A[$mmm]//"$nn"//}"
done
while [[ "${A[$mmm]}" =~ ^.*\;+[[:space:]]*$ ]]; do
A[$mmm]="${A[$mmm]%\;*}"
done
# check if recovered + isolated function definition produces the same declare -f as the original (requires NOT using set -n)
if ( IFS=$'\n'; . /proc/self/fd/0 <<<"unset ${1}; ${A[*]:${mm}:${m}}" &>/dev/null && [[ "$(declare -f "${1}")" == "${funcDef0}" ]] ); then
validFuncDefFlag=true
break
elif (( ( mm + m ) > ${#A[@]} )); then
break
fi
done
if ${validFuncDefFlag}; then
printf '%s\n' "${A[@]:${mm}:${m}}"
else
declare -f "${1}"
fi
}
if declare -F "${1}" &>/dev/null || ! [[ -f "${1}" ]]; then
# input is a defined function and/or doesnt existin filesystem. treat as a function.
out="$(_timep_getFuncSrc0 "${1}")"
[[ "$out" == 'eval '* ]] && out="$(eval "echo ${out#eval }")"
else
# input is not a function and exists in filesystenm. treat as script and cat it.
out="$(<"${1}")"
fi
out="${out//builtin trap /trap }"
${quietFlag} || echo "$out"
# feed the function definition through `bash --rpm-requires` to get dependencies, then test each with `type` to find function dependencies.
# recursively call _timep_getFuncSrc for each not-yet-processed dependent function, keeping track of which function deps were already listed to avoid duplicates
# NOTE: the "--rpm-requires" flag is non-standard, and may only be available on distros based on red hat / fedora
${recursionFlag} && : | bash --debug --rpm-requires -O extglob &>/dev/null && {
# get function dependencies
mapfile -t F < <(bash --debug --rpm-requires -O extglob <<<"$out" | sed -E s/'^executable\((.*)\)'/'\1'/ | sort -u | while read -r nn; do type "$nn" 2>/dev/null | grep -qF 'is a function' && echo "$nn"; done)
for kk in "${!F[@]}"; do
if [[ "${FF}" == *" ${F[$kk]} "* ]]; then
# we already processed this function. remove it from "functions to process" list (F)
unset "F[$kk]"
else
# we have not yet processed this function, keep it on the "functions to process" list (F) and add it to the "already processed functions" list (FF) so we dont process it again after this round
FF+=" ${F[$kk]} "
fi
done
for nn in "${F[@]}"; do
# for each function on the "functions to process" list (F), recursively call _timep_getFuncSrc -r and pass the "already processed functions" list (FF) as an environment variable
FF="${FF}" _timep_getFuncSrc -r "${nn}"
done
}
}
# generate the code for a wrapper function (timep_runFunc) that wraps around whatever we are running / time profiling.
# this will setup a DEBUG trap to measure runtime from every command, then will run the specified code.
# the source code is generated and then sourced (instead of directly defined) so that things like the tmpdir/logfile path are hardcoded.
# this allows timep to run without adding any new (and potentially conflicting) variables to the code being run / time profiled.
export -p timep_EXIT_TRAP_STR &>/dev/null && export -n timep_EXIT_TRAP_STR
timep_EXIT_TRAP_STR=':'
export -p timep_RETURN_TRAP_STR &>/dev/null && export -n timep_RETURN_TRAP_STR
timep_RETURN_TRAP_STR='timep_SKIP_DEBUG_FLAG=true
timep_TRAP_OPTS=${-//[^eu]/}; ${timep_TRAP_OPTS:+set +}${timep_TRAP_OPTS}
[[ -z ${#FUNCNAME[@]} ]] || (( ${#FUNCNAME[@]} < 1 )) || {
if (( ${#BASH_SOURCE[@]} < timep_BASH_SOURCE_N[${timep_FNEST_CUR}] )) || { (( ${#BASH_SOURCE[@]} == timep_BASH_SOURCE_N[${timep_FNEST_CUR}] )) && ! ${timep_IS_SOURCE_FLAG[${timep_FNEST_CUR}]}; }; then
unset "timep_FNEST[-1]" "timep_NEXEC_A[-1]" "timep_NEXEC_HASH_A[-1]" "timep_BASH_COMMAND_PREV[${timep_FNEST_CUR}]" "timep_NPIPE[${timep_FNEST_CUR}]" "timep_STARTTIME[${timep_FNEST_CUR}]" "timep_LINENO[${timep_FNEST_CUR}]" "timep_LINENO_OFFSET[${timep_FNEST_CUR}]" "timep_BASH_SOURCE_N[${timep_FNEST_CUR}]" "timep_IS_SOURCE_FLAG[${timep_FNEST_CUR}]"
timep_FUNCNAME_STR="${timep_FUNCNAME_STR%.*}"
timep_NEXEC_0="${timep_NEXEC_0%.*}"
timep_FNEST_CUR="${timep_FNEST[-1]}"
timep_NEXEC_CUR="${timep_NEXEC_A[-1]}"
timep_NEXEC_HASH_CUR="${timep_NEXEC_HASH_A[-1]}"
elif (( ${#BASH_SOURCE[@]} == timep_BASH_SOURCE_N[${timep_FNEST_CUR}] )) && ${timep_IS_SOURCE_FLAG[${timep_FNEST_CUR}]}; then
timep_IS_SOURCE_FLAG[${timep_FNEST_CUR}]=false
fi
}
${timep_IS_BG_FUNC_FLAG[${timep_FNEST_CUR}]} && {
timep_BASH_COMMAND_PREV_0="<< (FUNCTION): ${timep_BASH_COMMAND_PREV[${timep_FNEST_CUR}]} (&) >>"
printf '"'"'1\t%s\t%s\tF:%s %s\tS:%s %s\tN:%s %s.%s\t%s\t::\t%s\n'"'"' "${timep_STARTTIME[${timep_FNEST_CUR}]}" "${timep_ENDTIME}" "${timep_FNEST_CUR:-${timep_FUNCNAME_N}}" "${timep_FUNCNAME_STR}" "${timep_BASH_SUBSHELL_PREV_0}" "${timep_BASHPID_STR}" "${timep_NEXEC_N_0}" "${timep_NEXEC_0}" "${timep_NEXEC_CUR}" "${timep_LINENO[${timep_FNEST_CUR:-${timep_FUNCNAME_N}}]:-${timep_LINENO_0}}" "'"$(${timep_DEBUG_IDS_FLAG} && printf '%s' '{PP0: ${timep_PARENT_PGID0} PT0: ${timep_PARENT_TPID0} PP: ${timep_PARENT_PGID} PT: ${timep_PARENT_TPID} CP: ${timep_CHILD_PGID} CT: ${timep_CHILD_TPID}}')"'${timep_BASH_COMMAND_PREV_0@Q}" >>"${timep_TMPDIR}/.log/log.${timep_NEXEC_HASH_CUR}"
}
${timep_TRAP_OPTS:+set -}${timep_TRAP_OPTS}
timep_SKIP_DEBUG_FLAG=false
'
if ${timep_CLOCK_GETTIME_FLAG}; then
timep_END_CTIME_STR='getCPUtime timep_END_CTIME timep_END_CTIME_SELF'$'\n'
timep_START_CTIME_STR='getCPUtime timep_START_CTIME timep_START_CTIME_SELF'$'\n'
else
type -p getconf &>/dev/null && clktck=$(getconf CLK_TCK)
: "${clktck:=100}"
if (( clktck >= 10 )) && ((clktck <= 10000 )); then
(( timep_CPU_TIME_MULT = 1000000 / clktck ))
else
read -r _ a </proc/uptime
read -r _ _ _ _ b _ </proc/stat
a0="${a##*.}"
(( timep_CPU_TIME_MULT = ( 1000000 / ( 10 ** ${#a0} ) ) * ${a//[^0-9]/} / b ))
# clamp to CLK_TCK between 10-10000
(( timep_CPU_TIME_MULT < 100 )) && timep_CPU_TIME_MULT=100
(( timep_CPU_TIME_MULT > 100000 )) && timep_CPU_TIME_MULT=100000
until (( timep_CPU_TIME_MULT % 10 == 0 )); do
((timep_CPU_TIME_MULT++))
done
fi
timep_END_CTIME_STR+='read -r _ _ _ _ _ _ _ _ _ _ _ _ _ timep_END_UTIME timep_END_STIME timep_END_CUTIME timep_END_CSTIME _ </proc/${timep_BASHPID_PREV:-$BASHPID}/stat
(( timep_END_CTIME = '"${timep_CPU_TIME_MULT}"' * ( timep_END_UTIME + timep_END_STIME + timep_END_CUTIME + timep_END_CSTIME ) ))
(( timep_END_CTIME_SELF = '"${timep_CPU_TIME_MULT}"' * ( timep_END_UTIME + timep_END_STIME ) ))
(( timep_END_CTIME <= ${timep_STARTTIME[${timep_FNEST_CUR}]#*$'"'"'\t'"'"'} )) && timep_END_CTIME=${timep_STARTTIME[${timep_FNEST_CUR}]#*$'"'"'\t'"'"'}'$'\n'
timep_START_CTIME_STR+='read -r _ _ _ _ _ _ _ _ _ _ _ _ _ timep_START_UTIME timep_START_STIME timep_START_CUTIME timep_START_CSTIME _ </proc/${timep_BASHPID_PREV:-$BASHPID}/stat
(( timep_START_CTIME = '"${timep_CPU_TIME_MULT}"' * ( timep_START_UTIME + timep_START_STIME + timep_START_CUTIME + timep_START_CSTIME ) ))
(( timep_START_CTIME_SELF = '"${timep_CPU_TIME_MULT}"' * ( timep_START_UTIME + timep_START_STIME ) ))
(( timep_START_CTIME <= ${timep_ENDTIME#*$'"'"'\t'"'"'} )) && timep_START_CTIME=${timep_ENDTIME#*$'"'"'\t'"'"'}'$'\n'
fi
export -p timep_SIGNAL_RELAY_TRAP_STR &>/dev/null && export -n timep_SIGNAL_RELAY_TRAP_STR
timep_SIGNAL_RELAY_TRAP_STR='builtin trap - DEBUG EXIT RETURN
if [[ -s "${timep_TMPDIR}/.log/.disableSignalRelay" ]]; then
builtin trap - SIG%s
kill -%s "$BASHPID"
else
builtin trap '"''"' SIG%s
timep_pidA=()
jobs -p | {
mapfile -t timep_pidA
(( ${#timep_PIDA[@]} > 0 )) && kill -SIG%s "${timep_pidA[@]}" 2>/dev/null
}
builtin trap - SIG%s
kill -%s "${BASHPID}"
fi'
export -p timep_DEBUG_TRAP_STR_0 &>/dev/null && export -n timep_DEBUG_TRAP_STR_0
export -p timep_DEBUG_TRAP_STR_1 &>/dev/null && export -n timep_DEBUG_TRAP_STR_1
timep_DEBUG_TRAP_STR_0='timep_NPIPE0="${#PIPESTATUS[@]}"
(( timep_END_TIME = 10#${EPOCHREALTIME//[^0-9]/} ))
'"${timep_END_CTIME_STR}"
timep_DEBUG_TRAP_STR_1='timep_TRAP_OPTS=${-//[^eu]/}; ${timep_TRAP_OPTS:+set +}${timep_TRAP_OPTS}
'
${timep_ALLOW_ORPHANS_FLAG} && timep_DEBUG_TRAP_STR_1+='if [[ -f "${timep_TMPDIR}/.profiling.done" ]] || ! [[ -d "${timep_TMPDIR}/.log" ]]; then
kill -TERM "$BASHPID"
exit 0
fi
'
timep_DEBUG_TRAP_STR_1+='[[ "$-" == *m* ]] || {
printf '"'"'\nWARNING: timep requires job control (set -m) to be enabled.\n Running "set +m" is not allowed!\n Job control will automatically be re-enabled.\n\n'"'"' >&2
set -m
}
[[ "$-" == *T* ]] || {
printf '"'"'\nWARNING: timep requires functrace (set -T) to be enabled.\n Running "set +T" is not allowed!\n functrace will automatically be re-enabled.\n\n'"'"' >&2
set -T
}
if (( ${#BASH_COMMAND} > 16384 )); then
timep_BASH_COMMAND_CUR="${BASH_COMMAND::16384}"
timep_BASH_COMMAND_CUR="${timep_BASH_COMMAND_CUR@Q}"
else
timep_BASH_COMMAND_CUR="${BASH_COMMAND@Q}"
fi
timep_FUNCNAME_N="${#FUNCNAME[@]}"
: "${timep_FUNCNAME_N:=0}"
[[ "${timep_LAST_CMD_WORD[${timep_FNEST_CUR}]}" == '"'"'set'"'"' ]] && [[ "${timep_BASH_COMMAND_CUR}" == *'"'"'set -'"'"'*m* ]] && echo 1 > "${timep_TMPDIR}/.log/.disableSignalRelay"
[[ "${FUNCNAME[0]}" == "trap" ]] && ! ${timep_SKIP_DEBUG_FLAG} && {
timep_SKIP_DEBUG_NEXT_FLAG=true
}
[[ "${BASH_ENV}" == "${timep_TMPDIR}/env.bash" ]] || {
export timep_USER_BASH_ENV="${BASH_ENV}"
export BASH_ENV="${timep_TMPDIR}/env.bash"
}
${timep_SKIP_DEBUG_FLAG} || {
timep_NPIPE[${timep_FNEST_CUR}]=${timep_NPIPE0}
if (( 10#0${timep_START_CTIME_SELF_A[${timep_FNEST_CUR:-0}]} > 10#0${timep_END_CTIME_SELF} )); then
timep_STARTTIME[${timep_FNEST_CUR}]="${timep_STARTTIME[${timep_FNEST_CUR}]%$'"'"'\t'"'"'*}"$'"'"'\t'"'"'"0"
timep_START_CTIME_SELF_A[${timep_FNEST_CUR}]=0
fi
if [[ "${timep_LAST_CMD_WORD[${timep_FNEST_CUR}]}" == '"'"'wait'"'"' ]]; then
(( timep_END_CTIME = 10#0${timep_STARTTIME[${timep_FNEST_CUR:-0}]#*$'"'"'\t'"'"'} + 10#0${timep_END_CTIME_SELF} - 10#0${timep_START_CTIME_SELF_A[${timep_FNEST_CUR:-0}]} ))
fi
timep_ENDTIME="${timep_END_TIME}"$'"'"'\t'"'"'"${timep_END_CTIME}"
timep_IS_BG_FLAG=false
timep_IS_SUBSHELL_FLAG=false
if (( timep_FNEST_CUR >= ${timep_FUNCNAME_N} )); then
timep_IS_FUNC_FLAG=false
else
timep_IS_FUNC_FLAG=true
timep_FNEST+=("${timep_FUNCNAME_N}")
timep_IS_BG_FUNC_FLAG[${timep_FUNCNAME_N}]=false
fi
if ${timep_SIMPLEFORK_NEXT_FLAG}; then
timep_SIMPLEFORK_NEXT_FLAG=false
timep_SIMPLEFORK_CUR_FLAG=true
else
timep_SIMPLEFORK_CUR_FLAG=false
fi
if (( timep_BASH_SUBSHELL_PREV == BASH_SUBSHELL )); then
if (( timep_BG_PID_PREV == $! )); then
${timep_IS_FUNC_FLAG} && timep_NO_PRINT_FLAG=true
else
timep_IS_BG_FLAG=true
fi
(( timep_BASHPID_PREV == BASHPID )) || printf '%s\t%s\n' "${timep_BASHPID_PREV}" "${BASHPID}" >>"${timep_TMPDIR}/.corrections.pid"
else
timep_IS_SUBSHELL_FLAG=true
printf '"'"'%s\n'"'"' "${timep_ENDTIME}" >>"${timep_TMPDIR}/.log/.endtimes/${timep_NEXEC_HASH_CUR}.${timep_NEXEC_CUR}"
((BASHPID < timep_BASHPID_PREV)) && ((timep_NPIDWRAP++))
builtin trap '"'${timep_EXIT_TRAP_STR//"'"/"'"'"'"'"'"'"'"}'"' EXIT
'
for nn in INT TERM QUIT HUP; do
printf -v trapAddCur '%s' "${timep_SIGNAL_RELAY_TRAP_STR//\%s/${nn}}"
timep_DEBUG_TRAP_STR_1+=$'\n'"builtin trap '${trapAddCur//"'"/"'"'"'"'"'"'"'"}' SIG${nn}"$'\n'
done
timep_DEBUG_TRAP_STR_1+='
IFS='"'"' '"'"' read -r _ _ _ _ timep_CHILD_PGID _ _ timep_CHILD_TPID _ </proc/${BASHPID}/stat
((timep_CHILD_PGID == timep_PARENT_TPID)) || ((timep_CHILD_PGID == timep_CHILD_TPID)) || { ((timep_CHILD_PGID == timep_PARENT_PGID)) && ((timep_CHILD_TPID == timep_PARENT_TPID)); } || timep_IS_BG_FLAG=true
fi
if ${timep_IS_SUBSHELL_FLAG}; then
if ${timep_IS_BG_FLAG}; then
((timep_CHILD_PGID == BASHPID)) && ((timep_CHILD_TPID == timep_PARENT_PGID)) && ((timep_CHILD_TPID == timep_PARENT_TPID)) && timep_SIMPLEFORK_NEXT_FLAG=true
timep_CMD_TYPE="BACKGROUND FORK"
else
timep_CMD_TYPE="SUBSHELL"
fi
${timep_IS_FUNC_FLAG_1} && { timep_IS_FUNC_FLAG_1=false; [[ ${timep_LINENO_OFFSET[${timep_FNEST_CUR}]} ]] || (( timep_LINENO_OFFSET[${timep_FNEST_CUR}] = LINENO + 19 )); }
elif [[ "${timep_BASH_COMMAND_PREV[${timep_FNEST_CUR}]}" == " (F) "* ]]; then
timep_BASH_COMMAND_PREV[${timep_FNEST_CUR}]="${timep_BASH_COMMAND_PREV[${timep_FNEST_CUR}]# (F) }"
timep_IS_BG_FLAG=false
timep_CMD_TYPE="FUNCTION (P)"
elif ${timep_IS_BG_FLAG}; then
timep_CMD_TYPE="SIMPLE FORK"
elif ${timep_IS_FUNC_FLAG_1}; then
timep_CMD_TYPE="FUNCTION (C)"
timep_IS_FUNC_FLAG_1=false
[[ ${timep_LINENO_OFFSET[${timep_FNEST_CUR}]} ]] || (( timep_LINENO_OFFSET[${timep_FNEST_CUR}] = LINENO + 9 ))
else
timep_CMD_TYPE="NORMAL COMMAND"
fi
${timep_IS_SUBSHELL_FLAG} && ${timep_IS_BG_FLAG} && ${timep_IS_FUNC_FLAG} && {
builtin trap - EXIT
timep_IS_BG_FUNC_FLAG[${timep_FUNCNAME_N}]=true
timep_BASH_SUBSHELL_PREV_0="${timep_BASH_SUBSHELL_PREV}"
timep_NEXEC_N_0="${timep_NEXEC_N}"
}
${timep_IS_BG_FLAG} && ! ${timep_IS_SUBSHELL_FLAG} && declare -F "${timep_LAST_CMD_WORD[${timep_FNEST_CUR}]}" &>/dev/null && ! { [[ "${timep_LAST_CMD_WORD[${timep_FNEST_CUR}]}" == '"'"'trap'"'"' ]] || [[ "${FUNCNAME[0]}" == '"'"'trap'"'"' ]] || ${timep_IS_FUNC_FLAG}; } && {
timep_BASH_COMMAND_PREV[${timep_FNEST_CUR}]=""
timep_CMD_TYPE="FUNCTION (P)"
timep_NO_PRINT_FLAG=true
}
${timep_LINENO_INIT_FLAG} && {
: "${timep_FNEST_CUR:=${timep_FUNCNAME_N}}"
timep_LINENO[${timep_FNEST_CUR}]="${LINENO}"
timep_IS_BG_FUNC_FLAG[${timep_FNEST_CUR}]=false
timep_LINENO_INIT_FLAG=false
[[ ${timep_LINENO_OFFSET[${timep_FNEST_CUR}]} ]] || (( timep_LINENO_OFFSET[${timep_FNEST_CUR}] = LINENO + 4 ))
timep_NPIDWRAP=0
[[ "${timep_NEXEC_0}" == *':CHILD:'* ]] || timep_NEXEC_0="{${timep_NPIDWRAP}-${BASHPID}}"
timep_NEXEC_A[${timep_FNEST_CUR}]=0
timep_FNEST[${timep_FNEST_CUR}]="${timep_FUNCNAME_N}"
timep_hash - '"'"'timep_NEXEC_HASH_CUR'"'"' <<<"${timep_NEXEC_0}"
echo "${timep_NEXEC_0}" >"${timep_TMPDIR}/.log/.hash/log.${timep_NEXEC_HASH_CUR}"
echo "${timep_NEXEC_HASH_CUR} --> ${timep_NEXEC_0}" >>"${timep_TMPDIR}/run.log.txt"
timep_NEXEC_HASH_A[${timep_FNEST_CUR}]="${timep_NEXEC_HASH_CUR}"
}
if ${timep_IS_FUNC_FLAG}; then
timep_LINENO_0=1
else
(( timep_LINENO_0 = LINENO - 10#0${timep_LINENO_OFFSET[${timep_FNEST_CUR:-0}]:-0} ))
fi
if [[ -z ${timep_PARENT_PGID0} ]] && [[ -z ${timep_PARENT_TPID0} ]] && (( timep_PARENT_PGID == timep_CHILD_PGID )) && (( timep_PARENT_PGID == timep_PARENT_TPID )) && ! (( timep_PARENT_PGID == timep_CHILD_TPID )); then
timep_IS_BG_INDICATOR='"'"'(^)'"'"'
elif (( timep_PARENT_PGID0 == timep_PARENT_TPID0 )) && (( timep_PARENT_PGID == timep_CHILD_PGID )) && (( timep_PARENT_PGID0 == timep_PARENT_PGID )) && (( timep_PARENT_TPID == timep_CHILD_TPID )) && ! (( timep_PARENT_PGID == timep_PARENT_TPID )); then
timep_IS_BG_INDICATOR='"'"'(^)'"'"'
else
timep_IS_BG_INDICATOR='"''"'
fi
echo "NEW DEBUG TRAP ($BASHPID_$BASH_SUBSHELL): COMMAND TYPE IS $timep_CMD_TYPE -- CMD IS ${BASH_COMMAND}" >>"${timep_TMPDIR}/run.log.txt"
if ${timep_IS_SUBSHELL_FLAG}; then
echo "IN IS_SUBSHELL BRANCH" >>"${timep_TMPDIR}/run.log.txt"
timep_NPIPE[${timep_FNEST_CUR}]=1
timep_NPIDWRAP_PREV_0="${timep_NPIDWRAP}"
((BASHPID < timep_BASHPID_PREV)) && ((timep_NPIDWRAP++))
((timep_BASH_SUBSHELL_DIFF = BASH_SUBSHELL - timep_BASH_SUBSHELL_PREV))
timep_BASH_COMMAND_PREV_0="<< (${timep_CMD_TYPE}): ${timep_BASHPID_PREV} >>"
((timep_NEXEC_N++))
timep_PARENT_PGID="$timep_CHILD_PGID"
timep_PARENT_TPID="$timep_CHILD_TPID"
timep_BASHPID_ADD=()
timep_BASHPID_ADD_CUR="${BASHPID}"
timep_ADD_BG_PID_COUNTER_FLAG=false
((timep_BASH_SUBSHELL_DIFF--))
timep_BASHPID_ADD[${timep_BASH_SUBSHELL_DIFF}]="${timep_BASHPID_ADD_CUR}"
${timep_IS_BG_FLAG} && { [[ -f "${timep_TMPDIR}/.pid_used/${timep_BASHPID_ADD_CUR}" ]] || (( timep_BASHPID_ADD_CUR < timep_BASHPID_PREV )); } && timep_ADD_BG_PID_COUNTER_FLAG=true
: >"${timep_TMPDIR}/.pid_used/${timep_BASHPID_ADD_CUR%\-*}"
while ((timep_BASH_SUBSHELL_DIFF > 0)); do
((timep_BASH_SUBSHELL_DIFF--))
IFS='"'"' '"'"' read -r _ timep_PCOMM _ timep_BASHPID_ADD_CUR _ </proc/${timep_BASHPID_ADD_CUR}/stat
if (( timep_BASHPID_ADD_CUR == timep_BASHPID_PREV )) || (( timep_BASHPID_ADD_CUR <= 1 )); then
((timep_BASH_SUBSHELL_DIFF++))
break
else
${timep_IS_BG_FLAG} && { [[ -f "${timep_TMPDIR}/.pid_used/${timep_BASHPID_ADD_CUR}" ]] || (( timep_BASHPID_ADD_CUR < timep_BASHPID_PREV )); } && timep_ADD_BG_PID_COUNTER_FLAG=true
timep_BASHPID_ADD[${timep_BASH_SUBSHELL_DIFF}]="${timep_BASHPID_ADD_CUR}"
fi
done
timep_KK="${timep_BASH_SUBSHELL_DIFF}"
timep_NPIDWRAP="${timep_NPIDWRAP_PREV_0}"
((timep_NEXEC_N++))
if ${timep_ADD_BG_PID_COUNTER_FLAG}; then
read -r -u "${timep_LOCK_FD}" _
read -r timep_BG_PID_COUNTER <"${timep_TMPDIR}/.log/.count.bg_pid"
((timep_BG_PID_COUNTER++))
printf '"'"'%s\n'"'"' "${timep_BG_PID_COUNTER}" >"${timep_TMPDIR}/.log/.count.bg_pid"
timep_BG_PID_COUNTER="-${timep_BG_PID_COUNTER}"
printf '"'"'\n'"'"' >&${timep_LOCK_FD}
else
timep_BG_PID_COUNTER='"''"'
fi
while ((timep_KK < ${#timep_BASHPID_ADD[@]})); do
: >"${timep_TMPDIR}/.pid_used/${timep_BASHPID_PREV%\-*}"
(( ${timep_BASHPID_ADD[${timep_KK}]%%-*} < ${timep_BASHPID_PREV%%-*} )) && ((timep_NPIDWRAP++))
timep_BASHPID_PREV="${timep_BASHPID_ADD[${timep_KK}]}${timep_BG_PID_COUNTER}"
timep_BASH_COMMAND_PREV_0="<< (${timep_CMD_TYPE}): ${timep_BASHPID_PREV} >>"
timep_hash - '"'"'timep_NEXEC_HASH_CUR'"'"' <<<"${timep_NEXEC_0}.${timep_NEXEC_CUR}{${timep_NPIDWRAP}-${timep_BASHPID_PREV}}"
echo "${timep_NEXEC_0}.${timep_NEXEC_CUR}{${timep_NPIDWRAP}-${timep_BASHPID_PREV}}" >"${timep_TMPDIR}/.log/.hash/log.${timep_NEXEC_HASH_CUR}"
echo "${timep_NEXEC_HASH_CUR} --> ${timep_NEXEC_0}" >>"${timep_TMPDIR}/run.log.txt"
[[ -s "${timep_TMPDIR}/.log/log.${timep_NEXEC_HASH_CUR}.init_s" ]] || printf '"'"'1\t%s\t-\t-\tF:%s %s\tS:%s %s\tN:%s %s.%s{%s-%s}\t%s\t::\t%s\n'"'"' "${timep_ENDTIME}" "${timep_FNEST_CUR:-${timep_FUNCNAME_N}}" "${timep_FUNCNAME_STR}" "${timep_BASH_SUBSHELL_PREV}" "${timep_BASHPID_STR}" "${timep_NEXEC_N}" "${timep_NEXEC_0}" "${timep_NEXEC_CUR}" "${timep_NPIDWRAP}" "${timep_BASHPID_PREV}" "${timep_LINENO_0}" "${timep_BASH_COMMAND_PREV_0@Q}" >>"${timep_TMPDIR}/.log/log.${timep_NEXEC_HASH_CUR}.init_s"
timep_BASHPID_STR+=".${timep_BASHPID_PREV}"
timep_NEXEC_0+=".${timep_NEXEC_CUR}{${timep_NPIDWRAP}-${timep_BASHPID_PREV}}"
timep_NEXEC_A+=(0)
timep_NEXEC_CUR=0
((timep_BASH_SUBSHELL_PREV++))
((timep_KK++))
done
timep_BASHPID_PREV="${BASHPID}"
timep_BASH_SUBSHELL_PREV="${BASH_SUBSHELL}"
timep_NEXEC_HASH_A[-1]="${timep_NEXEC_HASH_CUR}"
((timep_NEXEC_N++))
${timep_IS_BG_FUNC_FLAG[${timep_FUNCNAME_N}]} || printf '"'"'1\t%s\t+\t%s\tF:%s %s\tS:%s %s\tN:%s %s.0\t%s\t::\t%s\n'"'"' "${timep_ENDTIME}" "${timep_END_CTIME}" "${timep_FNEST_CUR:-${timep_FUNCNAME_N}}" "${timep_FUNCNAME_STR}" "${BASH_SUBSHELL}" "${timep_BASHPID_STR}" "${timep_NEXEC_N}" "${timep_NEXEC_0}" "${timep_LINENO_0}" "'"$(${timep_DEBUG_IDS_FLAG} && printf '%s' '{PP0: ${timep_PARENT_PGID0} PT0: ${timep_PARENT_TPID0} PP: ${timep_PARENT_PGID} PT: ${timep_PARENT_TPID} CP: ${timep_CHILD_PGID} CT: ${timep_CHILD_TPID}}')"'${timep_BASH_COMMAND_CUR@Q} ${timep_IS_BG_INDICATOR}" >"${timep_TMPDIR}/.log/log.${timep_NEXEC_HASH_CUR}.init_c"
timep_SUBSHELL_INIT_FLAG=true
elif ${timep_SUBSHELL_INIT_FLAG}; then
[[ -s "${timep_TMPDIR}/.log/log.${timep_NEXEC_HASH_CUR}.init_c" ]] && : >"${timep_TMPDIR}/.log/log.${timep_NEXEC_HASH_CUR}.init_c"
timep_SUBSHELL_INIT_FLAG=false
fi
${timep_IS_SUBSHELL_FLAG} || [[ -z ${timep_BASH_COMMAND_PREV[${timep_FNEST_CUR}]} ]] || {
echo "IN WRITE NORMAL COMMAND BRANCH" >>"${timep_TMPDIR}/run.log.txt"
${timep_SIMPLEFORK_CUR_FLAG} && ((BASHPID < $!)) && {
timep_IS_BG_FLAG=true
timep_CMD_TYPE="SIMPLE FORK *"
}
${timep_IS_BG_FLAG} && [[ -z ${timep_IS_BG_INDICATOR} ]] && timep_IS_BG_INDICATOR='"'"'(&)'"'"'
[[ -s "${timep_TMPDIR}/.log/.endtimes/${timep_NEXEC_HASH_CUR}.${timep_NEXEC_CUR}" ]] && {
{
while IFS=$'"'"'\t'"'"' read -r -u ${timep_FD_ENDTIME} timep_END_TIME0 timep_END_CTIME0; do
(( 10#0${timep_END_TIME0//[^0-9]/} < 10#0${timep_END_TIME//[^0-9]/} )) && (( 10#0${timep_END_TIME0//[^0-9]/} > 10#0${timep_STARTTIME[${timep_FNEST_CUR}]%$'"'"'\t'"'"'*} )) && {
timep_END_TIME="${timep_END_TIME0}"
timep_END_CTIME="${timep_END_CTIME0}"
}
done
timep_ENDTIME="${timep_END_TIME}"$'"'"'\t'"'"'"${timep_END_CTIME}"
} {timep_FD_ENDTIME}<"${timep_TMPDIR}/.log/.endtimes/${timep_NEXEC_HASH_CUR}.${timep_NEXEC_CUR}"
exec {timep_FD_ENDTIME}>&-
}
${timep_NO_PRINT_FLAG} || printf '"'"'%s\t%s\t%s\tF:%s %s\tS:%s %s\tN:%s %s.%s\t%s\t::\t%s %s\n'"'"' "${timep_NPIPE[${timep_FNEST_CUR:-${timep_FUNCNAME_N}}]:-1}" "${timep_STARTTIME[${timep_FNEST_CUR}]}" "${timep_ENDTIME}" "${timep_FNEST_CUR:-${timep_FUNCNAME_N}}" "${timep_FUNCNAME_STR}" "${BASH_SUBSHELL}" "${timep_BASHPID_STR}" "${timep_NEXEC_N}" "${timep_NEXEC_0}" "${timep_NEXEC_CUR}" "${timep_LINENO[${timep_FNEST_CUR:-${timep_FUNCNAME_N}}]:-${timep_LINENO_0}}" "'"$(${timep_DEBUG_IDS_FLAG} && printf '%s' '{PP0: ${timep_PARENT_PGID0} PT0: ${timep_PARENT_TPID0} PP: ${timep_PARENT_PGID} PT: ${timep_PARENT_TPID} CP: ${timep_CHILD_PGID} CT: ${timep_CHILD_TPID}}')"'${timep_BASH_COMMAND_PREV[${timep_FNEST_CUR}]@Q}" "${timep_IS_BG_INDICATOR}" >>"${timep_TMPDIR}/.log/log.${timep_NEXEC_HASH_CUR}"
((timep_NEXEC_A[-1]++))
((timep_NEXEC_CUR++))
((timep_NEXEC_N++))
}
if ${timep_IS_FUNC_FLAG}; then
echo "IN IS_FUNC_FLAG BRANCH" >>"${timep_TMPDIR}/run.log.txt"
timep_FUNCNAME_STR+=".${FUNCNAME[0]}"
timep_NEXEC_0+=".${timep_NEXEC_A[-1]}"
timep_NEXEC_A+=(0)
timep_NEXEC_CUR=0
((timep_NEXEC_N++))
[[ "${FUNCNAME[0]}" == '"'"'trap'"'"' ]] || {
if ${timep_IS_BG_FUNC_FLAG[${timep_FUNCNAME_N}]}; then
timep_BASH_COMMAND_PREV[${timep_FNEST_CUR}]="${timep_BASH_COMMAND_CUR}"
else
timep_BASH_COMMAND_PREV[${timep_FNEST_CUR}]=" (F) << (FUNCTION): ${timep_BASH_COMMAND_CUR} >>"
fi
}
timep_NPIPE[${timep_FUNCNAME_N}]="1"
timep_FNEST_CUR="${timep_FUNCNAME_N}"
timep_BASH_SOURCE_N[${timep_FNEST_CUR}]="${#BASH_SOURCE[@]}"
timep_IS_SOURCE_FLAG[${timep_FNEST_CUR}]=false
timep_hash - '"'"'timep_NEXEC_HASH_CUR'"'"' <<<"${timep_NEXEC_0}"
echo "${timep_NEXEC_0}" >"${timep_TMPDIR}/.log/.hash/log.${timep_NEXEC_HASH_CUR}"
echo "${timep_NEXEC_HASH_CUR} --> ${timep_NEXEC_0}" >>"${timep_TMPDIR}/run.log.txt"
timep_NEXEC_HASH_A+=("${timep_NEXEC_HASH_CUR}")
timep_IS_FUNC_FLAG_1=true
elif (( ${#BASH_SOURCE[@]} > timep_BASH_SOURCE_N[${timep_FNEST_CUR}] )); then
timep_IS_SOURCE_FLAG[${timep_FNEST_CUR}]=true
fi
if (( timep_LINENO_0 < 0 )) && [[ "${timep_BASH_COMMAND_CUR}" == "${timep_BASH_COMMAND_PREV[${timep_FNEST_CUR}]% \(\?\)}" ]]; then
timep_BASH_COMMAND_PREV[${timep_FNEST_CUR}]="${timep_BASH_COMMAND_CUR} "'"'"'(?)'"'"'
else
timep_BASH_COMMAND_PREV[${timep_FNEST_CUR}]="${timep_BASH_COMMAND_CUR}"
fi
timep_LAST_CMD_WORD[${timep_FNEST_CUR}]="${BASH_COMMAND%% *}"
timep_LINENO[${timep_FNEST_CUR}]="${timep_LINENO_0}"
timep_BG_PID_PREV="$!"
timep_BASHPID_PREV="$BASHPID"
timep_NO_PRINT_FLAG=false
${timep_SKIP_DEBUG_NEXT_FLAG} && {
timep_SKIP_DEBUG_NEXT_FLAG=false
timep_SKIP_DEBUG_FLAG=true
}
'"${timep_START_CTIME_STR}"'
(( timep_START_TIME = 10#${EPOCHREALTIME//[^0-9]/} ))
timep_STARTTIME[${timep_FNEST_CUR}]="${timep_START_TIME}"$'"'"'\t'"'"'"${timep_START_CTIME}"
timep_START_CTIME_SELF_A[${timep_FNEST_CUR}]="${timep_START_CTIME_SELF}"
}
${timep_TRAP_OPTS:+set -}${timep_TRAP_OPTS}
'
# overload the trap builtin to allow the use of custom EXIT/RETURN/DEBUG traps
export -p -f trap &>/dev/null && export -n -f trap
{ printf 'declare -g timep_SIGNAL_RELAY_TRAP_STR='"'"'%s'"'"'\n\ndeclare -g timep_EXIT_TRAP_STR='"'"'%s'"'"'\n\ndeclare -g timep_RETURN_TRAP_STR='"'"'%s'"'"'\n\ndeclare -g timep_DEBUG_TRAP_STR_0='"'"'%s'"'"'\n\ndeclare -g timep_DEBUG_TRAP_STR_1='"'"'%s'"'"'\n\n%s\n\n' "${timep_SIGNAL_RELAY_TRAP_STR//"'"/"'"'"'"'"'"'"'"}" "${timep_EXIT_TRAP_STR//"'"/"'"'"'"'"'"'"'"}" "${timep_RETURN_TRAP_STR//"'"/"'"'"'"'"'"'"'"}" "${timep_DEBUG_TRAP_STR_0//"'"/"'"'"'"'"'"'"'"}" "${timep_DEBUG_TRAP_STR_1//"'"/"'"'"'"'"'"'"'"}" 'trap() {
local trapStr trapStr0 trapStrQ trapType
(( $# == 0 )) && return 1
if [[ "${1}" == -[lp] ]]; then
builtin trap "${@}"
return
else
[[ "${1}" == '"'"'--'"'"' ]] && shift 1
trapStr="${1}"
shift 1
while (( $# > 1)); do
case "${1}" in
EXIT|RETURN|DEBUG|ERR|SIGHUP|SIGINT|SIGQUIT|SIGILL|SIGTRAP|SIGABRT|SIGBUS|SIGFPE|SIGKILL|SIGUSR1|SIGSEGV|SIGUSR2|SIGPIPE|SIGALRM|SIGTERM|SIGSTKFLT|SIGCHLD|SIGCONT|SIGSTOP|SIGTSTP|SIGTTIN|SIGTTOU|SIGURG|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGIO|SIGPWR|SIGSYS|SIGRTMIN|SIGRTMAX|SIGRTMIN[+-]*|SIGRTMAX[+-]*)
break
;;
*)
trapStr+="${trapStr:+ }${1}"
shift 1
;;
esac
done
trapStr0="${trapStr}"$'"'"'\n'"'"'
{ [[ "${trapStr}" == '"'"'-'"'"' ]] || [[ -z "${trapStr}" ]]; } && trapStr0='"''"'
fi
for trapType in "${@}"; do
[[ -z "${trapStr}" ]] || [[ "${trapStr}" == '"'"'-'"'"' ]] || {
trapStrQ="@TRAP (${trapType}): ${trapStr}"
trapStrQ="${trapStrQ//$'"'"'\n'"'"'/'"'"'$'"'"'"'"'"'"'"'"'\n'"'"'"'"'"'"}"
trapStrQ="${trapStrQ//$'"'"'\t'"'"'/'"'"'$'"'"'"'"'"'"'"'"'\t'"'"'"'"'"'"}"
trapStrQ="${trapStrQ//\;/\\\;}"
}
case "${trapType}" in
EXIT)
if [[ -z "${trapStr}" ]] || [[ "${trapStr}" == '"'"'-'"'"' ]]; then
builtin trap "${timep_EXIT_TRAP_STR}" EXIT
else
builtin trap '"'"'timep_SKIP_DEBUG_FLAG=true
echo '"'"'"${trapStrQ@Q}"'"'"' >>"${timep_TMPDIR}/.log/log.${timep_NEXEC_HASH_CUR}"
'"'"'"${trapStr0}"'"'"'
timep_SKIP_DEBUG_FLAG=false
'"'"'"${timep_EXIT_TRAP_STR}" EXIT
fi
;;
RETURN)
if [[ -z "${trapStr}" ]] || [[ "${trapStr}" == '"'"'-'"'"' ]]; then
builtin trap "${timep_RETURN_TRAP_STR}" RETURN
else
builtin trap '"'"'timep_SKIP_DEBUG_FLAG=true
echo '"'"'"${trapStrQ@Q}"'"'"' >>"${timep_TMPDIR}/.log/log.${timep_NEXEC_HASH_CUR}"
'"'"'"${trapStr0}"'"'"'
timep_SKIP_DEBUG_FLAG=false
'"'"'"${timep_RETURN_TRAP_STR}" RETURN
fi
;;
DEBUG)
builtin trap "${timep_DEBUG_TRAP_STR_0}${trapStr0}${timep_DEBUG_TRAP_STR_1}" DEBUG
;;
INT|SIGINT|TERM|SIGTERM|QUIT|SIGQUIT|HUP|SIGHUP)
if [[ -z "${trapStr}" ]] || [[ "${trapStr}" == '"'"'-'"'"' ]]; then
builtin trap "${timep_SIGNAL_RELAY_TRAP_STR//\%s/"${trapType#SIG}"}" "${trapType}"
else
builtin trap '"'"'timep_SKIP_DEBUG_FLAG=true
echo '"'"'"${trapStrQ@Q}"'"'"' >>"${timep_TMPDIR}/.log/log.${timep_NEXEC_HASH_CUR}"
'"'"'"${trapStr0}"'"'"'
timep_SKIP_DEBUG_FLAG=false
'"'"'"${timep_SIGNAL_RELAY_TRAP_STR//\%s/"${trapType#SIG}"}" "${trapType}"
fi
;;
*)
if [[ -z "${trapStr}" ]]; then
builtin trap '"''"' "${trapType}"
elif [[ "${trapStr}" == '"'"'-'"'"' ]]; then
builtin trap - "${trapType}"
else
builtin trap '"'"'timep_SKIP_DEBUG_FLAG=true
echo '"'"'"${trapStrQ@Q}"'"'"' >>"${timep_TMPDIR}/.log/log.${timep_NEXEC_HASH_CUR}"
'"'"'"${trapStr0}"'"'"'
timep_SKIP_DEBUG_FLAG=false'"'"' "${trapType}"
fi
;;
esac
done
}
export -f trap
'; } >"${timep_TMPDIR}/functions.bash"
# setup a string with the command to run
case "${timep_runType}" in
s)
shift 1
timep_runCmd="$(<"${timep_runCmdPath}")"
timep_runCmd="${timep_runCmd//builtin trap /trap }"
if [[ "${timep_runCmd}" == '#!'* ]]; then
timep_runMainSrc="${timep_runCmd%%$'\n'*}"$'\n'
timep_runCmd="${timep_runCmd#*$'\n'}"
else
timep_runMainSrc='#!'"${BASH}"$'\n'
fi
;;
c)
printf -v timep_runCmd '%s\n' "${@}"
timep_runCmd="${timep_runCmd//builtin trap /trap }"
# start of wrapper code
timep_runMainSrc='#!'"${BASH}"$'\n'
;;
f)
timep_funcName="${1}"
shift 1
_timep_getFuncSrc -r "${timep_funcName}" >>"${timep_TMPDIR}/functions.bash"
printf -v timep_runCmd '%s "${@}"\n' "${timep_funcName}"
[[ -t 0 ]] || timep_runCmd+=" <&0"
# start of wrapper code
timep_runMainSrc='#!'"${BASH}"$'\n'
;;
esac
timep_runVarsSrc='
declare -g timep_BASHPID_PREV timep_BASHPID_STR timep_BASH_SUBSHELL_PREV timep_EXEC_ARG timep_BG_PID_PREV timep_CHILD_PGID timep_CHILD_TPID timep_CMD_TYPE timep_ENDTIME timep_ENDTIME0 timep_FD timep_LOCK_FD timep_FUNCNAME_STR timep_IS_BG_INDICATOR timep_IS_BG_FLAG timep_IS_FUNC_FLAG timep_IS_FUNC_FLAG_1 timep_IS_SUBSHELL_FLAG timep_SUBSHELL_INIT_FLAG timep_SUBSHELL_INIT_NEXT_FLAG timep_NEXEC_N timep_NO_PRINT_FLAG timep_NPIDWRAP timep_NPIPE0 timep_PARENT_PGID timep_PARENT_TPID timep_SIMPLEFORK_CUR_FLAG timep_SIMPLEFORK_NEXT_FLAG timep_SKIP_DEBUG_FLAG timep_SKIP_DEBUG_NEXT_FLAG timep_BASH_SUBSHELL_DIFF timep_BASH_SUBSHELL_DIFF_0 timep_KK timep_BASHPID_ADD_CUR timep_NPIDWRAP_PREV_0 timep_BASH_COMMAND_PREV_0 timep_CMD_TYPE_PREV_0 timep_BASHPID_PREV_0 timep_ENDTIME_PREV_0 timep_BASH_SUBSHELL_PREV_0 timep_BASHPID_STR_0 timep_BG_PID_COUNTER timep_LINENO_0 timep_START_UTIME0 timep_START_STIME0 timep_END_TIME timep_END_CTIME timep_START_CTIME_SELF timep_END_CTIME_SELF timep_END_UTIME timep_END_STIME timep_END_UTIME0 timep_END_STIME0 timep_pidCur timep_BASH_COMMAND_CUR timep_FUNCNAME_N timep_LINENO_INIT_FLAG timep_TRAP_OPTS timep_NEXEC_HASH_CUR timep_NEXEC_END timep_START_TIME timep_START_UTIME timep_START_STIME timep_BG_FUNC_RETURN_TRAP_FLAG
declare -ga timep_BASH_COMMAND_PREV timep_NEXEC_A timep_NPIPE timep_STARTTIME timep_A timep_LINENO timep_LINENO_OFFSET timep_LINENO_OFFSET_PREV timep_BASHPID_ADD timep_STARTTIME timep_START_CTIME_SELF_A timep_pidA timep_NEXEC_HASH_A timep_AVAILABLE_BUILTINS timep_LAST_CMD_WORD timep_IS_BG_FUNC_FLAG timep_BASH_SOURCE_N timep_IS_SOURCE_FLAG timep_FNEST
declare -gx timep_TMPDIR timep_NEXEC_0 timep_NEXEC_CUR timep_LOCK_FD timep_NPIDWRAP timep_FNEST_CUR timep_USER_BASH_ENV
: "${timep_FNEST_CUR:=0}"
: "${timep_FNEST[$timep_FNEST_CUR]:='"''"'}" "${timep_NEXEC_A[$timep_FNEST_CUR]:='"''"'}" "${timep_NEXEC_HASH_A[$timep_FNEST_CUR]:='"''"'}"
'
timep_runSetupSrc='
: & 2>/dev/null
_timep_SETUP
echo "IN BASH_ENV SETUP" >>"${timep_TMPDIR}/run.log.txt"
echo "$!" >"${timep_TMPDIR}/.log/.last_bg_pid"
exec {timep_LOCK_FD}<><(:)
printf '"'"'\n'"'"' >&${timep_LOCK_FD}
read -r _ _ _ _ timep_PARENT_PGID _ _ timep_PARENT_TPID _ </proc/${BASHPID}/stat
timep_CHILD_PGID="$timep_PARENT_PGID"
timep_CHILD_TPID="$timep_PARENT_TPID"
timep_FNEST=("${#FUNCNAME[@]}")
timep_FNEST_CUR="${#FUNCNAME[@]}"
mapfile -t timep_AVAILABLE_BUILTINS < <(enable -p | grep -E '"'"'((getCPUtime)|timep_((crc32)|(fnv1a)|(hash)))'"'"')
(( ${#timep_AVAILABLE_BUILTINS[@]} >= 4 )) || enable -f "${timep_TMPDIR0}/lib/${USER}-${EUID}/timep.so" getCPUtime timep_crc32 timep_fnv1a timep_hash || _timep_SETUP
unset "timep_AVAILABLE_BUILTINS"
timep_BASHPID_PREV="$BASHPID"
timep_BG_PID_PREV="$!"
timep_BG_PID_COUNTER='"''"'
timep_BASH_SUBSHELL_PREV="$BASH_SUBSHELL"
timep_NEXEC_N=0
timep_NEXEC_CUR=0
timep_NPIDWRAP=0
timep_BASHPID_STR="${BASHPID}"
timep_FUNCNAME_STR="main"
timep_SIMPLEFORK_NEXT_FLAG=false
timep_SIMPLEFORK_CUR_FLAG=false
timep_SKIP_DEBUG_FLAG=false
timep_SKIP_DEBUG_NEXT_FLAG=false
timep_NO_PRINT_FLAG=false
timep_IS_FUNC_FLAG_1=false
timep_SUBSHELL_INIT_FLAG=false
timep_LINENO_INIT_FLAG=true
timep_BG_FUNC_RETURN_TRAP_FLAG=false
timep_BASH_COMMAND_PREV[${timep_FNEST_CUR}]='"''"'
timep_NPIPE[${timep_FNEST_CUR}]='"'"'0'"'"'
timep_STARTTIME[${timep_FNEST_CUR}]="${EPOCHREALTIME}"
timep_BASH_SOURCE_N[${timep_FNEST_CUR}]="${#BASH_SOURCE[@]}"
timep_IS_SOURCE_FLAG[${timep_FNEST_CUR}]=false
'
for nn in INT TERM QUIT HUP; do
printf -v trapAddCur '%s' "${timep_SIGNAL_RELAY_TRAP_STR//\%s/${nn}}"
timep_runSetupSrc+=$'\n'"builtin trap '${trapAddCur//"'"/"'"'"'"'"'"'"'"}' SIG${nn}"$'\n'
done
timep_runSetupSrc+='
builtin trap "${timep_RETURN_TRAP_STR}" RETURN
builtin trap "${timep_EXIT_TRAP_STR}" EXIT
'
timep_runMainSrc='set -mT
. "${timep_TMPDIR}/vars.bash"
: "${timep_FNEST_CUR:=0}"
: "${timep_FNEST[$timep_FNEST_CUR]:='"''"'}" "${timep_NEXEC_A[$timep_FNEST_CUR]:='"''"'}" "${timep_NEXEC_HASH_A[$timep_FNEST_CUR]:='"''"'}"
[[ -x "${timep_TMPDIR0}/lib/${USER}-${EUID}/timep.so" ]] || _timep_SETUP
enable -f "${timep_TMPDIR0}/lib/${USER}-${EUID}/timep.so" getCPUtime timep_crc32 timep_fnv1a timep_hash
timep_NPIDWRAP=0
timep_NEXEC_0="{${timep_NPIDWRAP}-${BASHPID}}"
timep_NEXEC_A[$timep_FNEST_CUR]=0
timep_FNEST[$timep_FNEST_CUR]='"'"'main'"'"'
timep_hash - '"'"'timep_NEXEC_HASH_CUR'"'"' <<<"${timep_NEXEC_0}"
echo "${timep_NEXEC_0}" >"${timep_TMPDIR}/.log/.hash/log.${timep_NEXEC_HASH_CUR}"
echo "${timep_NEXEC_HASH_CUR} --> ${timep_NEXEC_0}" >>"${timep_TMPDIR}/run.log.txt"
timep_NEXEC_HASH_A=("${timep_NEXEC_HASH_CUR}")
. "${timep_TMPDIR}/functions.bash";
[[ ${BASH_ENV} ]] && ! [[ "${BASH_ENV}" == "${timep_TMPDIR}/env.bash" ]] && export timep_USER_BASH_ENV="${BASH_ENV}"
export BASH_ENV="${timep_TMPDIR}/env.bash"
. "${timep_TMPDIR}/setup.bash"
echo "${EPOCHREALTIME//[^0-9]/}" >"${timep_TMPDIR}/.log/.final.start.wtime"
builtin trap "${timep_DEBUG_TRAP_STR_0}${timep_DEBUG_TRAP_STR_1}" DEBUG
'
${timep_timeFlag} && timep_runMainSrc+='
time {
'
timep_runMainSrc+='
{
'"${timep_runCmd}"'
} 0<&${timep_FD0} 1>&${timep_FD1} 2>&${timep_FD2}
'
${timep_timeFlag} && timep_runMainSrc+='
} 1>&${timep_FD2}
'
timep_runMainSrc+='
builtin trap - DEBUG EXIT RETURN SIGTERM SIGQUIT SIGHUP SIGINT;
exec {timep_LOCK_FD}>&-
echo "${EPOCHREALTIME//[^0-9]/}" >"${timep_TMPDIR}/.log/.final.end.wtime"
'"${timep_END_CTIME_STR}"'
echo "${timep_END_CTIME//[^0-9]/}" >"${timep_TMPDIR}/.log/.final.end.ctime"