/** * mono_process_get_data: * @pid: pid of the process * @data: description of data to return * * Return a data item of a process like user time, memory use etc, * according to the @data argumet. */ gint64 mono_process_get_data_with_error (gpointer pid, MonoProcessData data, MonoProcessError *error) { gint64 val; int rpid = GPOINTER_TO_INT (pid); if (error) *error = MONO_PROCESS_ERROR_OTHER; switch (data) { case MONO_PROCESS_NUM_THREADS: return get_pid_status_item (rpid, "Threads", error, 1); case MONO_PROCESS_USER_TIME: return get_process_stat_time (rpid, 10, FALSE, error); case MONO_PROCESS_SYSTEM_TIME: return get_process_stat_time (rpid, 11, FALSE, error); case MONO_PROCESS_TOTAL_TIME: return get_process_stat_time (rpid, 10, TRUE, error); case MONO_PROCESS_WORKING_SET: return get_pid_status_item (rpid, "VmRSS", error, 1024); case MONO_PROCESS_WORKING_SET_PEAK: val = get_pid_status_item (rpid, "VmHWM", error, 1024); if (val == 0) val = get_pid_status_item (rpid, "VmRSS", error, 1024); return val; case MONO_PROCESS_PRIVATE_BYTES: return get_pid_status_item (rpid, "VmData", error, 1024); case MONO_PROCESS_VIRTUAL_BYTES: return get_pid_status_item (rpid, "VmSize", error, 1024); case MONO_PROCESS_VIRTUAL_BYTES_PEAK: val = get_pid_status_item (rpid, "VmPeak", error, 1024); if (val == 0) val = get_pid_status_item (rpid, "VmSize", error, 1024); return val; case MONO_PROCESS_FAULTS: return get_process_stat_item (rpid, 6, TRUE, error); case MONO_PROCESS_ELAPSED: return get_process_stat_item (rpid, 18, FALSE, error) / get_user_hz (); case MONO_PROCESS_PPID: return get_process_stat_time (rpid, 0, FALSE, error); case MONO_PROCESS_PAGED_BYTES: return get_pid_status_item (rpid, "VmSwap", error, 1024); /* Nothing yet */ case MONO_PROCESS_END: return 0; } return 0; }
static gint64 get_process_stat_time (int pid, int pos, int sum, MonoProcessError *error) { gint64 val = get_process_stat_item (pid, pos, sum, error); #if defined(__APPLE__) return val; #else /* return 100ns ticks */ return (val * 10000000) / get_user_hz (); #endif }