{"action":"created","comment":{"url":"https://api.github.com/repos/eminence/procfs/pulls/comments/331796941","pull_request_review_id":297846444,"id":331796941,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDMzMTc5Njk0MQ==","diff_hunk":"@@ -0,0 +1,186 @@\n+//! Pressure stall information retreived from `/proc/pressure/cpu`,\n+//! `/proc/pressure/memory` and `/proc/pressure/io`\n+//! may not be available on kernels older than 4.20.0\n+//! For reference: https://lwn.net/Articles/759781/\n+\n+use crate::{ProcError, ProcResult};\n+use std::collections::HashMap;\n+\n+#[derive(Debug)]\n+pub struct PressureRecord {\n+    avg10: f32,\n+    avg60: f32,\n+    avg300: f32,\n+    total: u64,\n+}\n+\n+#[derive(Debug)]\n+pub struct CpuPressure {\n+    some: PressureRecord,\n+}\n+\n+#[derive(Debug)]\n+pub struct MemoryPressure {\n+    some: PressureRecord,\n+    full: PressureRecord,\n+}\n+\n+#[derive(Debug)]\n+pub struct IoPressure {\n+    some: PressureRecord,\n+    full: PressureRecord,\n+}\n+\n+fn get_f32(map: &HashMap<&str, &str>, value: &str) -> ProcResult<f32> {\n+    map.get(value).map_or_else(\n+        || Err(ProcError::Incomplete(None)),\n+        |v| Ok(v.parse::<f32>().map_err(|_| ProcError::Incomplete(None))?),\n+    )\n+}\n+\n+fn get_total(map: &HashMap<&str, &str>) -> ProcResult<u64> {\n+    map.get(\"total\").map_or_else(\n+        || Err(ProcError::Incomplete(None)),\n+        |v| Ok(v.parse::<u64>().map_err(|_| ProcError::Incomplete(None))?),\n+    )\n+}\n+\n+fn parse_pressure_record(line: &str) -> ProcResult<PressureRecord> {\n+    let mut parsed = HashMap::new();\n+\n+    if !line.starts_with(\"some\") && !line.starts_with(\"full\") {\n+        return Err(ProcError::Incomplete(None));\n+    }\n+\n+    let values = &line[5..];\n+\n+    for kv_str in values.split_whitespace() {\n+        let kv_split = kv_str.split('=');\n+        let vec: Vec<&str> = kv_split.collect();\n+        if vec.len() == 2 {\n+            parsed.insert(vec[0], vec[1]);\n+        }\n+    }\n+\n+    Ok(PressureRecord {\n+        avg10: get_f32(&parsed, \"avg10\")?,\n+        avg60: get_f32(&parsed, \"avg60\")?,\n+        avg300: get_f32(&parsed, \"avg300\")?,\n+        total: get_total(&parsed)?,\n+    })\n+}\n+\n+pub fn cpu_pressure() -> ProcResult<CpuPressure> {\n+    use std::fs::File;\n+    use std::io::{BufRead, BufReader};\n+\n+    let file = File::open(\"/proc/pressure/cpu\")?;\n+    let mut reader = BufReader::new(file);\n+\n+    let mut some = String::new();\n+    reader.read_line(&mut some)?;\n+\n+    Ok(CpuPressure {\n+        some: parse_pressure_record(&some)?,\n+    })\n+}\n+\n+fn get_pressure(pressure_file: &str) -> ProcResult<(PressureRecord, PressureRecord)> {\n+    use std::fs::File;\n+    use std::io::{BufRead, BufReader};\n+\n+    let file = File::open(format!(\"/proc/pressure/{}\", pressure_file))?;\n+    let mut reader = BufReader::new(file);\n+\n+    let mut some = String::new();\n+    reader.read_line(&mut some)?;\n+    let mut full = String::new();\n+    reader.read_line(&mut full)?;\n+\n+    Ok((parse_pressure_record(&some)?, parse_pressure_record(&full)?))\n+}\n+\n+pub fn memory_pressure() -> ProcResult<MemoryPressure> {\n+    let (some, full) = get_pressure(\"memory\")?;\n+\n+    Ok(MemoryPressure { some, full })\n+}\n+\n+pub fn io_pressure() -> ProcResult<MemoryPressure> {","path":"src/pressure.rs","position":null,"original_position":109,"commit_id":"bab9cd6d652c43cbe70155e5c056af3bc30bf220","original_commit_id":"7f54c3d14d66bf66f93d2b2b1df2ac81eb9ea2fe","user":{"login":"idanski","id":7109652,"node_id":"MDQ6VXNlcjcxMDk2NTI=","avatar_url":"https://avatars0.githubusercontent.com/u/7109652?v=4","gravatar_id":"","url":"https://api.github.com/users/idanski","html_url":"https://github.com/idanski","followers_url":"https://api.github.com/users/idanski/followers","following_url":"https://api.github.com/users/idanski/following{/other_user}","gists_url":"https://api.github.com/users/idanski/gists{/gist_id}","starred_url":"https://api.github.com/users/idanski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/idanski/subscriptions","organizations_url":"https://api.github.com/users/idanski/orgs","repos_url":"https://api.github.com/users/idanski/repos","events_url":"https://api.github.com/users/idanski/events{/privacy}","received_events_url":"https://api.github.com/users/idanski/received_events","type":"User","site_admin":false},"body":"D'oh :man_facepalming: fixed!\r\nGood catch.","created_at":"2019-10-06T16:02:24Z","updated_at":"2019-10-06T16:02:24Z","html_url":"https://github.com/eminence/procfs/pull/41#discussion_r331796941","pull_request_url":"https://api.github.com/repos/eminence/procfs/pulls/41","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/eminence/procfs/pulls/comments/331796941"},"html":{"href":"https://github.com/eminence/procfs/pull/41#discussion_r331796941"},"pull_request":{"href":"https://api.github.com/repos/eminence/procfs/pulls/41"}},"in_reply_to_id":331793006},"pull_request":{"url":"https://api.github.com/repos/eminence/procfs/pulls/41","id":324437237,"node_id":"MDExOlB1bGxSZXF1ZXN0MzI0NDM3MjM3","html_url":"https://github.com/eminence/procfs/pull/41","diff_url":"https://github.com/eminence/procfs/pull/41.diff","patch_url":"https://github.com/eminence/procfs/pull/41.patch","issue_url":"https://api.github.com/repos/eminence/procfs/issues/41","number":41,"state":"open","locked":false,"title":"Add /proc/pressure parser (closes #40)","user":{"login":"idanski","id":7109652,"node_id":"MDQ6VXNlcjcxMDk2NTI=","avatar_url":"https://avatars0.githubusercontent.com/u/7109652?v=4","gravatar_id":"","url":"https://api.github.com/users/idanski","html_url":"https://github.com/idanski","followers_url":"https://api.github.com/users/idanski/followers","following_url":"https://api.github.com/users/idanski/following{/other_user}","gists_url":"https://api.github.com/users/idanski/gists{/gist_id}","starred_url":"https://api.github.com/users/idanski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/idanski/subscriptions","organizations_url":"https://api.github.com/users/idanski/orgs","repos_url":"https://api.github.com/users/idanski/repos","events_url":"https://api.github.com/users/idanski/events{/privacy}","received_events_url":"https://api.github.com/users/idanski/received_events","type":"User","site_admin":false},"body":"","created_at":"2019-10-03T22:35:00Z","updated_at":"2019-10-06T16:02:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cedf65a96b046a13337337c96ad226bff7d585fe","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/eminence/procfs/pulls/41/commits","review_comments_url":"https://api.github.com/repos/eminence/procfs/pulls/41/comments","review_comment_url":"https://api.github.com/repos/eminence/procfs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/eminence/procfs/issues/41/comments","statuses_url":"https://api.github.com/repos/eminence/procfs/statuses/bab9cd6d652c43cbe70155e5c056af3bc30bf220","head":{"label":"idanski:pressure","ref":"pressure","sha":"bab9cd6d652c43cbe70155e5c056af3bc30bf220","user":{"login":"idanski","id":7109652,"node_id":"MDQ6VXNlcjcxMDk2NTI=","avatar_url":"https://avatars0.githubusercontent.com/u/7109652?v=4","gravatar_id":"","url":"https://api.github.com/users/idanski","html_url":"https://github.com/idanski","followers_url":"https://api.github.com/users/idanski/followers","following_url":"https://api.github.com/users/idanski/following{/other_user}","gists_url":"https://api.github.com/users/idanski/gists{/gist_id}","starred_url":"https://api.github.com/users/idanski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/idanski/subscriptions","organizations_url":"https://api.github.com/users/idanski/orgs","repos_url":"https://api.github.com/users/idanski/repos","events_url":"https://api.github.com/users/idanski/events{/privacy}","received_events_url":"https://api.github.com/users/idanski/received_events","type":"User","site_admin":false},"repo":{"id":212647552,"node_id":"MDEwOlJlcG9zaXRvcnkyMTI2NDc1NTI=","name":"procfs","full_name":"idanski/procfs","private":false,"owner":{"login":"idanski","id":7109652,"node_id":"MDQ6VXNlcjcxMDk2NTI=","avatar_url":"https://avatars0.githubusercontent.com/u/7109652?v=4","gravatar_id":"","url":"https://api.github.com/users/idanski","html_url":"https://github.com/idanski","followers_url":"https://api.github.com/users/idanski/followers","following_url":"https://api.github.com/users/idanski/following{/other_user}","gists_url":"https://api.github.com/users/idanski/gists{/gist_id}","starred_url":"https://api.github.com/users/idanski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/idanski/subscriptions","organizations_url":"https://api.github.com/users/idanski/orgs","repos_url":"https://api.github.com/users/idanski/repos","events_url":"https://api.github.com/users/idanski/events{/privacy}","received_events_url":"https://api.github.com/users/idanski/received_events","type":"User","site_admin":false},"html_url":"https://github.com/idanski/procfs","description":"Rust library for reading the Linux procfs filesystem","fork":true,"url":"https://api.github.com/repos/idanski/procfs","forks_url":"https://api.github.com/repos/idanski/procfs/forks","keys_url":"https://api.github.com/repos/idanski/procfs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/idanski/procfs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/idanski/procfs/teams","hooks_url":"https://api.github.com/repos/idanski/procfs/hooks","issue_events_url":"https://api.github.com/repos/idanski/procfs/issues/events{/number}","events_url":"https://api.github.com/repos/idanski/procfs/events","assignees_url":"https://api.github.com/repos/idanski/procfs/assignees{/user}","branches_url":"https://api.github.com/repos/idanski/procfs/branches{/branch}","tags_url":"https://api.github.com/repos/idanski/procfs/tags","blobs_url":"https://api.github.com/repos/idanski/procfs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/idanski/procfs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/idanski/procfs/git/refs{/sha}","trees_url":"https://api.github.com/repos/idanski/procfs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/idanski/procfs/statuses/{sha}","languages_url":"https://api.github.com/repos/idanski/procfs/languages","stargazers_url":"https://api.github.com/repos/idanski/procfs/stargazers","contributors_url":"https://api.github.com/repos/idanski/procfs/contributors","subscribers_url":"https://api.github.com/repos/idanski/procfs/subscribers","subscription_url":"https://api.github.com/repos/idanski/procfs/subscription","commits_url":"https://api.github.com/repos/idanski/procfs/commits{/sha}","git_commits_url":"https://api.github.com/repos/idanski/procfs/git/commits{/sha}","comments_url":"https://api.github.com/repos/idanski/procfs/comments{/number}","issue_comment_url":"https://api.github.com/repos/idanski/procfs/issues/comments{/number}","contents_url":"https://api.github.com/repos/idanski/procfs/contents/{+path}","compare_url":"https://api.github.com/repos/idanski/procfs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/idanski/procfs/merges","archive_url":"https://api.github.com/repos/idanski/procfs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/idanski/procfs/downloads","issues_url":"https://api.github.com/repos/idanski/procfs/issues{/number}","pulls_url":"https://api.github.com/repos/idanski/procfs/pulls{/number}","milestones_url":"https://api.github.com/repos/idanski/procfs/milestones{/number}","notifications_url":"https://api.github.com/repos/idanski/procfs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/idanski/procfs/labels{/name}","releases_url":"https://api.github.com/repos/idanski/procfs/releases{/id}","deployments_url":"https://api.github.com/repos/idanski/procfs/deployments","created_at":"2019-10-03T18:14:04Z","updated_at":"2019-10-03T18:14:05Z","pushed_at":"2019-10-06T16:01:14Z","git_url":"git://github.com/idanski/procfs.git","ssh_url":"git@github.com:idanski/procfs.git","clone_url":"https://github.com/idanski/procfs.git","svn_url":"https://github.com/idanski/procfs","homepage":null,"size":186,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"eminence:master","ref":"master","sha":"875406c5bfda03700f3d4375a99e09e2d42e0428","user":{"login":"eminence","id":402454,"node_id":"MDQ6VXNlcjQwMjQ1NA==","avatar_url":"https://avatars0.githubusercontent.com/u/402454?v=4","gravatar_id":"","url":"https://api.github.com/users/eminence","html_url":"https://github.com/eminence","followers_url":"https://api.github.com/users/eminence/followers","following_url":"https://api.github.com/users/eminence/following{/other_user}","gists_url":"https://api.github.com/users/eminence/gists{/gist_id}","starred_url":"https://api.github.com/users/eminence/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eminence/subscriptions","organizations_url":"https://api.github.com/users/eminence/orgs","repos_url":"https://api.github.com/users/eminence/repos","events_url":"https://api.github.com/users/eminence/events{/privacy}","received_events_url":"https://api.github.com/users/eminence/received_events","type":"User","site_admin":false},"repo":{"id":135060366,"node_id":"MDEwOlJlcG9zaXRvcnkxMzUwNjAzNjY=","name":"procfs","full_name":"eminence/procfs","private":false,"owner":{"login":"eminence","id":402454,"node_id":"MDQ6VXNlcjQwMjQ1NA==","avatar_url":"https://avatars0.githubusercontent.com/u/402454?v=4","gravatar_id":"","url":"https://api.github.com/users/eminence","html_url":"https://github.com/eminence","followers_url":"https://api.github.com/users/eminence/followers","following_url":"https://api.github.com/users/eminence/following{/other_user}","gists_url":"https://api.github.com/users/eminence/gists{/gist_id}","starred_url":"https://api.github.com/users/eminence/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eminence/subscriptions","organizations_url":"https://api.github.com/users/eminence/orgs","repos_url":"https://api.github.com/users/eminence/repos","events_url":"https://api.github.com/users/eminence/events{/privacy}","received_events_url":"https://api.github.com/users/eminence/received_events","type":"User","site_admin":false},"html_url":"https://github.com/eminence/procfs","description":"Rust library for reading the Linux procfs filesystem","fork":false,"url":"https://api.github.com/repos/eminence/procfs","forks_url":"https://api.github.com/repos/eminence/procfs/forks","keys_url":"https://api.github.com/repos/eminence/procfs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eminence/procfs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eminence/procfs/teams","hooks_url":"https://api.github.com/repos/eminence/procfs/hooks","issue_events_url":"https://api.github.com/repos/eminence/procfs/issues/events{/number}","events_url":"https://api.github.com/repos/eminence/procfs/events","assignees_url":"https://api.github.com/repos/eminence/procfs/assignees{/user}","branches_url":"https://api.github.com/repos/eminence/procfs/branches{/branch}","tags_url":"https://api.github.com/repos/eminence/procfs/tags","blobs_url":"https://api.github.com/repos/eminence/procfs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eminence/procfs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eminence/procfs/git/refs{/sha}","trees_url":"https://api.github.com/repos/eminence/procfs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eminence/procfs/statuses/{sha}","languages_url":"https://api.github.com/repos/eminence/procfs/languages","stargazers_url":"https://api.github.com/repos/eminence/procfs/stargazers","contributors_url":"https://api.github.com/repos/eminence/procfs/contributors","subscribers_url":"https://api.github.com/repos/eminence/procfs/subscribers","subscription_url":"https://api.github.com/repos/eminence/procfs/subscription","commits_url":"https://api.github.com/repos/eminence/procfs/commits{/sha}","git_commits_url":"https://api.github.com/repos/eminence/procfs/git/commits{/sha}","comments_url":"https://api.github.com/repos/eminence/procfs/comments{/number}","issue_comment_url":"https://api.github.com/repos/eminence/procfs/issues/comments{/number}","contents_url":"https://api.github.com/repos/eminence/procfs/contents/{+path}","compare_url":"https://api.github.com/repos/eminence/procfs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eminence/procfs/merges","archive_url":"https://api.github.com/repos/eminence/procfs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eminence/procfs/downloads","issues_url":"https://api.github.com/repos/eminence/procfs/issues{/number}","pulls_url":"https://api.github.com/repos/eminence/procfs/pulls{/number}","milestones_url":"https://api.github.com/repos/eminence/procfs/milestones{/number}","notifications_url":"https://api.github.com/repos/eminence/procfs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eminence/procfs/labels{/name}","releases_url":"https://api.github.com/repos/eminence/procfs/releases{/id}","deployments_url":"https://api.github.com/repos/eminence/procfs/deployments","created_at":"2018-05-27T15:48:49Z","updated_at":"2019-10-06T14:48:09Z","pushed_at":"2019-10-06T16:01:15Z","git_url":"git://github.com/eminence/procfs.git","ssh_url":"git@github.com:eminence/procfs.git","clone_url":"https://github.com/eminence/procfs.git","svn_url":"https://github.com/eminence/procfs","homepage":null,"size":205,"stargazers_count":19,"watchers_count":19,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":6,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":12,"open_issues":6,"watchers":19,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/eminence/procfs/pulls/41"},"html":{"href":"https://github.com/eminence/procfs/pull/41"},"issue":{"href":"https://api.github.com/repos/eminence/procfs/issues/41"},"comments":{"href":"https://api.github.com/repos/eminence/procfs/issues/41/comments"},"review_comments":{"href":"https://api.github.com/repos/eminence/procfs/pulls/41/comments"},"review_comment":{"href":"https://api.github.com/repos/eminence/procfs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/eminence/procfs/pulls/41/commits"},"statuses":{"href":"https://api.github.com/repos/eminence/procfs/statuses/bab9cd6d652c43cbe70155e5c056af3bc30bf220"}},"author_association":"NONE"}}
{"actor":{"display_login":"idanski"}}