Announcement

Collapse
No announcement yet.

Comments on George Bleck's 'zTrace Helper'

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Comments on George Bleck's 'zTrace Helper'

    zTrace Helper

    Hi George

    The following works when %zTrace <0 or %zTrace>0 but not when %zTrace = 0.

    Tested with PBWin10 and PBWin9.

    With PBWin10 I am getting 'End-of-line expected', error 434, at the first zTrace.

    Code:
    #Compile Exe
    #Dim All
    #Register None
    
    '%zTrace = 1 ' Uncomment and we are OK.
    
    #If Not %Def( %zTrace )
      %zTrace = 0
    #EndIf
    
    #If %zTrace = 0
      Macro zTrace = #Utility
      Macro zDebug = #Utility
    #Else
      Declare Function zTraceX Lib "zTrace.DLL" Alias "zTrace" ( zMessage As AsciiZ ) As Long
      Declare Function zDebugX Lib "zTrace.DLL" Alias "zDebug" ( zMessage As AsciiZ ) As Long
      #If %zTrace > 0
        Macro zTrace = zTraceX
        Macro zDebug = zDebugX
      #Else
        Macro zTrace = zDebugX
        Macro zDebug = zDebugX
      #EndIf
    #EndIf
    
    Function PBMain
    
    zTrace ("Some text here")
    zTrace ("and more text")
    zTrace ("and so on")
    
    MsgBox "Wait"
    
    End Function
    Funny thing is if we replace
    Code:
    Macro zTrace = #Utility
    Macro zDebug = #Utility
    with
    Code:
    Macro zTrace = MsgBox
    Macro zDebug = MsgBox
    the three zTrace's in PBMain get treated as MsgBox's.

  • #2
    Hi David,
    I think I once tried zTrace years ago but never got into the habit of using it.

    But intrigued by your post, I followed the link, and then the link in George's helper message to Jose's site, and I downloaded the 1.52 version, then tested your code.

    The only error I got had to do with the parens around the text strings in PBMAIN. I deleted the parens, and got no more errors no matter what combo of Debug constant, or your substitutions...


    I recently hit an "End-of-line expected" error for the first time, and it had to do with inadvertently including the same file twice (that's a different story), and the line in error was a single-line macro definition. But once I removed the second Include, I didn't get the error any more. I figured the compiler was getting confused by the duplications, particularly with macros within compiler conditionals (#IF)...

    Anyway, here are the mods I made to your code in order to test:
    Code:
    'TEST zTraceHelper.BAS  by David Roberts
    'from: https://forum.powerbasic.com/forum/user-to-user-discussions/programming/783957-comments-on-george-bleck-s-ztrace-helper msg#1
    '===================================
    'jhm: minor mods to facilitate testing of many combinations of settings...
    '===================================
    
    #Compile Exe
    #Dim All
    #Register None
    
    'Uncomment these one at a time and debug:
    '%zTrace = -1
    %zTrace = 0
    '%zTrace = 1
    
    #If Not %Def( %zTrace )
      %zTrace = 0
    #EndIf
    
    #If %zTrace = 0
    
       #If 0 ' don't test David's substitutions:
          Macro zTrace = #Utility
          Macro zDebug = #Utility
    
       #Else ' test David's substitutions:
          'Macro zTrace = #Utility
          'Macro zDebug = #Utility
          'David is asking us to change the above to the below, and test:
          Macro zTrace = MsgBox
          Macro zDebug = MsgBox
    
       #EndIf
    
    #Else
      Declare Function zTraceX Lib "zTrace.DLL" Alias "zTrace" ( zMessage As AsciiZ ) As Long
      Declare Function zDebugX Lib "zTrace.DLL" Alias "zDebug" ( zMessage As AsciiZ ) As Long
      #If %zTrace > 0
        Macro zTrace = zTraceX
        Macro zDebug = zDebugX
      #Else
        Macro zTrace = zDebugX
        Macro zDebug = zDebugX
      #EndIf
    #EndIf
    
    Function PBMain
       #If 10    ' the original:
          zTrace ("Some text here")
          zTrace ("and more text" )
          zTrace ("and so on"     )
       #Else
          ' needed to remove the parens in order to avoid errors
          zTrace "Some text here"
          zTrace "and more text"
          zTrace "and so on"
       #EndIf
    
       MsgBox "Wait"
    End Function
    I'm compiling in PBWIN 10.04, running on Win7 Pro, with all OS updates current.

    One positive from this: I'm going to start using zTrace.

    -John

    Comment


    • #3
      Hi John

      Originally posted by John
      The only error I got had to do with the parens around the text strings in PBMAIN.
      So I removed them in the opening post and with '%zTrace = 0' I now just get the "Wait" MsgBox. I expected trouble with '%zTrace = 1' but did not get any. However, '%zTrace = -1' did not work - a txt file was not created.

      According to Patrice
      Code:
      Syntax to use:
      zTrace("StringInformation")
      zDebug("StringInformation")
      So zTrace will work sans parens but zDebug will not - nearly there. Oh dear, are we questioning zTrace.dll?

      I have been using the parens for the last 10 years, and I am on Win10.

      One positive from this: I'm going to start using zTrace.
      I have only done this once but needed to know when things were happening so used zTrace to accept remarks plus the value of the Performance Counter. What an eye opener that was and helped in the design of the code.

      Is George's Helper still working for him? If so what are we doing wrong?

      STOP PRESS.

      Flaming heck, I have just tried 'zTrace = -1' again and it worked.

      So, it looks like George doesn't use parens.

      You have cracked it, John.

      Added: I pulled out a few pieces of old code and, yes, we don't need parens.

      Comment


      • #4
        Hi John

        Just to whet your appetite here is a snippet where zTrace is being used in Sub Test which is called in a Callback Function.
        Code:
        #Compile Exe
        #Dim All
        #Include "Win32API.inc" ' Needed for MultipleTimersLite
        #Include "C:\PBWin\Timers\MultipleTimersLite.inc"         ' Change to your path
        
        %Button = 100
        %zTrace = 1    ' Standard zTrace and zDebug usage
        
        ' George Bleck's 'zTrace Helper'
        
        #IF NOT %DEF( %zTrace )
            %zTrace = 0
        #ENDIF
        
        #IF %zTrace = 0
            MACRO zTrace = #UTILITY
            MACRO zDebug = #UTILITY
        #ELSE
            DECLARE FUNCTION zTraceX LIB "zTrace.DLL" ALIAS "zTrace" ( zMessage AS ASCIIZ ) AS LONG
            DECLARE FUNCTION zDebugX LIB "zTrace.DLL" ALIAS "zDebug" ( zMessage AS ASCIIZ ) AS LONG
            #IF %zTrace > 0
                MACRO zTrace = zTraceX
                MACRO zDebug = zDebugX
            #ELSE
                MACRO zTrace = zDebugX
                MACRO zDebug = zDebugX
            #ENDIF
        #ENDIF
        
        Function PBMain
        Local hDlg As Long
        
          InitializeTimers
          Randomize
        
          Dialog New 0, "zTrace example", , , 150, 60, %WS_SYSMENU To hDlg
          Control Add Button, hDlg, %Button, "Click me a few times and then Close", 10,10,130,20 Call CBF_Button
          Dialog Show Modal hDlg
        
        End Function
        
        CallBack Function CBF_Button
          Test
        End Function
        
        Sub Test
        Local i As Long, x As Single
        
          StartTimer(0)
          For i = 1 To 10000000
            x = Rnd
          Next
          StopTimer(0)
          zTrace sTimeTaken(0,3,%True)
        
        End Sub
        I clicked on the button five times and got something like this. sTimetaken() is in verbose mode; third parameter is %True.

        Click image for larger version  Name:	zTrace.jpg Views:	0 Size:	31.5 KB ID:	783985

        Before closing, you can click on zTrace's client area and in the pop-up menu you will see 'Create zDebug.txt report'. Clicking on that will have the client area dumped to zDebug.txt.

        Comment


        • #5
          "Just to whet your appetite"... Done!

          I searched/found your "MultipleTimersLite.inc" file and ran your code. Very cool.

          Of particular help: "Before closing, you can click on zTrace's client area and in the pop-up menu you will see 'Create zDebug.txt report'. Clicking on that will have the client area dumped to zDebug.txt." I like being able to get an output file (like PROFILE), but it looks like zTrace/zDebug strings make the output customized to my needs.

          Question 1: Looks like the strings have to be literals. No way to use variables?

          Question 2: I know that the "InitializeTimers" is for your .INC file, but why the "Randomize"? Is that just to mix things up for "RND"??

          [ADDED] I see how easy it is to use (instructions in the first post of the zTrace thread on Jose's Forum), so I'll be expanding from using "#IF %DEBUG" and "MsgBox/print" statements to using zTrace/zDebug statements. Very useful!

          Thanks!
          -John

          Comment


          • #6
            Answered my own Question 1:

            Code:
            'AppetiteWhetter.bas    by David Roberts
            'from: https://forum.powerbasic.com/forum/user-to-user-discussions/programming/783957-comments-on-george-bleck-s-ztrace-helper msg#4
            '===========================================================
            'Combines zTrace with timer stuff...
            ' See related threads and my notes in related INC files:
            '- George Bleck's 'zTrace Helper'
            '- MultipleTimersLite.inc
            '===========================================================
            
            #Compiler PBWin
            #Compile Exe
            #Dim All
            
            '#Include "Win32API.inc" ' Needed for MultipleTimersLite
            #Include "Windows.inc"  ' for JR includes
            '#Include "C:\PBWin\Timers\MultipleTimersLite.inc"         ' Change to your path
            #Include "MultipleTimersLite.inc"
            
            %Button = 100
            %zTrace = 1    ' Standard zTrace and zDebug usage
            
            ' George Bleck's 'zTrace Helper'
            
            #If Not %Def( %zTrace )
               %zTrace = 0
            #EndIf
            
            #If %zTrace = 0
               Macro zTrace = #Utility
               Macro zDebug = #Utility
            #Else
               Declare Function zTraceX Lib "zTrace.DLL" Alias "zTrace" ( zMessage As AsciiZ ) As Long
               Declare Function zDebugX Lib "zTrace.DLL" Alias "zDebug" ( zMessage As AsciiZ ) As Long
               #If %zTrace > 0
                  Macro zTrace = zTraceX
                  Macro zDebug = zDebugX
               #Else
                  Macro zTrace = zDebugX
                  Macro zDebug = zDebugX
               #EndIf
            #EndIf
            
            Function PBMain
               Local hDlg As Long
               Local sText As String
            
               sText = "Start of run"
               'zTrace sText     'nope
               'zDebug sText     'nope
               zTrace FuncName$  'ok
               zTrace MyText(sText)
            
               InitializeTimers
               Randomize
            
               Dialog New 0, "zTrace example", , , 150, 60, %WS_SysMenu To hDlg
               Control Add Button, hDlg, %Button, "Click me a few times and then Close", 10,10,130,20 Call CBF_Button
               Dialog Show Modal hDlg
            
               sText = "End of run"
               zTrace MyText(sText)
               zDebug MyText(sText)
            
            End Function
            
            CallBack Function CBF_Button
              Test
            End Function
            
            
            Function MyText(sText As String) As String
               Function = sText
            End Function
            
            
            Sub Test
               Local i As Long, x As Single
            
               StartTimer(0)
               For i = 1 To 10000000
                  x = Rnd
               Next
               StopTimer(0)
               zTrace sTimeTaken(0,3,%True)
            
            End Sub

            Comment


            • #7
              Originally posted by John
              Question 2: I know that the "InitializeTimers" is for your .INC file, but why the "Randomize"? Is that just to mix things up for "RND"??
              Randomize is not a requirement in this context. I don't want a newbie seeing Rnd being used without Randomize whatever we are using Rnd for; even for presenting a workload to time. What if the same sequence is needed? In that case I would post Randomize [number]. So I think about newbies when posting code? Yes, don't we all?

              zTrace is only limited by our imagination. Patrice describes it as a "debugging utility" but it is much more than that and George's Helper is a great add on.

              Comment


              • #8
                Dave,
                Thanks for clarifying about Randomize.

                BTW, I found an old note, can't find the source, but written by Patrice in response to some workaround code by a fellow named Cook:
                'For numbers:
                ' zTrace(STR$(Value))
                'or
                ' zTrace("Value =" & STR$(Value))
                '
                'For STRINGs:
                ' zTrace((MyString$))
                'or
                ' zTrace(A$ & B$ & STR$(12))
                I've played with these a bit, and found that the ((MyString$)) actually needs both sets of parens to evaluate properly.
                All of those statements evaluate properly with or without a space between the keyword "zTrace" and the first paren.

                Also, because I don't always like to overwrite the output zDebug.txt file from every run, I crated this routine and added a call to it at the top of the MAIN function:

                Code:
                Sub zSavePreviouszDebugfile                  'to avoid overwriting a previous debug output file  
                   Local sFileDate As String
                   If IsFile("zDebug.txt") Then
                      sFileDate = GetFileDateTime("zDebug.txt", "W")
                      Replace ":" With "_" In sFileDate
                      Name "zDebug.txt" As "zDebug" & " - " & sFileDate & ".txt"
                   End If
                End Sub
                You can use your favorite routine for "GetFileDateTime" and format it any way you want...

                I now have that routine, my zMyText(), and the compiler directives all in one "zTrace.inc" file. I set the %zTrace constant just ahead of the #INCLUDE "zTrace.inc" statement.

                Works great! I'm on board!

                -John

                Comment


                • #9
                  John, yes it is an "old note" - who still use type-specifier characters? The latest FreeBASIC compilers don't even use Str$(Value) any more, for example, using Str(Value) instead.

                  I've played with these a bit, and found that the ((MyString$)) actually needs both sets of parens to evaluate properly.
                  I don't understand that - can you give an example?

                  Comment


                  • #10
                    Oh, I see!
                    Code:
                    Dim A$
                    A$ = "PowerBASIC"
                    zTrace ((A$))
                    %zTrace = 0 will fail now but I wouldn't dream of using 'Dim A$' in the first place.

                    We also need to be careful when using dynamic strings.
                    Code:
                    Local A As String
                    A = "PowerBASIC"
                    zTrace A
                    will not work with a 'Parameter mismatches definition' because zTrace's parameter is 'zMessage As AsciiZ'

                    This will work:
                    Code:
                    Local A As String
                    A = "PowerBASIC"
                    zTrace A + Chr$(0)


                    zTrace "PowerBASIC" works because PowerBASIC gets cast as AsciiZ.

                    Ha, ha.

                    Added:

                    So why does 'zTrace sTimeTaken()' work. Erm, erm. Well, because macro functions get cast as AsciiZ. [Starts whistling and exits stage left].

                    Comment


                    • #11
                      Yup, that's it!

                      Thanks for helping me get back on board with zTrace!

                      Now I've got to switch to my other thread and get answers about MyLittleGrid...
                      Ciao,
                      -John

                      Comment


                      • #12
                        Fooey! Hit a new wrinkle...

                        All the code and testing I did above was with zTrace.DLL version 1.52, dated 2009-05-07 08:18:14; I do not have any source files for this version.

                        Then I realized there's a later version, 2.01, dated 2013-12-05 16:41:40 (I have source for this version, but they're not PB.)

                        So I renamed the old DLL to *.D_L, and copied the new DLL into the folder.

                        The program compiles with no errors, but when I run it, I get this message:
                        ---------------------------
                        AppetiteWhetter.EXE - Entry Point Not Found
                        ---------------------------
                        The procedure entry point zDebug could not be located in the dynamic link library ZTRACE.DLL.
                        ---------------------------
                        OK
                        ---------------------------

                        I gather there's something different in the newer DLL; I'm guessing that the DECLAREs need to be edited, but have no idea how to find info that would indicate what changes to make...

                        The DECLAREs are shown in Post 1, from the George Bleck helper code.


                        Any suggestions or guidance?

                        Thanks,
                        -John

                        Comment


                        • #13
                          2009-05-07 08:18:14 is the one that I have been using for years so had a look at Patrice's post a few days ago and downloaded the latest version from his post #1. It is dated 2011-08-07 17:54:22. The version number remained at 1.52. Both versions have zDebug and zTrace as entry points and the source is in PB.

                          A version was not published in 2013 and it never got beyond 1.52.

                          2.01 is the 64-bit version at CodeProject written in VS2010.

                          Oops-a-daisy.

                          I could use the 64-bit version in FreeBASIC but it is a single compiler, so we can write a GUI application and compile it as Console application. The GUI application can then print to the console as well as carrying out its GUI role. Many of my FB random number generators run on Windows, Linux and MAC. I can have FB code emitted as asm and passed to an assembler or emitted as C and passed to a C optimizing compiler. FB is a different world to PB.

                          Comment


                          • #14
                            In the 2.01 zipfile, I found both 32- and 64-bit versions:
                            Code:
                             
                            zTrace32.dll     2013-12-05  16:42:54          79,872 bytes
                            zTrace64.dll     2013-12-05  16:41:40          98,304 bytes
                            Neither version worked for me, so I'll happily go back to the 2011-08-07 version 1.52 (newer)

                            Thanks,
                            -John

                            Comment


                            • #15
                              John, I downloaded the zip file from CodeProject but there wasn't any dlls, just the C source code. Where did you get the 2.01 zip file from?

                              Comment

                              Working...
                              X