예제 #1
0
파일: cgroup.cpp 프로젝트: noxiouz/porto
TError TMemorySubsystem::SetupOOMEvent(TCgroup &cg, TFile &event) {
    TError error;
    TFile knob;

    error = knob.OpenRead(cg.Knob(OOM_CONTROL));
    if (error)
        return error;

    event.Close();
    event.SetFd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
    if (event.Fd < 0)
        return TError(EError::Unknown, errno, "Cannot create eventfd");

    error = cg.Set(EVENT_CONTROL, std::to_string(event.Fd) + " " + std::to_string(knob.Fd));
    if (error)
        event.Close();
    return error;
}
예제 #2
0
파일: cgroup.cpp 프로젝트: noxiouz/porto
TError TBlkioSubsystem::Statistics(TCgroup &cg,
                                   const std::string &file,
                                   std::vector<BlkioStat> &stat) const {
    std::vector<std::string> lines;
    TError error = cg.Knob(file).ReadLines(lines);
    if (error)
        return error;

    BlkioStat s;
    for (size_t i = 0; i < lines.size(); i += 5) {
        std::vector<std::string> tokens;
        error = SplitString(lines[i], ' ', tokens);
        if (error)
            return error;

        if (tokens.size() == 3) {
            error = GetDevice(tokens[0], s.Device);
            if (error)
                return error;
        } else {
            continue; /* Total */
        }

        error = GetStatLine(lines, i + 0, "Read", s.Read);
        if (error)
            return error;
        error = GetStatLine(lines, i + 1, "Write", s.Write);
        if (error)
            return error;
        error = GetStatLine(lines, i + 2, "Sync", s.Sync);
        if (error)
            return error;
        error = GetStatLine(lines, i + 3, "Async", s.Async);
        if (error)
            return error;

        stat.push_back(s);
    }

    return TError::Success();
}