@@ -12,6 +12,11 @@ type ThreadDebugState struct {
1212 IsWaiting bool
1313 IsBusy bool
1414 WaitingSinceMilliseconds int64
15+ CurrentURI string
16+ CurrentMethod string
17+ RequestStartedAt int64
18+ RequestCount int64
19+ MemoryUsage int64
1520}
1621
1722// EXPERIMENTAL: FrankenPHPDebugState prints the state of all PHP threads - debugging purposes only
@@ -39,12 +44,38 @@ func DebugState() FrankenPHPDebugState {
3944
4045// threadDebugState creates a small jsonable status message for debugging purposes
4146func threadDebugState (thread * phpThread ) ThreadDebugState {
42- return ThreadDebugState {
47+ isBusy := ! thread .state .IsInWaitingState ()
48+
49+ s := ThreadDebugState {
4350 Index : thread .threadIndex ,
4451 Name : thread .name (),
4552 State : thread .state .Name (),
4653 IsWaiting : thread .state .IsInWaitingState (),
47- IsBusy : ! thread . state . IsInWaitingState () ,
54+ IsBusy : isBusy ,
4855 WaitingSinceMilliseconds : thread .state .WaitTime (),
4956 }
57+
58+ s .RequestCount = thread .requestCount .Load ()
59+ s .MemoryUsage = thread .lastMemoryUsage .Load ()
60+
61+ if isBusy {
62+ thread .handlerMu .RLock ()
63+ fc := thread .handler .frankenPHPContext ()
64+ thread .handlerMu .RUnlock ()
65+
66+ if fc != nil && fc .request != nil && fc .responseWriter != nil {
67+ if fc .originalRequest != nil {
68+ s .CurrentURI = fc .originalRequest .URL .RequestURI ()
69+ s .CurrentMethod = fc .originalRequest .Method
70+ } else {
71+ s .CurrentURI = fc .requestURI
72+ s .CurrentMethod = fc .request .Method
73+ }
74+ if ! fc .startedAt .IsZero () {
75+ s .RequestStartedAt = fc .startedAt .UnixMilli ()
76+ }
77+ }
78+ }
79+
80+ return s
5081}
0 commit comments