| 1 | # /=====================================================================\ # | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | LaTeXML::Core::Definition | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # | Representation of definitions of Control Sequences | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # |=====================================================================| # | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # | Part of LaTeXML: | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # | Public domain software, produced as part of work done by the | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # | United States Government & not subject to copyright in the US. | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # |---------------------------------------------------------------------| # | ||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # | Bruce Miller <bruce.miller@nist.gov> #_# | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # | http://dlmf.nist.gov/LaTeXML/ (o o) | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # \=========================================================ooo==U==ooo=/ # | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | package LaTeXML::Core::Definition; | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use LaTeXML::Global; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use LaTeXML::Common::Object; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use LaTeXML::Core::Token; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 5 | ▶ | use LaTeXML::Core::Parameters; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 5 | ▶ | use LaTeXML::Common::Error; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | ▶ | use Time::HiRes; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 5 | ▶ | use base qw(LaTeXML::Common::Object); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # Make these present, but do not import. | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | require LaTeXML::Core::Definition::Expandable; | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | require LaTeXML::Core::Definition::Conditional; | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | require LaTeXML::Core::Definition::Primitive; | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | require LaTeXML::Core::Definition::Register; | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | require LaTeXML::Core::Definition::CharDef; | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | require LaTeXML::Core::Definition::Constructor; | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | #********************************************************************** | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub isaDefinition { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isaDefinition: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | return 1; } | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub getCS { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getCS: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | return $$self{cs}; } | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub getCSName { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getCSName: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | return (defined $$self{alias} ? $$self{alias} : $$self{cs}->getCSName); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # NOTE: Need to clean up alias; really should already be Token (or Tokens?) | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # and is not always a CS! | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub getCSorAlias { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getCSorAlias: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | return (defined $$self{alias} ? T_CS($$self{alias}) : $$self{cs}); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub isExpandable { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isExpandable: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | return 0; } | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub isRegister { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isRegister: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | return ''; } | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub isPrefix { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isPrefix: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | return 0; } | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # The following come from flags, but probably(?) only make sense for Expandable (macros) | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # and furthermore, only isProtected is used for anything significant. | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub isProtected { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isProtected: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | return $$self{isProtected}; } | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub setIsProtected { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setIsProtected: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $$self{isProtected} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | return; } | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub isOuter { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isOuter: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | return $$self{isOuter}; } | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub setIsOuter { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setIsOuter: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $$self{isOuter} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | return; } | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub isLong { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isLong: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | return $$self{isLong}; } | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub setIsLong { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setIsLong: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $$self{isLong} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | return; } | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub getLocator { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getLocator: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | return $$self{locator}; } | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub readArguments { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readArguments: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my ($self, $gullet) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | return ($$self{parameters} ? $$self{parameters}->readArguments($gullet, $self) : ()); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub getParameters { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getParameters: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | return $$self{parameters}; } | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | #====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # Overriding methods | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub stringify { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $type = ref $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $type =~ s/^LaTeXML:://; | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | my $name = ($$self{alias} || $$self{cs}->getCSName); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{'alias'} || $self->{'cs'}->getCSName
MC/DC0%0/2
$self->{'alias'} || $self->{'cs'}->getCSName
$self->{'alias'}
$self->{'cs'}->getCSName
Truth table0%0/3
A || B
A= $self->{'alias'}B= $self->{'cs'}->getCSName
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | return $type . '[' . ($$self{parameters} | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | ? $name . ' ' . Stringify($$self{parameters}) : $name) . ']'; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub toString { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
toString: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | return ($$self{parameters} | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | ? ToString($$self{cs}) . ' ' . ToString($$self{parameters}) : ToString($$self{cs})); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | #====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # Tracing support | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub tracingCSName { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tracingCSName: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $parameters = $$self{parameters}; | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | return ToString($self->getCSName) | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # Show parameter string too | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | . ($parameters ? ' ' . ToString($parameters) : '') | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # And if this was \let to something show the name it was called by | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | . ($LaTeXML::CURRENT_TOKEN && !$$self{cs}->equals($LaTeXML::CURRENT_TOKEN) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$LaTeXML::CURRENT_TOKEN and not $self->{"cs"}->equals($LaTeXML::CURRENT_TOKEN)
MC/DC0%0/2
$LaTeXML::CURRENT_TOKEN and not $self->{"cs"}->equals($LaTeXML::CURRENT_TOKEN)
$LaTeXML::CURRENT_TOKEN
not $self->{"cs"}->equals($LaTeXML::CURRENT_TOKEN)
Truth table0%0/3
A and not(B)
A= $LaTeXML::CURRENT_TOKENB= not $self->{"cs"}->equals($LaTeXML::CURRENT_TOKEN)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | ? ' [for ' . ToString($LaTeXML::CURRENT_TOKEN) . ']' : ''); } | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub tracingArgs { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tracingArgs: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $i = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | return join("\n", map { '#' . $i++ . '<-' . tracingArgToString($_) } @args); } | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # Annoying special handing of registers | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | sub tracingArgToString { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tracingArgToString: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | return (ref $arg eq 'ARRAY' ? '[' . join(',', map { ToString($_) } @$arg) . ']' : ToString($arg)); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | #====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # Profiling support | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | #====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # If the value PROFILING is true, we'll collect some primitive profiling info. | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # Start profiling $CS (typically $LaTeXML::CURRENT_TOKEN) | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # Call from within ->invoke. | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # $mode = expand | digest | absorb | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub startProfiling { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
startProfiling: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my ($cs, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my $name = $cs->getCSName; | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my $entry = $STATE->lookupMapping('runtime_profile', $name); | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | # [#calls, max_depth, inclusive_time, exclusive_time, #pending | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # starts of pending calls...] | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if (!defined $entry) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $entry = [0, 0, 0, 0, 0]; $STATE->assignMapping('runtime_profile', $name, $entry); } | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | $$entry[0]++ unless $mode eq 'absorb'; # One more call. | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $$entry[4]++; # One more pending... | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | #Debug("START PROFILE $mode of ".ToString($cs)); | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | $STATE->pushValue('runtime_stack', [$name, $mode, [Time::HiRes::gettimeofday], $entry]); | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | return; } | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # Stop profiling $CS. | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # Complication w/Macros: If the expansion of a macro contains CS's that read tokens, | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # the end MARKER of macros may get read before the macro's effects have really been processed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # So we need to ignore a stop on a macro that isn't at the top of the stack, | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # and conversely, automatically stop a macro that is at the top above a CS that is being stopped. | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | sub stopProfiling { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stopProfiling: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my ($cs, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | $cs = $cs->getString if $cs->getCatcode == CC_MARKER; # Special case for macros!! | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | return unless ref $cs; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $name = $cs->getCSName; | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my $stack = $STATE->lookupValue('runtime_stack'); | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | my $currdepth = scalar(@$stack); | |||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | my $prevdepth = $STATE->lookupValue('runtime_maxdepth') || '0'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$LaTeXML::Core::Definition::STATE->lookupValue('runtime_maxdepth') || '0'
MC/DC0%0/1
$LaTeXML::Core::Definition::STATE->lookupValue('runtime_maxdepth') || '0'
$LaTeXML::Core::Definition::STATE->lookupValue('runtime_maxdepth')
Truth table0%0/2
A
A= $LaTeXML::Core::Definition::STATE->lookupValue('runtime_maxdepth')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | $STATE->assignValue('runtime_maxdepth' => $currdepth, 'global') if $currdepth > $prevdepth; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | while (@{$stack}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | my ($top, $topmode, $t0, $entry) = @{ $$stack[-1] }; | |||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | if ((($top ne $name) || ($topmode ne $mode)) && ($topmode ne 'expand')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$top ne $name || $topmode ne $mode and $topmode ne "expand"
$top ne $name or $topmode ne $mode
MC/DC0%0/3
$top ne $name || $topmode ne $mode and $topmode ne "expand"
$top ne $name
$topmode ne $mode
$topmode ne "expand"
Truth table0%0/5
A or B and C
A= $top ne $nameB= $topmode ne $modeC= $topmode ne "expand"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | return if $mode eq 'expand'; # No error (yet) if this is a macro end marker. | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | Debug("PROFILE Error: ending $mode of $name but stack holds " | ||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | . join(',', map { $$_[0] . '(' . $$_[1] . ')' } @$stack) . ", $top ($topmode)"); | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | return; } | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | pop(@$stack); | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | my $duration = Time::HiRes::tv_interval($t0, [Time::HiRes::gettimeofday]); | |||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my $depth = $$entry[4]; | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | if ($depth > $$entry[1]) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | $$entry[1] = $depth; } | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | $$entry[2] += $duration if $depth == 1; # add to inclusive time only in uppermost call | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | $$entry[3] += $duration; # add to exclusive time (see below) | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | $$entry[4]--; | |||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | if (my $caller = $$stack[-1]) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | my ($callername, $callermode, $callerstart, $callerentry) = @$caller; | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $$callerentry[3] -= $duration; } # Remove our cost from caller's exclusive time. | |||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | return if $top eq $name; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | Debug("PROFILE Error: ending $mode of $name but stack is empty") | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | unless $mode eq 'expand'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | return; } | |||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | our $MAX_PROFILE_ENTRIES = 30; # [CONSTANT] | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # Print out profiling information, if any was collected | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | sub showProfile { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
showProfile: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | if (my $profile = $STATE->lookupValue('runtime_profile')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my @cs = keys %$profile; | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | my $calls = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | map { $calls += $$profile{$_}[0] } @cs; | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my $depth = $STATE->lookupValue('runtime_maxdepth'); | |||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my @frequent = sort { $$profile{$b}[0] <=> $$profile{$a}[0] } @cs; | |||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | @frequent = @frequent[0 .. $MAX_PROFILE_ENTRIES]; | |||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | my @deepest = sort { $$profile{$b}[1] <=> $$profile{$a}[1] } @cs; | |||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | @deepest = @deepest[0 .. $MAX_PROFILE_ENTRIES]; | |||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | my @inclusive = sort { $$profile{$b}[2] <=> $$profile{$a}[2] } @cs; | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | @inclusive = @inclusive[0 .. $MAX_PROFILE_ENTRIES]; | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | my @exclusive = sort { $$profile{$b}[3] <=> $$profile{$a}[3] } @cs; | |||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | @exclusive = @exclusive[0 .. $MAX_PROFILE_ENTRIES]; | |||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | Debug("Profiling results:"); | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | Debug("Total calls: $calls; Maximum depth: $depth"); | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | Debug("Most frequent:\n " | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | . join(', ', map { $_ . ':' . $$profile{$_}[0] } @frequent)); | |||||||||||||||||||||||||||||||||||||||||||||
| 217 | Debug("Deepest :\n " | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | . join(', ', map { $_ . ':' . $$profile{$_}[1] } @deepest)); | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | Debug("Most expensive inclusive:\n " | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | . join(', ', map { $_ . ':' . sprintf("%.2fs/%d", $$profile{$_}[2], $$profile{$_}[0]) } @inclusive)); | |||||||||||||||||||||||||||||||||||||||||||||
| 221 | Debug("Most expensive exclusive:\n " | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | . join(', ', map { $_ . ':' . sprintf("%.2fs/%d", $$profile{$_}[3], $$profile{$_}[0]) } @exclusive)); | |||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | my $stack = $STATE->lookupValue('runtime_stack'); | |||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if (@$stack) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | Debug("The following were never marked as done:\n " | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | . join(', ', map { $$_[0] . '(' . $$_[1] . ')' } @$stack)); } } | |||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | return; } | |||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | #=============================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||
| 232 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||