1 subroutine da_trace_exit(&
3 Message, & ! in, optional
4 Messages, & ! in, optional
5 MaxNoCalls) ! in, optional
7 !-----------------------------------------------------------------------
8 ! Purpose: Trace exit from subroutine
9 !-----------------------------------------------------------------------
13 character (len=*), intent(in) :: Name ! subroutine name
14 character (len=*), optional, intent(in) :: Message ! text to trace
15 character (len=*), optional, intent(in) :: Messages(:) ! text to trace
16 integer, optional, intent(in) :: MaxNoCalls ! max no calls to show
18 integer :: IOStatus ! I-O return code
19 integer :: Loop ! General loop counter
22 integer :: LocalMaxNoCalls
27 character(len=25) :: Change
29 call cpu_time(temp_CPUTime)
34 !======================================================================
35 ! check whether trace active and whether depth exceeded
36 !======================================================================
38 if (.NOT. TraceActive) then
43 ! was tracing enabled by this routine? If it was, disable it, to
44 ! take affect after the trace line has been written
45 if (Name == TraceStartedBy(1:LEN(Name))) then
50 temp1 = real(Count - BaseElapsedTime) - ElapsedTimeLocalStart
51 temp2 = temp_CPUTime - CPUTimeLocalStart
53 TraceDepth=TraceDepth-1
55 if (TraceDepth < 0) then
59 !=======================================================================
60 ! Check timing and maximum heap memory usage
61 !=======================================================================
63 ElapsedTimeLocal(Pointer) = ElapsedTimeLocal(Pointer) + temp1
64 ElapsedTimeThisCall(Pointer) = ElapsedTimeThisCall(Pointer) + temp1
65 ElapsedTime(Pointer) = ElapsedTime(Pointer) + &
66 ElapsedTimeThisCall(Pointer)
68 CPUTimeLocal(Pointer) = CPUTimeLocal(Pointer) + temp2
69 CPUTimeThisCall(Pointer) = CPUTimeThisCall(Pointer) + temp2
70 CPUTime(Pointer) = CPUTime(Pointer) + CPUTimeThisCall(Pointer)
72 Caller=CalledBy(Pointer)
74 ElapsedTimeThisCall(Caller) = ElapsedTimeThisCall(Caller) + &
75 ElapsedTimeThisCall(Pointer)
76 CPUTimeThisCall(Caller) = CPUTimeThisCall(Caller) + CPUTimeThisCall(Pointer)
81 if (trace_memory) then
84 if (EntryHeap(Pointer) < TotalSpace) then
85 write(Change,"(A9,I12)")", BIGGER", TotalSpace - EntryHeap(Pointer)
86 else if (EntryHeap(Pointer) > TotalSpace) then
87 write(Change,"(A9,I12)")", SMALLER", TotalSpace - EntryHeap(Pointer)
89 if (MaxHeap(Pointer) < TotalSpace) then
90 MaxHeap(Pointer) = TotalSpace
96 if (trace_write .AND. TraceDepth <= trace_max_depth) then
98 if (present(MaxNoCalls)) then
99 LocalMaxNoCalls = MaxNoCalls
101 LocalMaxNoCalls = trace_repeat_head
106 if (NoCalls(Pointer) <= LocalMaxNoCalls) then
107 if (trace_memory) then
109 write (unit=trace_unit, &
110 fmt='(A, "< <a href=",A,"/",A,".html>",A,"</a>",I11,A)', &
112 pad(1:TraceDepth*TraceIndentAmount),trim(Documentation_url), &
113 trim(Name),trim(Name), TotalSpace, Change
115 write (unit=trace_unit, &
116 fmt='(A, "< ",A,I11,A)', &
118 pad(1:TraceDepth*TraceIndentAmount),trim(Name), TotalSpace, Change
122 write (unit=trace_unit, &
123 fmt='(A, "< <a href=",A,"/",A,".html>",A,"</a>")', &
125 pad(1:TraceDepth*TraceIndentAmount),trim(Documentation_url), &
126 trim(Name),trim(Name)
128 write (unit=trace_unit, fmt='(A, "< ",A)', iostat=IOStatus) &
129 pad(1:TraceDepth*TraceIndentAmount),trim(Name)
133 if (IOStatus /= 0) then
134 call da_error(__FILE__,__LINE__, &
135 (/"Cannot write to trace file for "//Name/))
138 if (present(Message)) then
139 write (unit=trace_unit, fmt='(A," ",A)', iostat=IOStatus) &
140 pad(1:TraceDepth*TraceIndentAmount),trim(Message)
141 if (IOStatus .NE. 0) then
142 call da_error(__FILE__,__LINE__, &
143 (/"Cannot write to trace file for "//Name/))
147 if (present(Messages)) then
148 do Loop = 1, size(Messages)
149 write (unit=trace_unit, fmt='(A," ",A)', iostat=IOStatus) &
150 pad(1:TraceDepth*TraceIndentAmount),trim(Messages(Loop))
151 if (IOStatus .NE. 0) then
152 call da_error(__FILE__,__LINE__, &
153 (/"Cannot write to trace file for "//Name/))
159 if (NoCalls(Pointer) == trace_repeat_head) then
160 write(unit=trace_unit,fmt='(A," Called enough, going quiet")', &
162 pad(1:TraceDepth*TraceIndentAmount)
163 if (IOStatus .NE. 0) then
164 call da_error(__FILE__,__LINE__, &
165 (/"Cannot write to trace file for "//Name/))
171 Pointer = CalledBy(Pointer)
178 elapsedtimelocalstart = real(count-baseelapsedtime)
179 call cpu_time(cputimelocalstart)
181 ! call flush(trace_unit)
183 end subroutine da_trace_exit