@@ -33,6 +33,7 @@ type Config struct {
3333 Workers int
3434 MonitorPID int
3535 MonitorProcess string
36+ MonitorSelf bool
3637 MonitorInterval time.Duration
3738 PayloadPoolSize int
3839}
@@ -188,40 +189,68 @@ func main() {
188189 }()
189190 }
190191
191- // Determine monitoring PID if monitoring is enabled.
192- var processStats * ProcessStats
192+ // Determine monitoring targets.
193+ var targetStats * ProcessStats
194+ var selfStats * ProcessStats
195+
193196 if config .MonitorProcess != "" {
194197 pid , err := findProcessByName (config .MonitorProcess )
195198 if err != nil {
196199 log .Fatalf ("Failed to find process '%s': %v" , config .MonitorProcess , err )
197200 }
198- processStats = & ProcessStats {
201+ targetStats = & ProcessStats {
199202 pid : pid ,
200203 processName : config .MonitorProcess ,
204+ monitorType : MonitorTypeTarget ,
201205 }
202206 log .Printf ("Found process '%s' with PID: %d" , config .MonitorProcess , pid )
203207 } else if config .MonitorPID > 0 {
204- processStats = & ProcessStats {
205- pid : config .MonitorPID ,
208+ targetStats = & ProcessStats {
209+ pid : config .MonitorPID ,
210+ monitorType : MonitorTypeTarget ,
206211 }
207212 log .Printf ("Monitoring process PID: %d" , config .MonitorPID )
208213 }
209214
215+ if config .MonitorSelf {
216+ selfStats = & ProcessStats {
217+ pid : os .Getpid (),
218+ processName : "loadgen" ,
219+ monitorType : MonitorTypeSelf ,
220+ }
221+ log .Printf ("Monitoring self PID: %d" , selfStats .pid )
222+ }
223+
210224 // Determine mode: monitoring-only vs concurrent vs normal.
211- monitoringEnabled := processStats != nil
225+ monitoringEnabled := targetStats != nil || selfStats != nil
212226 endpointProvided := flag .Lookup ("endpoint" ).Value .String () != flag .Lookup ("endpoint" ).DefValue
213227
214228 if monitoringEnabled && ! endpointProvided {
215229 // Mode 2: Standalone monitoring only.
216230 log .Printf ("Starting monitoring-only mode (interval: %s)" , config .MonitorInterval )
217- runMonitoringOnly (ctx , processStats , config .MonitorInterval )
231+
232+ if targetStats != nil {
233+ go monitorProcess (ctx , targetStats , config .MonitorInterval )
234+ }
235+ if selfStats != nil {
236+ go monitorProcess (ctx , selfStats , config .MonitorInterval )
237+ }
238+
239+ // Block until context is cancelled.
240+ <- ctx .Done ()
241+ log .Println ("Monitoring stopped" )
218242 return
219243 }
220244
221245 if monitoringEnabled {
222246 // Mode 1: Concurrent monitoring + load generation.
223247 log .Printf ("Starting concurrent monitoring (interval: %s)" , config .MonitorInterval )
224- go monitorProcess (ctx , processStats , config .MonitorInterval )
248+ if targetStats != nil {
249+ go monitorProcess (ctx , targetStats , config .MonitorInterval )
250+ }
251+ if selfStats != nil {
252+ go monitorProcess (ctx , selfStats , config .MonitorInterval )
253+ }
225254 }
226255
227256 // Normal load generation (with or without monitoring).
@@ -245,6 +274,7 @@ func parseFlags() *Config {
245274 workers := flag .Int ("workers" , 1 , "Number of concurrent workers" )
246275 monitorPID := flag .Int ("monitor-pid" , 0 , "PID of process to monitor (0 means disabled)" )
247276 monitorProcess := flag .String ("monitor-process" , "" , "Process name to monitor (e.g., 'edgedelta')" )
277+ monitorSelf := flag .Bool ("monitor-self" , false , "Monitor loadgen's own resource usage" )
248278 monitorInterval := flag .Duration ("monitor-interval" , 5 * time .Second , "Interval for process monitoring stats" )
249279 payloadPoolSize := flag .Int ("payload-pool-size" , 100 , "Number of unique payloads to generate in the pool" )
250280 flag .Parse ()
@@ -261,6 +291,7 @@ func parseFlags() *Config {
261291 Workers : * workers ,
262292 MonitorPID : * monitorPID ,
263293 MonitorProcess : * monitorProcess ,
294+ MonitorSelf : * monitorSelf ,
264295 MonitorInterval : * monitorInterval ,
265296 PayloadPoolSize : * payloadPoolSize ,
266297 }
0 commit comments