Debug window switch from time to ElapsedMilliseconds

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Debug window switch from time to ElapsedMilliseconds

Post by jassing »

It'd be useful to see a sub-second tracing of debug output as an option to just displaying time.
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: Debug window switch from time to ElapsedMilliseconds

Post by juergenkulow »

Does that really make sense?

Code: Select all

; File Preferences Debugger Individual Settings Debug Output Add Timestamp set
For i=1 To 10 
  Debug RSet(Str(ElapsedMilliseconds()%1000),3,"0")+" "+Str(i)
Next 
; [07:55:36] 523 1
; [07:55:36] 523 2
; [07:55:36] 523 3
; [07:55:36] 523 4
; [07:55:36] 523 5
; [07:55:36] 523 6
; [07:55:36] 523 7
; [07:55:36] 523 8
; [07:55:36] 523 9
; [07:55:36] 523 10

Code: Select all

; Debug GetRDTSC
Declare.q GetRDTSC()
For i=1 To 10 
  Debug FormatNumber(GetRDTSC(),0)+" "+Str(i)
Next 

; https://www.purebasic.fr/english/viewtopic.php?p=605757&hilit=RDTSC#p605757 Thanks to idle
CompilerIf Defined(PB_Compiler_Backend,#PB_Constant) 
  CompilerIf #PB_Compiler_Backend=#PB_Backend_C
    CompilerIf #PB_Compiler_Processor = #PB_Processor_x64 Or #PB_Compiler_Processor = #PB_Processor_x86 
      Procedure.q GetRDTSC()
        Protected t.q
        !unsigned hi, lo;
        !__asm__ __volatile__ ("lfence\n rdtsc\n lfence" : "=a"(lo), "=d"(hi));
        !v_t =((unsigned long long)lo)|(((unsigned long long)hi)<<32 );
        ProcedureReturn t
      EndProcedure
    CompilerElseIf #PB_Compiler_Processor = #PB_Processor_Arm64 Or #PB_Compiler_Processor = #PB_Processor_Arm32 
      Procedure.q GetRDTSC()
        Protected pmuseren.l,pmcntenset.l,pmccntr.l;
        !asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r"(v_pmuseren));
        If pmuseren & 1 
          !asm volatile("mrc p15, 0, %0, c9, c12, 1" : "=r"(v_pmcntenset));
          If pmcntenset & $80000000 
            !asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r"(v_pmccntr));
            t = pmccntr
            ProcedureReturn t << 6 
          EndIf 
        EndIf 
      EndProcedure 
    CompilerEndIf 
  CompilerElse
    Procedure.q GetRDTSC()
      Protected hi.q,lo.q,res.q 
      DisableDebugger
      !lfence 
      !rdtsc
      !lfence
      !mov [p.v_hi], edx
      !mov [p.v_lo], eax 
      res = hi
      res << 32
      res | lo
      ProcedureReturn res
      EnableDebugger 
    EndProcedure
  CompilerEndIf
CompilerElse
  Procedure.q GetRDTSC()
    Protected hi.q,lo.q,res.q 
    DisableDebugger
    !lfence 
    !rdtsc
    !lfence
    !mov [p.v_hi], edx
    !mov [p.v_lo], eax 
    res = hi
    res << 32
    res | lo
    EnableDebugger 
  EndProcedure
CompilerEndIf  

; [07:56:49] 13,689,326,123,849 1
; [07:56:49] 13,689,326,229,816 2
; [07:56:49] 13,689,326,257,960 3
; [07:56:49] 13,689,326,282,131 4
; [07:56:49] 13,689,326,306,652 5
; [07:56:49] 13,689,326,331,271 6
; [07:56:49] 13,689,326,355,610 7
; [07:56:49] 13,689,326,379,287 8
; [07:56:49] 13,689,326,403,831 9
; [07:56:49] 13,689,326,428,601 10
Post Reply