Skip to content

Commit

Permalink
Merge pull request #311 from facebookexperimental/htejun/update-deps
Browse files Browse the repository at this point in the history
Update enum-iterartor dependency to the latest
  • Loading branch information
htejun authored Apr 25, 2024
2 parents ef63c30 + f65eedf commit 2d545f7
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 53 deletions.
31 changes: 10 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rd-agent-intf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rd-hashd-intf = { path = "../rd-hashd-intf", version = "2.2.6" }
anyhow = "1.0"
clap = "2.33"
chrono = { version = "0.4", features = ["serde"] }
enum-iterator = "0.7"
enum-iterator = "2.0"
lazy_static = "1.4"
libc = "0.2"
log = "0.4"
Expand Down
6 changes: 3 additions & 3 deletions rd-agent-intf/src/slices.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Facebook, Inc. and its affiliates.
use anyhow::Result;
use enum_iterator::IntoEnumIterator;
use enum_iterator::Sequence;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::ops::{Index, IndexMut};
Expand All @@ -26,7 +26,7 @@ const SLICE_DOC: &str = "\
//
";

#[derive(Debug, Copy, Clone, IntoEnumIterator, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, Sequence, PartialEq, Eq)]
pub enum Slice {
Init = 0,
Host = 1,
Expand Down Expand Up @@ -181,7 +181,7 @@ pub struct SliceKnobs {
impl Default for SliceKnobs {
fn default() -> Self {
let mut slices = BTreeMap::new();
for slc in Slice::into_enum_iter() {
for slc in enum_iterator::all::<Slice>() {
slices.insert(slc.name().into(), SliceConfig::default(slc));
}
Self {
Expand Down
16 changes: 3 additions & 13 deletions rd-agent-intf/src/sysreqs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Facebook, Inc. and its affiliates.
use enum_iterator::IntoEnumIterator;
use enum_iterator::Sequence;
use log::warn;
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, BTreeSet};
Expand All @@ -21,21 +21,11 @@ const SYSREQ_DOC: &str = "\
";

lazy_static::lazy_static! {
pub static ref ALL_SYSREQS_SET: BTreeSet<SysReq> = SysReq::into_enum_iter().collect();
pub static ref ALL_SYSREQS_SET: BTreeSet<SysReq> = enum_iterator::all::<SysReq>().collect();
}

#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
IntoEnumIterator,
Serialize,
Deserialize,
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Sequence, Serialize, Deserialize,
)]
pub enum SysReq {
Controllers,
Expand Down
2 changes: 1 addition & 1 deletion rd-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rd-agent-intf = { path = "../rd-agent-intf", version = "2.2.6" }
anyhow = "1.0"
chrono = { version = "0.4", features = ["serde"] }
crossbeam = "0.8"
enum-iterator = "0.7"
enum-iterator = "2.0"
glob = "0.3"
json = "0.12"
lazy_static = "1.4"
Expand Down
5 changes: 2 additions & 3 deletions rd-agent/src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use anyhow::{anyhow, bail, Result};
use chrono::prelude::*;
use crossbeam::channel::{self, select, Receiver, Sender};
use enum_iterator::IntoEnumIterator;
use log::{debug, error, info, trace, warn};
use nix::sys::signal::{kill, Signal};
use nix::unistd::Pid;
Expand Down Expand Up @@ -266,7 +265,7 @@ impl UsageTracker {
};

us.usages.insert(ROOT_SLICE.into(), Default::default());
for slice in Slice::into_enum_iter() {
for slice in enum_iterator::all::<Slice>() {
us.usages.insert(slice.name().into(), Default::default());
}

Expand All @@ -281,7 +280,7 @@ impl UsageTracker {

let (us, cpu_total) = read_system_usage(self.devnr)?;
usages.insert(ROOT_SLICE.into(), us);
for slice in Slice::into_enum_iter() {
for slice in enum_iterator::all::<Slice>() {
usages.insert(
slice.name().to_string(),
read_cgroup_usage(slice.cgrp(), self.devnr),
Expand Down
7 changes: 3 additions & 4 deletions rd-agent/src/slices.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Facebook, Inc. and its affiliates.
use anyhow::{Context, Result};
use enum_iterator::IntoEnumIterator;
use glob::glob;
use log::{debug, error, info, trace, warn};
use scan_fmt::scan_fmt;
Expand Down Expand Up @@ -246,7 +245,7 @@ pub fn apply_slices(knobs: &mut SliceKnobs, hashd_mem_size: u64, cfg: &Config) -
}

let mut updated = false;
for slice in Slice::into_enum_iter() {
for slice in enum_iterator::all::<Slice>() {
let enforce_mem = slice_enforce_mem(&cfg.enforce, slice);

if !cfg.enforce.cpu && !enforce_mem && !cfg.enforce.io {
Expand Down Expand Up @@ -353,7 +352,7 @@ fn clear_one_slice(slice: Slice, ecfg: &EnforceConfig) -> Result<bool> {

pub fn clear_slices(ecfg: &EnforceConfig) -> Result<()> {
let mut updated = false;
for slice in Slice::into_enum_iter() {
for slice in enum_iterator::all::<Slice>() {
let enforce_mem = slice_enforce_mem(ecfg, slice);

if !ecfg.cpu && !enforce_mem && !ecfg.io {
Expand Down Expand Up @@ -597,7 +596,7 @@ pub fn verify_and_fix_slices(

let recursive_mem_prot = cfg.memcg_recursive_prot();

for slice in Slice::into_enum_iter() {
for slice in enum_iterator::all::<Slice>() {
let sk = knobs.slices.get(slice.name()).unwrap();

let path = slice.cgrp();
Expand Down
2 changes: 1 addition & 1 deletion resctl-demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ crossbeam = "0.8"
cursive = { version = "^0", default-features = false, features = ["termion"] }
cursive_buffered_backend = "^0"
cursive-tabs = "^0"
enum-iterator = "0.7"
enum-iterator = "2.0"
env_logger = "0.11"
lazy_static = "1.4"
libc = "0.2"
Expand Down
7 changes: 3 additions & 4 deletions resctl-demo/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use cursive::utils::markup::StyledString;
use cursive::view::{Nameable, Resizable, Scrollable, SizeConstraint, View};
use cursive::views::{Button, Checkbox, Dialog, DummyView, LinearLayout, SliderView, TextView};
use cursive::Cursive;
use enum_iterator::IntoEnumIterator;
use log::{error, info, warn};
use std::collections::{BTreeMap, BTreeSet, HashSet};
use std::sync::{Mutex, RwLock};
Expand Down Expand Up @@ -94,7 +93,7 @@ fn load_docs() -> BTreeMap<String, &'static str> {

let mut nr_missing = 0;

let graph_tags: HashSet<String> = GraphTag::into_enum_iter()
let graph_tags: HashSet<String> = enum_iterator::all::<GraphTag>()
.map(|x| format!("{:?}", x))
.collect();
for tag in graphs.iter() {
Expand Down Expand Up @@ -122,7 +121,7 @@ fn format_markup_tags(tag: &str) -> Option<StyledString> {
let empty_some = Some(StyledString::plain(""));

if tag.starts_with("SysReq::") {
for req in SysReq::into_enum_iter() {
for req in enum_iterator::all::<SysReq>() {
if format!("{:?}", req) == tag[8..] {
if sysreqs.satisfied.contains(&req) {
return Some(StyledString::styled(tag, *COLOR_ACTIVE));
Expand Down Expand Up @@ -288,7 +287,7 @@ fn exec_one_cmd(siv: &mut Cursive, cmd: &RdCmd) {
},
RdCmd::Graph(tag_name) => {
if tag_name.len() > 0 {
let tag = GraphTag::into_enum_iter()
let tag = enum_iterator::all::<GraphTag>()
.filter(|x| &format!("{:?}", x) == tag_name)
.next()
.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions resctl-demo/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cursive::view::{Nameable, Resizable, SizeConstraint, View};
use cursive::views::{DummyView, LinearLayout, NamedView, Panel, ResizedView, TextView};
use cursive::Cursive;
use cursive_tabs::TabView;
use enum_iterator::IntoEnumIterator;
use enum_iterator::Sequence;
use log::error;
use std::collections::HashMap;
use std::fmt;
Expand Down Expand Up @@ -693,7 +693,7 @@ fn plot_spec_factory(id: PlotId) -> PlotSpec {
}
}

#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug, IntoEnumIterator)]
#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug, Sequence)]
pub enum GraphTag {
HashdA,
HashdB,
Expand Down

0 comments on commit 2d545f7

Please sign in to comment.