Trace Visualizing tool versus delta T Trace Visualizing Tool Little CoCreate WorkManager Debugging Macro which runs through all loaded macros and tags each of them with let run_stat '->macroname' at the beginning of the macro and let run_stat '<-macroname' at the end of the macro ( and before "RETURN"s and before "CANCEL"s ) so you can see in the trace which macros have been called and which have returned. Additionally, if you start dTraVis instead of TraVis, you get timestamps before each SQL_QUERY and after each SQL_QUERY, so you get the delta T in seconds of the duration each SQL_QUERY took to find out which Queries took most of your valuable time in the code. { IDEE: Hinzufgen: LET l_qry_lines ( LTAB_ROWS qry_table ) } DEFINE dtravis {**************************************************************************** * * MACRO : dtravis * PURPOSE : tags all loaded macros with '->[macroname]' and '<-[macroname]' for faster debugging * * PARAMETER : * * FILEDESCR : * * RESULTFILE : * * GLOBAL : * * AUTHOR : Tim Doerfler * CREATE_DATE : 20-OCT-2003 * * MODIFICATIONS: * * *****************************************************************************} local i local oneline local macroname local l_line local l_written local has_locals local last_line local last_last local last_local local l_avoid let l_avoid 'cm_get_elem_infos;cm_get_elem_elid;cm_get_equip_location;cm_divide_string;cm_push_cleanup;cm_get_elem_id;cm_sync_dde' let l_avoid 'cm_sync_dde;cm_push_cleanup' save_macro all del_old 'c:\temp\tra_dump.mac' open_infile 1 'c:\temp\tra_dump.mac' open_outfile 2 del_old 'c:\temp\travis.mac' let oneline '' let locals_area FALSE let l_written FALSE let has_locals FALSE let run_stat '' let last_line '' let last_local 0 read_file 1 oneline LET l_next_write_sql_delta FALSE while ( oneline <> 'END-OF-FILE' ) let last_local ( last_local + 1 ) if ( ( ( pos ( trim oneline ) 'DEFINE' ) = 1 ) and ( ( trim oneline ) <> 'END_DEFINE' ) ) let macroname ( substr oneline 8 ( ( len oneline ) - 7 ) ) let has_locals FALSE LET l_sqlqry_found FALSE let last_local 0 END_IF { -- TD: 09-JUN-05 Add SQL Delta t ->(050609)--} IF ( ( POS ( trim oneline ) 'SQL_QUERY' ) > 0 ) WRITE_FILE 2 ( 'LET run_qry_start ( current_time )' ) LET l_sqlqry_found TRUE END_IF IF ( l_next_write_sql_delta ) WRITE_FILE 2 ( 'LET run_qry_delta ( current_time - run_qry_start )' ) LET l_next_write_sql_delta FALSE END_IF IF ( ( ( POS ( trim oneline ) 'END' > 0 ) ) AND ( l_sqlqry_found ) ) LET l_next_write_sql_delta TRUE LET l_sqlqry_found FALSE END_IF { -- END TD: 09-JUN-05 <-(050609)--} if ( ( pos ( trim oneline ) 'LOCAL' ) > 0 ) if ( ( ( pos macroname 'Dms_' ) = 0 ) and ( ( pos macroname '__' ) = 0 ) ) let has_locals TRUE end_if let last_local 0 end_if if ( ( pos ( trim oneline ) 'PARAMETER' ) = 1 ) if ( ( ( pos macroname 'Dms_' ) = 0 ) and ( ( pos macroname '__' ) = 0 ) ) let has_locals TRUE end_if let last_local 0 end_if if ( ( ( trim oneline ) = 'LOCAL' ) or ( ( trim oneline ) = 'PARAMETER' ) ) let last_local -1 end_if if ( ( ( trim oneline )='END_DEFINE' ) or ( ( trim oneline ) = 'RETURN' ) or ( ( trim oneline ) = 'CANCEL' ) ) if ( ( has_locals ) and ( ( pos l_avoid (lwc macroname) ) < 1 ) ) if ( ( pos last_line 'LET Run_stat' ) < 1 ) if ( ( trim oneline ) = 'CANCEL' ) write_file 2 ('LET Run_stat "<-CANCEL"' ) write_file 2 ('LET Run_delta ( (current_time)-run_start )' ) else write_file 2 ('LET Run_stat "<-'+ macroname +'"') write_file 2 ('LET Run_delta ( (current_time)-run_start )' ) end_if end_if end_if end_if if ( ( last_local = 1 ) and ( has_locals ) and ( ( pos l_avoid (lwc macroname) ) < 1 ) ) if ( ( pos oneline 'LET Run_stat' ) < 1 ) write_file 2 ('let run_stat "->'+macroname+'"' ) write_file 2 ('LET run_start ( current_time ) ' ) end_if end_if let last_line oneline if ( ( pos macroname 'Dms_' ) = 0 ) write_file 2 oneline end_if read_file 1 oneline end_while close_file 1 close_file 2 input 'c:\temp\travis.mac' END_DEFINE { dtravis } DEFINE travis {**************************************************************************** * * MACRO : travis * PURPOSE : tags all loaded macros with '->[macroname]' and '<-[macroname]' for faster debugging * * PARAMETER : * * FILEDESCR : * * RESULTFILE : * * GLOBAL : * * AUTHOR : Tim Doerfler * CREATE_DATE : 20-OCT-2003 * * MODIFICATIONS: * * *****************************************************************************} local i local oneline local macroname local l_line local l_written local has_locals local last_line local last_last local last_local local l_avoid let l_avoid 'cm_get_elem_infos;cm_get_elem_elid;cm_get_equip_location;cm_divide_string;cm_push_cleanup;cm_get_elem_id;cm_sync_dde' let l_avoid 'cm_sync_dde;cm_push_cleanup' save_macro all del_old 'c:\temp\tra_dump.mac' open_infile 1 'c:\temp\tra_dump.mac' open_outfile 2 del_old 'c:\temp\travis.mac' let oneline '' let locals_area FALSE let l_written FALSE let has_locals FALSE let run_stat '' let last_line '' let last_local 0 read_file 1 oneline while ( oneline <> 'END-OF-FILE' ) let last_local ( last_local + 1 ) if ( ( ( pos ( trim oneline ) 'DEFINE' ) = 1 ) and ( ( trim oneline ) <> 'END_DEFINE' ) ) let macroname ( substr oneline 8 ( ( len oneline ) - 7 ) ) let has_locals FALSE let last_local 0 end_if if ( ( pos ( trim oneline ) 'LOCAL' ) > 0 ) if ( ( ( pos macroname 'Dms_' ) = 0 ) and ( ( pos macroname '__' ) = 0 ) ) let has_locals TRUE end_if let last_local 0 end_if if ( ( pos ( trim oneline ) 'PARAMETER' ) = 1 ) if ( ( ( pos macroname 'Dms_' ) = 0 ) and ( ( pos macroname '__' ) = 0 ) ) let has_locals TRUE end_if let last_local 0 end_if if ( ( ( trim oneline ) = 'LOCAL' ) or ( ( trim oneline ) = 'PARAMETER' ) ) let last_local -1 end_if if ( ( ( trim oneline )='END_DEFINE' ) or ( ( trim oneline ) = 'RETURN' ) or ( ( trim oneline ) = 'CANCEL' ) ) if ( ( has_locals ) and ( ( pos l_avoid (lwc macroname) ) < 1 ) ) if ( ( pos last_line 'LET Run_stat' ) < 1 ) if ( ( trim oneline ) = 'CANCEL' ) write_file 2 ('LET Run_stat "<-CANCEL"' ) else write_file 2 ('LET Run_stat "<-'+ macroname +'"') end_if end_if end_if end_if if ( ( last_local = 1 ) and ( has_locals ) and ( ( pos l_avoid (lwc macroname) ) < 1 ) ) if ( ( pos oneline 'LET Run_stat' ) < 1 ) write_file 2 ('let run_stat "->'+macroname+'"' ) end_if end_if let last_line oneline if ( ( pos macroname 'Dms_' ) = 0 ) write_file 2 oneline end_if read_file 1 oneline end_while close_file 1 close_file 2 input 'c:\temp\travis.mac' END_DEFINE { travis } DEFINE tagmac {**************************************************************************** * * MACRO : tagmac * PURPOSE : tags a single macro * * PARAMETER : * * FILEDESCR : * * RESULTFILE : * * GLOBAL : * * AUTHOR : Tim Doerfler * CREATE_DATE : 07-NOV-2003 * * MODIFICATIONS: * * *****************************************************************************} parameter macname local i local oneline local macroname local l_line local l_written local has_locals local last_line local last_last local last_local evaluate_string ("save_macro "+macname +" del_old 'c:\temp\td_dh.mac'" ) open_infile 1 no_delay 'c:\temp\td_dh.mac' open_outfile 2 del_old ('c:\temp\'+macname+'.tv') let oneline '' let locals_area FALSE let l_written FALSE let has_locals FALSE let run_stat '' let last_line '' let last_local 0 read_file 1 oneline while ( oneline <> 'END-OF-FILE' ) let last_local ( last_local + 1 ) if ( ( ( pos ( trim oneline ) 'DEFINE' ) = 1 ) and ( ( trim oneline ) <> 'END_DEFINE' ) ) let macroname ( substr oneline 8 ( ( len oneline ) - 7 ) ) let has_locals FALSE let last_local 0 end_if if ( ( pos ( trim oneline ) 'LOCAL' ) > 0 ) if ( ( pos macroname 'Dms_' ) = 0 ) let has_locals TRUE end_if let last_local 0 end_if if ( ( pos ( trim oneline ) 'PARAMETER' ) = 1 ) if ( ( pos macroname 'Dms_' ) = 0 ) let has_locals TRUE end_if let last_local 0 end_if if ( ( ( trim oneline ) = 'LOCAL' ) or ( ( trim oneline ) = 'PARAMETER' ) ) let last_local -1 end_if if ( ( ( trim oneline )='END_DEFINE' ) or ( ( trim oneline ) = 'RETURN' ) or ( ( trim oneline ) = 'CANCEL' ) ) if ( has_locals ) if ( ( pos last_line 'LET Run_stat' ) < 1 ) if ( ( trim oneline ) = 'CANCEL' ) write_file 2 ('LET Run_stat "<-CANCEL"' ) else write_file 2 ('LET Run_stat "<-'+ macroname +'"') end_if end_if end_if end_if if ( ( last_local = 1 ) and ( has_locals ) ) if ( ( pos oneline 'LET Run_stat' ) < 1 ) write_file 2 ('let run_stat "->'+macroname+'"' ) end_if end_if let last_line oneline if ( ( pos macroname 'Dms_' ) = 0 ) write_file 2 oneline end_if read_file 1 oneline end_while close_file 2 close_file 1 END_DEFINE { tagmac } DEFINE tag_em {**************************************************************************** * * MACRO : tag_em * PURPOSE : trace visualizer load. Loads a macrofile and tags all macros * * PARAMETER : * * FILEDESCR : was: tvld * * RESULTFILE : * * GLOBAL : * * AUTHOR : Tim Doerfler * CREATE_DATE : 17-FEB-2004 * * MODIFICATIONS: * * *****************************************************************************} parameter filename local i local mac_file input filename purge_file 'c:\temp\*.tv' confirm open_infile 1 no_delay filename read_file 1 oneline let i 0 create_ltab 'macros_ltab' while ( oneline <> 'END-OF-FILE' ) if ( pos (upc ( substr oneline 1 7 ) ) 'DEFINE ' ) IF ( NOT ( POS (upc oneline) 'END_DEFINE' ) ) { NUR taggen, wenn DEFINE und END_DEFINE NICHT in der gleichen Zeile stehen ! } let i ( i + 1 ) write_ltab 'macros_ltab' i 1 ( substr oneline 8 ( (len oneline )-7 ) ) END_IF end_if read_file 1 oneline end_while close_file 1 let i 0 while ( i < ( ltab_rows 'macros_ltab' ) ) let i ( i + 1 ) tagmac ( read_ltab 'macros_ltab' i 1 ) end_while display("please wait a short moment for the buffer to be flushed to disk and then type get_em into command line to input the tagged macros") END_DEFINE { tvld } define get_em let i 0 while ( i < ( ltab_rows 'macros_ltab' ) ) let i ( i + 1 ) let mac_file ('c:\temp\'+( read_ltab 'macros_ltab' i 1 )+'.tv' ) input mac_file end_while end_define