<commit_before>#!/usr/bin/env python
#
# $Id$
#

import os
import signal
import errno
import pwd
import grp

# import psutil exceptions we can override with our own
from error import *

def _get_uptime():
    """Return system boot time (epoch in seconds)"""
    f = open('/proc/stat', 'r')
    for line in f:
        if line.startswith('btime'):
            f.close()
            return float(line.strip().split()[1])

def _get_num_cpus():
    """Return the number of CPUs on the system"""
    num = 0
    f = open('/proc/cpuinfo', 'r')
    for line in f:
        if line.startswith('processor'):
            num += 1
    f.close()
    return num


# Number of clock ticks per second
_CLOCK_TICKS = os.sysconf(os.sysconf_names["SC_CLK_TCK"])
_UPTIME = _get_uptime()
NUM_CPUS = _get_num_cpus()
# XXX - real implementation needed
TOTAL_PHYMEM = 0
TOTAL_VIRTMEM = 0


def prevent_zombie(method):
    """Call method(self, pid) into a try/except clause so that if an
    IOError "No such file" exception is raised we assume the process
    has died and raise psutil.NoSuchProcess instead.
    """
    def wrapper(self, pid, *args, **kwargs):
        try:
            return method(self, pid, *args, **kwargs)
        except IOError, err:
            if err.errno == errno.ENOENT:  # no such file or directory
                if not self.pid_exists(pid):
                    raise NoSuchProcess(pid)
            raise
    return wrapper


def wrap_privileges(callable):
    """Call callable into a try/except clause so that if an
    OSError EPERM exception is raised we translate it into
    psutil.AccessDenied.
    """<commit_msg>Implemented TOTAL_PHYMEM and TOTAL_VIRTMEM on Linux<commit_after>#!/usr/bin/env python
#
# $Id$
#

import os
import signal
import errno
import pwd
import grp

# import psutil exceptions we can override with our own
from error import *

def _get_uptime():
    """Return system boot time (epoch in seconds)"""
    f = open('/proc/stat', 'r')
    for line in f:
        if line.startswith('btime'):
            f.close()
            return float(line.strip().split()[1])

def _get_num_cpus():
    """Return the number of CPUs on the system"""
    num = 0
    f = open('/proc/cpuinfo', 'r')
    for line in f:
        if line.startswith('processor'):
            num += 1
    f.close()
    return num

def _get_total_phymem():
    """Return total physical system memory"""
    f = open('/proc/meminfo', 'r')
    for line in f:
        if line.startswith('MemTotal:'):
            f.close()
            return int(line.split()[1]) * 1024

def _get_total_virtmem():
    """Return total physical system memory"""
    f = open('/proc/meminfo', 'r')
    for line in f:
        if line.startswith('VmallocTotal:'):
            f.close()
            return int(line.split()[1]) * 1024


# Number of clock ticks per second
_CLOCK_TICKS = os.sysconf(os.sysconf_names["SC_CLK_TCK"])
_UPTIME = _get_uptime()
NUM_CPUS = _get_num_cpus()
TOTAL_PHYMEM = _get_total_phymem()
TOTAL_VIRTMEM = _get_total_virtmem()


def prevent_zombie(method):
    """Call method(self, pid) into a try/except clause so that if an
    IOError "No such file" exception is raised we assume the process
    has died and raise psutil.NoSuchProcess instead.
    """
    def wrapper(self, pid, *args, **kwargs):
        try:
            return method(self, pid, *args, **kwargs)
        except IOError, err:
            if err.errno == errno.ENOENT:  # no such file or directory
                if not self.pid_exists(pid):
                    raise NoSuchProcess(pid)
            raise
    return wrapper


def wrap_privileges(callable):
    """Call callable into a try/except clause so that if an
    OSError EPERM exception is raised we translate it into
    psutil.AccessDenied.
    """
{'fraction_non_alphanumeric': 0.11031556616282154, 'fraction_numerical': 0.00477326968973747, 'mean_word_length': 2.6444444444444444, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '306399', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1182, 'n_words': 389}