Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/landscape/lib/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/landscape/lib/process.pyc

ó
ÍÿŠTc@s‡ddlZddlZddlmZmZddlmZddlmZddlm	Z	m
Z
defd„ƒYZd„Z
dS(	iÿÿÿÿN(t	timedeltatdatetime(tto_timestamp(tdetect_jiffies(t	BootTimest
get_uptimetProcessInformationcBs5eZdZddddd„Zd„Zd„ZRS(sI
    @param proc_dir: The directory to use for process information.
    @param jiffies: The value to use for jiffies per second.
    @param boot_time: An alternate value to use for the last boot time.  If
        None, the system last boot time will be used.
    @param uptime: The uptime value to use (for unit tests only).
    s/proccCsm|dkrtƒjƒ}n|dk	r<tj|ƒ}n||_||_|pZtƒ|_||_	dS(N(
tNoneRtget_last_boot_timeRtutcfromtimestampt
_boot_timet	_proc_dirRt_jiffies_per_sect_uptime(tselftproc_dirtjiffiest	boot_timetuptime((s9/usr/lib/python2.7/dist-packages/landscape/lib/process.pyt__init__s		ccsex^tj|jƒD]J}yt|ƒ}Wntk
r?qnX|j|ƒ}|r|VqqWdS(s8Get process information for all processes on the system.N(tostlistdirRtintt
ValueErrortget_process_info(Rtfilenamet
process_idtprocess_info((s9/usr/lib/python2.7/dist-packages/landscape/lib/process.pytget_all_process_info!s
cCsed}tjj|jt|ƒƒ}i|d6}yÍttjj|dƒdƒ}z/|jƒ}tjj|jdƒdƒ}Wd|j	ƒXttjj|dƒdƒ}zLxE|D]=}|jd	d
ƒ}|ddkr|j
ƒpø|d
j
ƒ|d<q·|dd
krN|d
j
ƒ}	|	dkr=|	jƒ}	n|	d|d<q·|ddkr…|d
jƒ}
t|
dƒ|d<q·|ddkr¼|d
jƒ}
t|
dƒ|d<q·|ddkr·|d
jƒ}
t|
dƒ|d<Pq·q·WWd|j	ƒXttjj|dƒdƒ}zÊ|j
ƒjƒ}t|dƒ}t|dƒ}t|dƒ}
|jpytƒ}t||
|||jƒ}||d<td||jƒ}|jdkr×tjdƒdSt|j|ƒ|d<Wd|j	ƒXWntk
rdSXd|kr[d|kr[d|kr[d|kr[d|kr[d|ksat‚|S(s
        Parse the /proc/<pid>/cmdline and /proc/<pid>/status files for
        information about the running process with process_id.

        The /proc filesystem doesn't behave like ext2, open files can disappear
        during the read process.
        ttpidtcmdlinetrtiNtstatust:itNametnametStatesT (tracing stop)tstatetUidtuidtGidtgidtVmSizesvm-sizetstatii
ispercent-cpus,Skipping process (PID %s) without boot time.s
start-time(RtpathtjoinRtstrtopentreadlinetbasenametsplittclosetstriptlowerRtreadR
Rtcalculate_pcpuRRR
RtloggingtwarningRtIOErrortAssertionError(RRt
cmd_line_nametprocess_dirRtfiletcmd_linetlinetpartsR'tvalue_partst
start_timetutimetstimeRtpcputdelta((s9/usr/lib/python2.7/dist-packages/landscape/lib/process.pyR,sp
#



N(t__name__t
__module__t__doc__RRRR(((s9/usr/lib/python2.7/dist-packages/landscape/lib/process.pyR
s
	
	cCsXd}||}|||}|r9|d||}nttt|dƒdƒdƒS(so
    Implement ps' algorithm to calculate the percentage cpu utilisation for a
    process.::

    unsigned long long total_time;   /* jiffies used by this process */
    unsigned pcpu = 0;               /* scaled %cpu, 99 means 99% */
    unsigned long long seconds;      /* seconds of process life */
    total_time = pp->utime + pp->stime;
    if(include_dead_children) total_time += (pp->cutime + pp->cstime);
    seconds = seconds_since_boot - pp->start_time / hertz;
    if(seconds) pcpu = (total_time * 100ULL / hertz) / seconds;
    if (pcpu > 99U) pcpu = 99U;
    return snprintf(outbuf, COLWID, "%2u", pcpu);
    iidgÀX@i(troundtmaxtmin(RFRGRREthertzRHt
total_timetseconds((s9/usr/lib/python2.7/dist-packages/landscape/lib/process.pyR9‡s
(R:RRRtlandscape.lib.timestampRtlandscape.lib.jiffiesRt landscape.monitor.computeruptimeRRtobjectRR9(((s9/usr/lib/python2.7/dist-packages/landscape/lib/process.pyt<module>sz