Merge lp:~nickpapior/siesta/4.0-json-time into lp:~albertog/siesta/4.0-json-time

Proposed by Nick Papior
Status: Merged
Approved by: Alberto Garcia
Approved revision: 559
Merged at revision: 559
Proposed branch: lp:~nickpapior/siesta/4.0-json-time
Merge into: lp:~albertog/siesta/4.0-json-time
Diff against target: 136 lines (+29/-40)
2 files modified
Src/timer_tree.f90 (+28/-39)
version.info (+1/-1)
To merge this branch: bzr merge lp:~nickpapior/siesta/4.0-json-time
Reviewer Review Type Date Requested Status
Alberto Garcia Approve
Review via email: mp+337934@code.launchpad.net

Description of the change

Small changes and removed unnecessary arguments.

These are merely suggestions to remove some of the logic.

I.e. before two (optional) flags where passed, one to decide whether JSON should be written, and another to specify the unit.

It may make more sense to:
If JSON unit is passed, then write. Else, don't write JSON.

Also, used m_io for unit retrieval.

To post a comment you must log in.
Revision history for this message
Alberto Garcia (albertog) wrote :

Approved, but you were too quick about the border cases, and you had extra braces.
We avoid the m_io dependency for now.

review: Approve
Revision history for this message
Nick Papior (nickpapior) wrote :

