<s> """<STR_LIT>""" <EOL> import os <EOL> import re <EOL> import datetime <EOL> class ProcFileParseError ( RuntimeError ) : <EOL> """<STR_LIT>""" <EOL> class ProcessStat ( object ) : <EOL> """<STR_LIT>""" <EOL> __ticks_per_second = os . sysconf ( os . sysconf_names [ "<STR_LIT>" ] ) <EOL> __entry_re = re . compile ( "<STR_LIT>" ) <EOL> __stat_re_strings = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:0>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> __stat_res = [ re . compile ( s ) for s in __stat_re_strings ] <EOL> def __init__ ( self , pid ) : <EOL> """<STR_LIT>""" <EOL> with open ( "<STR_LIT>" % pid ) as file : <EOL> stat = file . read ( ) <EOL> strings = stat . split ( ) <EOL> self . __d = { <EOL> "<STR_LIT>" : strings [ <NUM_LIT:0> ] , <EOL> "<STR_LIT>" : strings [ <NUM_LIT:5> ] , <EOL> "<STR_LIT>" : strings [ <NUM_LIT> ] , <EOL> } <EOL> @ staticmethod <EOL> def all ( ) : <EOL> """<STR_LIT>""" <EOL> for name in os . listdir ( "<STR_LIT>" ) : <EOL> m = ProcessStat . __entry_re . match ( name ) <EOL> if m : <EOL> try : <EOL> yield ProcessStat ( int ( name ) ) <EOL> except IOError : <EOL> pass <EOL> @ staticmethod <EOL> def in_session ( sid ) : <EOL> """<STR_LIT>""" <EOL> for process in ProcessStat . all ( ) : <EOL> if process . sid == sid : <EOL> yield process <EOL> def __ticks_to_timedelta ( self , ticks ) : <EOL> """<STR_LIT>""" <EOL> return datetime . timedelta ( seconds = float ( ticks ) / self . __ticks_per_second ) <EOL> pid = property ( lambda self : int ( self . __d [ "<STR_LIT>" ] ) ) <EOL> name = property ( lambda self : self . __d [ "<STR_LIT:name>" ] ) <EOL> state = property ( lambda self : self . __d [ "<STR_LIT:state>" ] ) <EOL> ppid = property ( lambda self : int ( self . __d [ "<STR_LIT>" ] ) ) <EOL> pgid = property ( lambda self : int ( self . __d [ "<STR_LIT>" ] ) ) <EOL> sid = property ( lambda self : int ( self . __d [ "<STR_LIT>" ] ) ) <EOL> tty = property ( lambda self : int ( self . __d [ "<STR_LIT>" ] ) ) <EOL> tty_owner_group = property ( lambda self : int ( self . __d [ "<STR_LIT>" ] ) ) <EOL> flags = property ( lambda self : long ( self . __d [ "<STR_LIT>" ] ) ) <EOL> minor_faults = property ( lambda self : long ( self . __d [ "<STR_LIT>" ] ) ) <EOL> child_minor_faults = property ( lambda self : long ( self . __d [ "<STR_LIT>" ] ) ) <EOL> major_faults = property ( lambda self : long ( self . __d [ "<STR_LIT>" ] ) ) <EOL> child_major_faults = property ( lambda self : long ( self . __d [ "<STR_LIT>" ] ) ) <EOL> user_time = property ( lambda self : self . __ticks_to_timedelta ( self . __d [ "<STR_LIT>" ] ) ) <EOL> kernel_time = property ( lambda self : self . __ticks_to_timedelta ( self . __d [ "<STR_LIT>" ] ) ) <EOL> child_user_time = property ( lambda self : self . __ticks_to_timedelta ( self . __d [ "<STR_LIT>" ] ) ) <EOL> child_kernel_time = property ( lambda self : self . __ticks_to_timedelta ( self . __d [ "<STR_LIT>" ] ) ) <EOL> priority = property ( lambda self : int ( self . __d [ "<STR_LIT>" ] ) ) <EOL> nice = property ( lambda self : int ( self . __d [ "<STR_LIT>" ] ) ) <EOL> threads = property ( lambda self : int ( self . __d [ "<STR_LIT>" ] ) ) <EOL> start_time = property ( lambda self : self . __ticks_to_timedelta ( self . __d [ "<STR_LIT:start>" ] ) ) <EOL> virtual_size = property ( lambda self : long ( self . __d [ "<STR_LIT>" ] ) ) <EOL> resident_set_size = property ( lambda self : int ( self . __d [ "<STR_LIT>" ] ) ) <EOL> resident_set_limit = property ( lambda self : long ( self . __d [ "<STR_LIT>" ] ) ) <EOL> text_bottom = property ( lambda self : long ( self . __d [ "<STR_LIT>" ] ) ) <EOL> text_top = property ( lambda self : long ( self . __d [ "<STR_LIT>" ] ) ) <EOL> stack_start = property ( lambda self : long ( self . __d [ "<STR_LIT>" ] ) ) <EOL> stack_pointer = property ( lambda self : long ( self . __d [ "<STR_LIT>" ] ) ) <EOL> instruction_pointer = property ( lambda self : long ( self . __d [ "<STR_LIT>" ] ) ) <EOL> pending_signals = property ( lambda self : long ( self . __d [ "<STR_LIT>" ] ) ) <EOL> blocked_signals = property ( lambda self : long ( self . __d [ "<STR_LIT>" ] ) ) <EOL> ignored_signals = property ( lambda self : long ( self . __d [ "<STR_LIT>" ] ) ) <EOL> caught_signals = property ( lambda self : long ( self . __d [ "<STR_LIT>" ] ) ) <EOL> wait_channel = property ( lambda self : long ( self . __d [ "<STR_LIT>" ] ) ) <EOL> exit_signal = property ( lambda self : int ( self . __d [ "<STR_LIT>" ] ) ) <EOL> last_cpu = property ( lambda self : int ( self . __d [ "<STR_LIT>" ] ) ) <EOL> priority = property ( lambda self : long ( self . __d [ "<STR_LIT>" ] ) ) <EOL> policy = property ( lambda self : long ( self . __d [ "<STR_LIT>" ] ) ) <EOL> io_delay = property ( lambda self : long ( self . __d [ "<STR_LIT>" ] ) ) <EOL> guest_time = property ( lambda self : self . __ticks_to_timedelta ( self . __d [ "<STR_LIT>" ] ) ) <EOL> child_guest_time = property ( lambda self : self . __ticks_to_timedelta ( self . __d [ "<STR_LIT>" ] ) ) <EOL> def get_pid_utime ( pid ) : <EOL> return ProcessStat ( pid ) . user_time <EOL> def get_sid_utime ( sid ) : <EOL> return sum ( p . user_time for p in ProcessStat . in_session ( sid ) ) </s>
