@@ -52,6 +52,9 @@ class Metrics(object):
5252 ru_nsignals = 0
5353 ru_nvcs = 0
5454 ru_nivcsw = 0
55+ dead_threads = 0
56+ alive_threads = 0
57+ daemon_threads = 0
5558 gc = None
5659
5760 def __init__ (self , ** kwds ):
@@ -124,22 +127,25 @@ def collect_modules(self):
124127 r [k ] = d ["__version__" ]
125128 else :
126129 r [k ] = "builtin"
127- else :
128- r [k ] = "builtin"
129130
130131 return r
131132
132133 def collect_metrics (self ):
133134 u = resource .getrusage (resource .RUSAGE_SELF )
134135 if gc .isenabled ():
135136 c = list (gc .get_count ())
136- t = list (gc .get_threshold ())
137+ th = list (gc .get_threshold ())
137138 g = GC (collect0 = c [0 ] if not self .last_collect else c [0 ] - self .last_collect [0 ],
138139 collect1 = c [1 ] if not self .last_collect else c [1 ] - self .last_collect [1 ],
139140 collect2 = c [2 ] if not self .last_collect else c [2 ] - self .last_collect [2 ],
140- threshold0 = t [0 ],
141- threshold1 = t [1 ],
142- threshold2 = t [2 ])
141+ threshold0 = th [0 ],
142+ threshold1 = th [1 ],
143+ threshold2 = th [2 ])
144+
145+ thr = t .enumerate ()
146+ daemon_threads = len (map (lambda tr : tr .daemon and tr .is_alive (), thr ))
147+ alive_threads = len (map (lambda tr : not tr .daemon and tr .is_alive (), thr ))
148+ dead_threads = len (map (lambda tr : not tr .is_alive (), thr ))
143149
144150 m = Metrics (ru_utime = u [0 ] if not self .last_usage else u [0 ] - self .last_usage [0 ],
145151 ru_stime = u [1 ] if not self .last_usage else u [1 ] - self .last_usage [1 ],
@@ -157,6 +163,9 @@ def collect_metrics(self):
157163 ru_nsignals = u [13 ] if not self .last_usage else u [13 ] - self .last_usage [13 ],
158164 ru_nvcs = u [14 ] if not self .last_usage else u [14 ] - self .last_usage [14 ],
159165 ru_nivcsw = u [15 ] if not self .last_usage else u [15 ] - self .last_usage [15 ],
166+ alive_threads = alive_threads ,
167+ dead_threads = dead_threads ,
168+ daemon_threads = daemon_threads ,
160169 gc = g )
161170
162171 self .last_usage = u
0 commit comments