debugstate.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package frankenphp
  2. // EXPERIMENTAL: ThreadDebugState prints the state of a single PHP thread - debugging purposes only
  3. type ThreadDebugState struct {
  4. Index int
  5. Name string
  6. State string
  7. IsWaiting bool
  8. IsBusy bool
  9. WaitingSinceMilliseconds int64
  10. }
  11. // EXPERIMENTAL: FrankenPHPDebugState prints the state of all PHP threads - debugging purposes only
  12. type FrankenPHPDebugState struct {
  13. ThreadDebugStates []ThreadDebugState
  14. ReservedThreadCount int
  15. }
  16. // EXPERIMENTAL: DebugState prints the state of all PHP threads - debugging purposes only
  17. func DebugState() FrankenPHPDebugState {
  18. fullState := FrankenPHPDebugState{
  19. ThreadDebugStates: make([]ThreadDebugState, 0, len(phpThreads)),
  20. ReservedThreadCount: 0,
  21. }
  22. for _, thread := range phpThreads {
  23. if thread.state.is(stateReserved) {
  24. fullState.ReservedThreadCount++
  25. continue
  26. }
  27. fullState.ThreadDebugStates = append(fullState.ThreadDebugStates, threadDebugState(thread))
  28. }
  29. return fullState
  30. }
  31. // threadDebugState creates a small jsonable status message for debugging purposes
  32. func threadDebugState(thread *phpThread) ThreadDebugState {
  33. return ThreadDebugState{
  34. Index: thread.threadIndex,
  35. Name: thread.handler.name(),
  36. State: thread.state.name(),
  37. IsWaiting: thread.state.isInWaitingState(),
  38. IsBusy: !thread.state.isInWaitingState(),
  39. WaitingSinceMilliseconds: thread.state.waitTime(),
  40. }
  41. }