Ok, thanks for fixing my mistakes.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Src/timer_tree.f90'
--- Src/timer_tree.f90 2018-02-12 15:41:16 +0000
+++ Src/timer_tree.f90 2018-02-19 08:20:19 +0000
@@ -254,11 +254,11 @@
254 !------------------------------------------------254 !------------------------------------------------
255 subroutine timer_report_global()255 subroutine timer_report_global()
256256
257 use m_io, only: io_assign, io_close
258
257 integer :: i, js_lun259 integer :: i, js_lun
258 type(times_t), pointer :: qd260 type(times_t), pointer :: qd
259261
260 logical :: json_output
261
262 p => global_section262 p => global_section
263 ! Assign to the global section the sum of the times263 ! Assign to the global section the sum of the times
264 ! of its children264 ! of its children
@@ -269,47 +269,46 @@
269 enddo269 enddo
270 p%data%totTime = globaltime + 1.0e-6_dp270 p%data%totTime = globaltime + 1.0e-6_dp
271271
272 json_output = .true.272 ! Open JSON
273 call get_unit_number(js_lun)273 call io_assign(js_lun)
274 open(unit=js_lun,file="time.json",form="formatted", &274 open(unit=js_lun, file="time.json", form="formatted", &
275 action="write",position="rewind")275 action="write",position="rewind")
276 276
277 write(*,"(/,a20,T30,a6,a12,a8)") "Section","Calls","Walltime","%"277 write(*,"(/,a20,T30,a6,a12,a8)") "Section","Calls","Walltime","%"
278278
279 write(js_lun,*) '{'279 call walk_tree(p,0, js_lun=js_lun)
280 call walk_tree(p,0,json=json_output,js_lun=js_lun)280
281 write(js_lun,*) '}'281 call io_close(js_lun)
282 if (json_output) close(js_lun)
283 282
284 end subroutine timer_report_global283 end subroutine timer_report_global
285284
286 !------------------------------------------------285 !------------------------------------------------
287 recursive subroutine walk_tree(p,level,maxlevel,json,js_lun)286 recursive subroutine walk_tree(p,level,maxlevel,js_lun)
288 type(section_t), intent(in),target :: p287 type(section_t), intent(in),target :: p
289 integer, intent(in) :: level288 integer, intent(in) :: level
290 integer, intent(in), optional:: maxlevel289 integer, intent(in), optional:: maxlevel
291 logical, intent(in), optional:: json
292 integer, intent(in), optional:: js_lun290 integer, intent(in), optional:: js_lun
293291
294 integer :: i292 integer :: i
295 character(len=40) fmtstr, fmt_json, fmt_json_head293 character(len=64) fmtstr, fmt_json, fmt_json_head
296 logical :: json_output294 logical :: json_output
297295
298 json_output = .false.296 ! Determine whether we should output JSON
299 if (present(json)) then297 ! If the unit is there, we output to JSON as well
300 json_output = json298 json_output = present(js_lun)
301 if (.not. present(js_lun)) then299
302 call die("Need a js_lun for json timer output")
303 endif
304 endif
305 if (present(maxlevel)) then300 if (present(maxlevel)) then
306 if (level > maxlevel) RETURN301 if (level > maxlevel) RETURN
307 endif302 end if
303
304 if ( json_output ) then
305 write(js_lun,*) '{'
306 end if
307
308 pd => p%data308 pd => p%data
309 write(fmtstr,"(a,i0,a1,a)") "(", level+1, "x", ",a20,T30,i6,f12.3,f8.2)"309 write(fmtstr,"(a,i0,a1,a)") "(", level+1, "x", ",a20,T30,i6,f12.3,f8.2)"
310 310
311 write(*,fmtstr) pd%name, pd%nCalls, &311 write(*,fmtstr) pd%name, pd%nCalls, pd%totTime, 100*pd%totTime/globaltime
312 pd%totTime, 100*pd%totTime/globaltime
313 if (json_output) then312 if (json_output) then
314 write(fmt_json,"(a,i0,a1,a)") "(",2*level+1,"x",",a,i0,a,f12.3,a,f8.2)"313 write(fmt_json,"(a,i0,a1,a)") "(",2*level+1,"x",",a,i0,a,f12.3,a,f8.2)"
315 write(fmt_json_head,"(a,i0,a)") "(", 2*level+1, "x,a)"314 write(fmt_json_head,"(a,i0,a)") "(", 2*level+1, "x,a)"
@@ -317,11 +316,11 @@
317 '"' // trim(pd%name) // '": { "_calls": ', pd%nCalls, &316 '"' // trim(pd%name) // '": { "_calls": ', pd%nCalls, &
318 ', "_time": ', pd%totTime, &317 ', "_time": ', pd%totTime, &
319 ', "_%": ', 100*pd%totTime/globaltime318 ', "_%": ', 100*pd%totTime/globaltime
320 endif319 end if
321 if (p%nchildren /= 0) then320 if (p%nchildren /= 0) then
322 if (json_output) write(js_lun,"(a)") ","321 if (json_output) write(js_lun,"(a)") ","
323 do i=1,p%nchildren322 do i=1,p%nchildren
324 call walk_tree(p%child(i),level+1,maxlevel,json,js_lun)323 call walk_tree(p%child(i),level+1,maxlevel, js_lun)
325 if (json_output) then324 if (json_output) then
326 if (i < p%nchildren) then325 if (i < p%nchildren) then
327 write(js_lun,fmt="(a)") ','326 write(js_lun,fmt="(a)") ','
@@ -336,6 +335,10 @@
336 if (json_output) write(js_lun,fmt="(a)",advance="no") "}"335 if (json_output) write(js_lun,fmt="(a)",advance="no") "}"
337 endif336 endif
338337
338 if ( json_output ) then
339 write(js_lun,*) '}'
340 end if
341
339 end subroutine walk_tree342 end subroutine walk_tree
340343
341 !------------------------------------------------344 !------------------------------------------------
@@ -396,18 +399,4 @@
396 endif399 endif
397 end subroutine current_time400 end subroutine current_time
398401
399subroutine get_unit_number(lun)
400integer, intent(out) :: lun
401
402logical :: used
403integer :: iostat
404
405do lun= 10, 99
406 inquire(unit=lun, opened=used, iostat=iostat)
407 if (iostat .ne. 0) used = .true.
408 if (.not. used) return
409enddo
410call die("Cannot get unit for timer output")
411end subroutine get_unit_number
412
413end module m_timer_tree402end module m_timer_tree
414403
=== modified file 'version.info'
--- version.info 2018-02-15 15:45:23 +0000
+++ version.info 2018-02-19 08:20:19 +0000
@@ -1,3 +1,3 @@
1siesta-4.0--555--json-time-31siesta-4.0--555--json-time-3--npa-1
22
33

Subscribers

People subscribed via source and target branches

to all changes: