comparison src/testdir/test_profile.vim @ 28373:2ddf8aa1252c v8.2.4712

patch 8.2.4712: only get profiling information after exiting Commit: https://github.com/vim/vim/commit/18ee0f603ebd3c091f6d2ab88e652fda32821048 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Fri Apr 8 13:23:19 2022 +0100 patch 8.2.4712: only get profiling information after exiting Problem: Only get profiling information after exiting. Solution: Add "profile dump" and "profile stop". (Marco Hinz, Yegappan Lakshmanan, closes #10107)
author Bram Moolenaar <Bram@vim.org>
date Fri, 08 Apr 2022 14:30:03 +0200
parents 554f493902ea
children 008808e60963
comparison
equal deleted inserted replaced
28372:efc1c3dc2b0d 28373:2ddf8aa1252c
426 426
427 call delete('Xprofile_file.vim') 427 call delete('Xprofile_file.vim')
428 call delete('Xprofile_file.log') 428 call delete('Xprofile_file.log')
429 endfunc 429 endfunc
430 430
431 " Test for ':profile stop' and ':profile dump' commands
432 func Test_profile_stop_dump()
433 call delete('Xprof1.out')
434 call delete('Xprof2.out')
435 call delete('Xprof3.out')
436 func Xprof_test1()
437 return "Hello"
438 endfunc
439 func Xprof_test2()
440 return "World"
441 endfunc
442
443 " Test for ':profile stop'
444 profile start Xprof1.out
445 profile func Xprof_test1
446 call Xprof_test1()
447 profile stop
448
449 let lines = readfile('Xprof1.out')
450 call assert_equal(17, len(lines))
451 call assert_equal('FUNCTION Xprof_test1()', lines[0])
452 call assert_match('Defined:.*test_profile.vim:', lines[1])
453 call assert_equal('Called 1 time', lines[2])
454 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[3])
455 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[4])
456 call assert_equal('', lines[5])
457 call assert_equal('count total (s) self (s)', lines[6])
458 call assert_match('^\s*1\s\+.*\sreturn "Hello"$', lines[7])
459 call assert_equal('', lines[8])
460 call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[9])
461 call assert_equal('count total (s) self (s) function', lines[10])
462 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Xprof_test1()$', lines[11])
463 call assert_equal('', lines[12])
464 call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[13])
465 call assert_equal('count total (s) self (s) function', lines[14])
466 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Xprof_test1()$', lines[15])
467 call assert_equal('', lines[16])
468
469 " Test for ':profile stop' for a different function
470 profile start Xprof2.out
471 profile func Xprof_test2
472 call Xprof_test2()
473 profile stop
474 let lines = readfile('Xprof2.out')
475 call assert_equal(17, len(lines))
476 call assert_equal('FUNCTION Xprof_test2()', lines[0])
477 call assert_match('Defined:.*test_profile.vim:', lines[1])
478 call assert_equal('Called 1 time', lines[2])
479 call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[3])
480 call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[4])
481 call assert_equal('', lines[5])
482 call assert_equal('count total (s) self (s)', lines[6])
483 call assert_match('^\s*1\s\+.*\sreturn "World"$', lines[7])
484 call assert_equal('', lines[8])
485 call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[9])
486 call assert_equal('count total (s) self (s) function', lines[10])
487 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Xprof_test2()$', lines[11])
488 call assert_equal('', lines[12])
489 call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[13])
490 call assert_equal('count total (s) self (s) function', lines[14])
491 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Xprof_test2()$', lines[15])
492 call assert_equal('', lines[16])
493
494 " Test for ':profile dump'
495 profile start Xprof3.out
496 profile func Xprof_test1
497 profile func Xprof_test2
498 call Xprof_test1()
499 profile dump
500 " dump the profile once and verify the contents
501 let lines = readfile('Xprof3.out')
502 call assert_equal(17, len(lines))
503 call assert_match('^\s*1\s\+.*\sreturn "Hello"$', lines[7])
504 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Xprof_test1()$', lines[11])
505 call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Xprof_test1()$', lines[15])
506 " dump the profile again and verify the contents
507 call Xprof_test2()
508 profile dump
509 profile stop
510 let lines = readfile('Xprof3.out')
511 call assert_equal(28, len(lines))
512 call assert_equal('FUNCTION Xprof_test1()', lines[0])
513 call assert_match('^\s*1\s\+.*\sreturn "Hello"$', lines[7])
514 call assert_equal('FUNCTION Xprof_test2()', lines[9])
515 call assert_match('^\s*1\s\+.*\sreturn "World"$', lines[16])
516
517 delfunc Xprof_test1
518 delfunc Xprof_test2
519 call delete('Xprof1.out')
520 call delete('Xprof2.out')
521 call delete('Xprof3.out')
522 endfunc
523
524 " Test for :profile sub-command completion
431 func Test_profile_completion() 525 func Test_profile_completion()
432 call feedkeys(":profile \<C-A>\<C-B>\"\<CR>", 'tx') 526 call feedkeys(":profile \<C-A>\<C-B>\"\<CR>", 'tx')
433 call assert_equal('"profile continue file func pause start', @:) 527 call assert_equal('"profile continue dump file func pause start stop', @:)
434 528
435 call feedkeys(":profile start test_prof\<C-A>\<C-B>\"\<CR>", 'tx') 529 call feedkeys(":profile start test_prof\<C-A>\<C-B>\"\<CR>", 'tx')
436 call assert_match('^"profile start.* test_profile\.vim', @:) 530 call assert_match('^"profile start.* test_profile\.vim', @:)
437 531
438 call feedkeys(":profile file test_prof\<Tab>\<C-B>\"\<CR>", 'tx') 532 call feedkeys(":profile file test_prof\<Tab>\<C-B>\"\<CR>", 'tx')
479 573
480 func Test_profile_errors() 574 func Test_profile_errors()
481 call assert_fails("profile func Foo", 'E750:') 575 call assert_fails("profile func Foo", 'E750:')
482 call assert_fails("profile pause", 'E750:') 576 call assert_fails("profile pause", 'E750:')
483 call assert_fails("profile continue", 'E750:') 577 call assert_fails("profile continue", 'E750:')
578 call assert_fails("profile stop", 'E750:')
579 call assert_fails("profile dump", 'E750:')
484 endfunc 580 endfunc
485 581
486 func Test_profile_truncate_mbyte() 582 func Test_profile_truncate_mbyte()
487 if &enc !=# 'utf-8' 583 if &enc !=# 'utf-8'
488 return 584 return