interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t0211 / scrub_perf.perl

91 lines · 2536 bytes Raw Blame History
1#!/usr/bin/perl
2#
3# Scrub the variable fields from the perf trace2 output to
4# make testing easier.
5
6use strict;
7use warnings;
8
9my $qpath = '\'[^\']*\'|[^ ]*';
10
11my $col_depth=0;
12my $col_thread=1;
13my $col_event=2;
14my $col_repo=3;
15my $col_t_abs=4;
16my $col_t_rel=5;
17my $col_category=6;
18my $col_rest=7;
19
20# This code assumes that the trace2 data was written with bare
21# turned on (which omits the "<clock> <file>:<line> | <parents>"
22# prefix.
23
24while (<>) {
25 my @tokens = split /\|/;
26
27 foreach my $col (@tokens) { $col =~ s/^\s+|\s+$//g; }
28
29 if ($tokens[$col_event] =~ m/^start/) {
30 # The 'start' message lists the contents of argv in $col_rest.
31 # On some platforms (Windows), argv[0] is *sometimes* a canonical
32 # absolute path to the EXE rather than the value passed in the
33 # shell script. Replace it with a placeholder to simplify our
34 # HEREDOC in the test script.
35 my $argv0;
36 my $argvRest;
37 $tokens[$col_rest] =~ s/^($qpath)\W*(.*)/_EXE_ $2/;
38 }
39 elsif ($tokens[$col_event] =~ m/cmd_path/) {
40 # Likewise, the 'cmd_path' message breaks out argv[0].
41 #
42 # This line is only emitted when RUNTIME_PREFIX is defined,
43 # so just omit it for testing purposes.
44 # $tokens[$col_rest] = "_EXE_";
45 goto SKIP_LINE;
46 }
47 elsif ($tokens[$col_event] =~ m/cmd_ancestry/) {
48 # 'cmd_ancestry' is platform-specific and not implemented everywhere,
49 # so skip it.
50 goto SKIP_LINE;
51 }
52 elsif ($tokens[$col_event] =~ m/child_exit/) {
53 $tokens[$col_rest] =~ s/ pid:\d* / pid:_PID_ /;
54 }
55 elsif ($tokens[$col_event] =~ m/data/) {
56 if ($tokens[$col_category] =~ m/process/) {
57 # 'data' and 'data_json' events containing 'process'
58 # category data are assumed to be platform-specific
59 # and highly variable. Just omit them.
60 goto SKIP_LINE;
61 }
62 if ($tokens[$col_category] =~ m/fsync/) {
63 # fsync events aren't interesting for the test
64 goto SKIP_LINE;
65 }
66 }
67 elsif ($tokens[$col_event] =~ m/timer/) {
68 # This also captures "th_timer" events
69 $tokens[$col_rest] =~ s/ total:\d+\.\d*/ total:_T_TOTAL_/;
70 $tokens[$col_rest] =~ s/ min:\d+\.\d*/ min:_T_MIN_/;
71 $tokens[$col_rest] =~ s/ max:\d+\.\d*/ max:_T_MAX_/;
72 }
73
74 # t_abs and t_rel are either blank or a float. Replace the float
75 # with a constant for matching the HEREDOC in the test script.
76 if ($tokens[$col_t_abs] =~ m/\d/) {
77 $tokens[$col_t_abs] = "_T_ABS_";
78 }
79 if ($tokens[$col_t_rel] =~ m/\d/) {
80 $tokens[$col_t_rel] = "_T_REL_";
81 }
82
83 my $out;
84
85 $out = join('|', @tokens);
86 print "$out\n";
87
88 SKIP_LINE:
89}
90
91