{"action":"created","issue":{"url":"https://api.github.com/repos/oshi/oshi/issues/683","repository_url":"https://api.github.com/repos/oshi/oshi","labels_url":"https://api.github.com/repos/oshi/oshi/issues/683/labels{/name}","comments_url":"https://api.github.com/repos/oshi/oshi/issues/683/comments","events_url":"https://api.github.com/repos/oshi/oshi/issues/683/events","html_url":"https://github.com/oshi/oshi/issues/683","id":381868020,"node_id":"MDU6SXNzdWUzODE4NjgwMjA=","number":683,"title":"USER_HZ counts incorrectly on Linux with variable number of cpus","user":{"login":"risik","id":1710758,"node_id":"MDQ6VXNlcjE3MTA3NTg=","avatar_url":"https://avatars1.githubusercontent.com/u/1710758?v=4","gravatar_id":"","url":"https://api.github.com/users/risik","html_url":"https://github.com/risik","followers_url":"https://api.github.com/users/risik/followers","following_url":"https://api.github.com/users/risik/following{/other_user}","gists_url":"https://api.github.com/users/risik/gists{/gist_id}","starred_url":"https://api.github.com/users/risik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/risik/subscriptions","organizations_url":"https://api.github.com/users/risik/orgs","repos_url":"https://api.github.com/users/risik/repos","events_url":"https://api.github.com/users/risik/events{/privacy}","received_events_url":"https://api.github.com/users/risik/received_events","type":"User","site_admin":false},"labels":[{"id":143889182,"node_id":"MDU6TGFiZWwxNDM4ODkxODI=","url":"https://api.github.com/repos/oshi/oshi/labels/bug?","name":"bug?","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2018-11-17T14:31:57Z","updated_at":"2018-11-20T04:04:08Z","closed_at":null,"author_association":"NONE","body":"USER_HZ constant calculated incorrectly and so getKernelTime, getUserTime and getUpTime methods of OSProcess class returns incorrect results.\r\n\r\nCode example:\r\n\r\n    private void run() {\r\n        for (int i = 0; i < 100000000; i++) {\r\n            System.out.println(\"-----------------------------------------\");\r\n            printProcessCpuInfo();\r\n            System.out.println(\"=========================================\");\r\n        }\r\n    }\r\n\r\n    void printProcessCpuInfo() {\r\n        final SystemInfo si = new SystemInfo();\r\n        final OperatingSystem os = si.getOperatingSystem();\r\n\r\n        // this process\r\n        final int processId = os.getProcessId();\r\n        final OSProcess osProcess = os.getProcess(processId);\r\n\r\n        try {\r\n            Thread.sleep(1000);\r\n        }\r\n        catch (InterruptedException ignored) {\r\n        }\r\n\r\n        System.out.println(\"now: \" + new Date().getTime());\r\n        System.out.println(\"System.nanoTime(): \" + System.nanoTime());\r\n        System.out.println(\"process.start_time: \" + osProcess.getStartTime()); // here OK\r\n        System.out.println(\"process.cpu.kernel_usage_ms: \" + osProcess.getKernelTime()); // it's too large\r\n        System.out.println(\"process.cpu.user_usage_ms: \" + osProcess.getUserTime());  // it's too large\r\n        System.out.println(\"process.cpu.up_time: \" + osProcess.getUpTime()); // here always 1\r\n        System.out.println(\"process.cpu.usage_percent: \" + osProcess.calculateCpuPercent()); // here we have very large values due getUpTime works incorrectly\r\n    }\r\n\r\nOutput example:\r\n\r\nnow: 1542464204617\r\nSystem.nanoTime(): 90196842438436\r\nprocess.start_time: 1542464203607\r\nprocess.cpu.kernel_usage_ms: 1705\r\nprocess.cpu.user_usage_ms: 10029\r\nprocess.cpu.up_time: 1\r\nprocess.cpu.usage_percent: 11734.0\r\n\r\nnow: 1542464205623\r\nSystem.nanoTime(): 90197848765779\r\nprocess.start_time: 1542464204618\r\nprocess.cpu.kernel_usage_ms: 1735\r\nprocess.cpu.user_usage_ms: 10058\r\nprocess.cpu.up_time: 1\r\nprocess.cpu.usage_percent: 11793.0\r\n\r\nIn this time HTOP displays time 4.01 seconds.\r\n\r\nbefore stop application:\r\n$ cat /proc/14826/stat | awk '{print \"PPID: \" $4 \" USER_TIME: \" $14 \" KERNEL_TIME: \" $15 \" PRIORITY: \" $18 \" THREAD_COUNT: \" $20 \" START_TIME: \" $22 \" VSZ: \" $23 \" RSS: \" $24}'\r\nPPID: 14754 USER_TIME: 290 KERNEL_TIME: 46 PRIORITY: 20 THREAD_COUNT: 19 START_TIME: 26330527 VSZ: 11364433920 RSS: 27482\r\n\r\n$ cat /proc/uptime \r\n263616.17 276045.52\r\n\r\nuptime in htop: 3 days + 1hour...\r\n\r\nWhile debugging library code I see that USER_HZ=36 but according my calculation it must be approx 10.\r\n\r\nMy platform:\r\n\r\n$ uname -orp\r\n4.15.0-39-generic x86_64 GNU/Linux\r\n\r\n$ java -version\r\njava version \"1.8.0_191\"\r\nJava(TM) SE Runtime Environment (build 1.8.0_191-b12)\r\nJava HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/oshi/oshi/issues/comments/440130496","html_url":"https://github.com/oshi/oshi/issues/683#issuecomment-440130496","issue_url":"https://api.github.com/repos/oshi/oshi/issues/683","id":440130496,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MDEzMDQ5Ng==","user":{"login":"dbwiddis","id":9291703,"node_id":"MDQ6VXNlcjkyOTE3MDM=","avatar_url":"https://avatars0.githubusercontent.com/u/9291703?v=4","gravatar_id":"","url":"https://api.github.com/users/dbwiddis","html_url":"https://github.com/dbwiddis","followers_url":"https://api.github.com/users/dbwiddis/followers","following_url":"https://api.github.com/users/dbwiddis/following{/other_user}","gists_url":"https://api.github.com/users/dbwiddis/gists{/gist_id}","starred_url":"https://api.github.com/users/dbwiddis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbwiddis/subscriptions","organizations_url":"https://api.github.com/users/dbwiddis/orgs","repos_url":"https://api.github.com/users/dbwiddis/repos","events_url":"https://api.github.com/users/dbwiddis/events{/privacy}","received_events_url":"https://api.github.com/users/dbwiddis/received_events","type":"User","site_admin":false},"created_at":"2018-11-20T04:04:08Z","updated_at":"2018-11-20T04:04:08Z","author_association":"MEMBER","body":"So after all this, I find out that `getconf CLK_TCK` returns USER_HZ from the command line... go figure!"}}
{"actor":{"display_login":"dbwiddis"}}