/** * Constructor which allows assigning the /proc/ directories. This will be * used only in unit tests. * @param procfsMemFile fake file for /proc/meminfo * @param procfsCpuFile fake file for /proc/cpuinfo * @param procfsStatFile fake file for /proc/stat * @param procfsNetFile fake file for /proc/net/dev * @param procfsDisksFile fake file for /proc/diskstats * @param jiffyLengthInMillis fake jiffy length value */ @VisibleForTesting public SysInfoLinux(String procfsMemFile, String procfsCpuFile, String procfsStatFile, String procfsNetFile, String procfsDisksFile, long jiffyLengthInMillis) { this.procfsMemFile = procfsMemFile; this.procfsCpuFile = procfsCpuFile; this.procfsStatFile = procfsStatFile; this.procfsNetFile = procfsNetFile; this.procfsDisksFile = procfsDisksFile; this.jiffyLengthInMillis = jiffyLengthInMillis; this.cpuTimeTracker = new CpuTimeTracker(jiffyLengthInMillis); this.perDiskSectorSize = new HashMap<String, Integer>(); }
/** * Create a monitor for a Windows process tree. * @param pid Identifier of the job object. * @param pClock Clock to keep track of time for CPU utilization. */ public WindowsBasedProcessTree(final String pid, final Clock pClock) { super(pid); this.taskProcessId = pid; this.clock = pClock; // Instead of jiffies, Windows uses milliseconds directly; 1ms = 1 jiffy this.cpuTimeTracker = new CpuTimeTracker(1L); }
/** * Create resource calculator for testing. * @param pid A pid from the cgroup or null for all containers * @param procfsDir Path to /proc or a mock /proc directory * @param cGroupsHandler Initialized cgroups handler object * @param clock A clock object * @param jiffyLengthMs0 Jiffy length in milliseconds */ @VisibleForTesting CGroupsResourceCalculator(String pid, String procfsDir, CGroupsHandler cGroupsHandler, Clock clock, long jiffyLengthMs0) { super(pid); this.procfsDir = procfsDir; this.cGroupsHandler = cGroupsHandler; this.pid = pid != null && pid.equals("0") ? "1" : pid; this.jiffyLengthMs = jiffyLengthMs0; this.cpuTimeTracker = new CpuTimeTracker(this.jiffyLengthMs); this.clock = clock; this.processTotalJiffies = BigInteger.ZERO; this.processPhysicalMemory = UNAVAILABLE; this.processVirtualMemory = UNAVAILABLE; }
/** * Constructor which allows assigning the /proc/ directories. This will be * used only in unit tests. * @param procfsMemFile fake file for /proc/meminfo * @param procfsCpuFile fake file for /proc/cpuinfo * @param procfsStatFile fake file for /proc/stat * @param procfsNetFile fake file for /proc/net/dev * @param procfsDisksFile fake file for /proc/diskstats * @param jiffyLengthInMillis fake jiffy length value */ @VisibleForTesting public SysInfoLinux(String procfsMemFile, String procfsCpuFile, String procfsStatFile, String procfsNetFile, String procfsDisksFile, long jiffyLengthInMillis) { this.procfsMemFile = procfsMemFile; this.procfsCpuFile = procfsCpuFile; this.procfsStatFile = procfsStatFile; this.procfsNetFile = procfsNetFile; this.procfsDisksFile = procfsDisksFile; this.jiffyLengthInMillis = jiffyLengthInMillis; this.cpuTimeTracker = new CpuTimeTracker(jiffyLengthInMillis); this.perDiskSectorSize = new HashMap<String, Integer>(); }
/** * Build a new process tree rooted at the pid. * * This method is provided mainly for testing purposes, where * the root of the proc file system can be adjusted. * * @param pid root of the process tree * @param procfsDir the root of a proc file system - only used for testing. * @param clock clock for controlling time for testing */ public ProcfsBasedProcessTree(String pid, String procfsDir, Clock clock) { super(pid); this.clock = clock; this.pid = getValidPID(pid); this.procfsDir = procfsDir; this.cpuTimeTracker = new CpuTimeTracker(JIFFY_LENGTH_IN_MILLIS); }