| 
									
										
										
										
											2012-03-24 10:06:23 +01:00
										 |  |  | """Memory watchdog: periodically read the memory usage of the main test process
 | 
					
						
							|  |  |  | and print it out, until terminated."""
 | 
					
						
							|  |  |  | # stdin should refer to the process' /proc/<PID>/statm: we don't pass the | 
					
						
							|  |  |  | # process' PID to avoid a race condition in case of - unlikely - PID recycling. | 
					
						
							|  |  |  | # If the process crashes, reading from the /proc entry will fail with ESRCH. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | import time | 
					
						
							| 
									
										
										
										
											2023-03-02 20:10:08 +09:00
										 |  |  | from test.support import get_pagesize | 
					
						
							| 
									
										
										
										
											2012-03-24 10:06:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | while True: | 
					
						
							| 
									
										
										
										
											2023-03-02 20:10:08 +09:00
										 |  |  |     page_size = get_pagesize() | 
					
						
							| 
									
										
										
										
											2012-03-24 10:06:23 +01:00
										 |  |  |     sys.stdin.seek(0) | 
					
						
							|  |  |  |     statm = sys.stdin.read() | 
					
						
							|  |  |  |     data = int(statm.split()[5]) | 
					
						
							|  |  |  |     sys.stdout.write(" ... process data size: {data:.1f}G\n" | 
					
						
							|  |  |  |                      .format(data=data * page_size / (1024 ** 3))) | 
					
						
							|  |  |  |     sys.stdout.flush() | 
					
						
							|  |  |  |     time.sleep(1) |