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

2 Replies to “Weird little tidbit”

  1. Unfortunately my goal was to control the profiler via code but it absolutely *requires* the internal item be included by selecting the Profile Code menu item. When it’s not selected the profiler stuff isn’t included, and I wasn’t able to turn it on 🙁

    1. Yeah this item isnt included unless Profile Project is on

      But you CAN build with profiling on then turn it on & off in code after that

      An annoyance to have to do it this way but it is possible

Comments are closed.