Esempio n. 1
0
    // Returns resident memory usage.
    boost::uint64_t read_psm_resident(bool)
    {
        proc_statm ps;

        if (!read_proc_statm(ps, getpid()))
        {
            HPX_THROW_EXCEPTION(
                hpx::invalid_data,
                "hpx::performance_counters::memory::read_psm_resident",
                boost::str( boost::format("failed to parse '/proc/%1%/statm'")
                          % getpid()));
            return boost::uint64_t(-1);
        }

        // ps.resident is in pages, but we need to return the number of bytes.
        return ps.resident * EXEC_PAGESIZE;
    }
Esempio n. 2
0
/*
 * Read the proc statistics information of given group name.
 *
 * IN:
 * @group_name :          The given group name.
 * @stats_lists:          The lists of proc statistics information.
 *
 * RETURN
 * 0                     Success.
 * -1                    Failed.
 */
int read_cg_proc_stats(const char* group_name, cg_proc_stats_lists* stats_lists) {

	FILE *fp = NULL;
	int i = 0, j = 0, num = 0;
	char* pre = NULL;
	pid_t* procs;
	char proc_name[FN_LEN] = { 0 };
	char line[MAX_LINE_LEN] = { 0 };
	cg_proc_stats* cg_stats = NULL;

	if (!group_name || !stats_lists) {
#ifdef DEBUG
		fprintf(stderr,
				"rd_stats: the group name or io stats lists is null.\n");
#endif
		return -1;
	}
	/** Clear the history information.*/
	clear_proc_stats(stats_lists);
	/** Get all of the process id in the group. But the variables procs should
	 *  be free at the end of this procedure.*/
	if (cgroup_get_procs(group_name, CG_CPUSET, &procs, &j)) {
#ifdef DEBUG
		fprintf(stderr,
				"rd_stats: read the value of procs in cpuset %s failed\n",
				group_name);
#endif
		return -1;
	}
	/** Read the io statistics information of each process id(/proc/<PID>/io).
	 *  Initialized the io statistics information and store the value of the
	 *  parameter. Finally add the io statistics information into the lists.*/
	for (i = 0; i < j; i++) {
		/** Initialized the io statistics information.*/
		if (init_proc_stats(&cg_stats, procs[i])) {
			fprintf(stderr, "rd_stats: initialize the io stats failed\n");
			goto err;
		}
		if (read_proc_io(cg_stats->io_stats, procs[i])
				|| read_proc_stat(cg_stats->proc_stat, procs[i])
				|| read_proc_statm(cg_stats->proc_statm, procs[i])) {
#ifdef DEBUG
			fprintf(stderr, "rd_stats: read the proc io stats, proc"
					" stat and proc statm into io stats list failed\n");
#endif
			goto err;
		}
		/** Add the io statistics information into the lists.*/
		if (add_proc_stats(stats_lists, cg_stats)) {
#ifdef DEBUG
			fprintf(stderr,
					"rd_stats: add the io stats into io stats list failed\n");
#endif
			goto err;
		}
	}
	if (procs)
		free(procs);
	return 0;

	err: if (cg_stats)
		uninit_proc_stats(cg_stats);
	clear_proc_stats(stats_lists);
	if (procs)
		free(procs);
	if (fp)
		fclose(fp);
	return -1;
}