Weird little tidbit

Got asked an interesting question
Can you know, in code, if profiling is or was enabled when the app was built ?

At first I couldn’t think of a way so I said “off the top of my head no”

But a bit more poking about and I came up with

Public Function isprofiling() As boolean
  For i As Integer = 0 To runtime.ObjectCount - 1
    
    Dim s As String = runtime.ObjectClass(i)
    
    If s = "_Profiler.Profile" Then 
      Return True
    End If
    
  Next
  
  return false
  
End Function

And now you can actually tell if profiling was on or not when the app was built and so is available to be enabled or not with the start profiling / stop profiling commands

Leave a Reply

Your email address will not be published. Required fields are marked *