Example #1
0
/*
 * Parser comma separated list of strings to Glist
 *
 * @param list comma separated list of strings
 * @returns GList or null if the list is empty
 */
GList *parse_list(const char* list)
{
    if (list == NULL)
        return NULL;

    char *tmp_list = xstrdup(list);

    GList *l = parse_delimited_list(tmp_list, LIST_DELIMITER);

    free(tmp_list);

    return l;
}
Example #2
0
/*
 * Finds the cpumask related to a pmu. If no cpumask file is present,
 * it assumes the default mask, i.e., the set of all cpus.
 */
void setup_cpu_config(struct pmu *pmu_ptr, int *ncpus, int **cpuarr)
{
    FILE *cpulist;
    char cpumask_path[PATH_MAX], *line;
    int *on_cpus = NULL;
    size_t len = 0;

    memset(cpumask_path, '\0', PATH_MAX);
    snprintf(cpumask_path, PATH_MAX, "%s%s/%s", dev_dir, pmu_ptr->name,
             PMU_CPUMASK);
    cpulist = fopen(cpumask_path, "r");
    /*
     * If this file is not available, then the cpumask is the set of all
     * available cpus.
     */
    if (!cpulist)
        return;

    if (getline(&line, &len, cpulist) > 0) {
	*ncpus = parse_delimited_list(line, NULL);
        if (*ncpus > 0) {
            on_cpus = calloc(*ncpus, sizeof (*on_cpus));
            if (!on_cpus) {
                fclose(cpulist);
                *cpuarr = NULL;
                return;
            }
        } else {
            *cpuarr = NULL;
            return;
        }

        parse_delimited_list(line, on_cpus);
        *cpuarr = on_cpus;
    }

    fclose(cpulist);
}