Measuring CPU usage with top - dependency on delay?











up vote
0
down vote

favorite












I try to measure per process CPU utilization. There are many answers to other questions which suggest to use top for this. My top call looks like this:



top -b -n 2 -d <delay> -p <pid> | tail -1 | awk '{print $7}'


My question is now how to choose the delay. Seemingly, the %CPU values I get, are highly dependent on the delay I choose. When I choose -d 1 (1 second) I only get xx.0 %, sometimes xx.9 %. When I choose -d 2 I only get xx.0 % or xx.5 %. With d=1.5 I always get xx.0 %, xx.3% or xx.7 % (Probably, these are thrids?). When I use d=1.7 I get nearly all decimal digits.



Why is this the case?










share|improve this question









New contributor




lukasl1991 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    0
    down vote

    favorite












    I try to measure per process CPU utilization. There are many answers to other questions which suggest to use top for this. My top call looks like this:



    top -b -n 2 -d <delay> -p <pid> | tail -1 | awk '{print $7}'


    My question is now how to choose the delay. Seemingly, the %CPU values I get, are highly dependent on the delay I choose. When I choose -d 1 (1 second) I only get xx.0 %, sometimes xx.9 %. When I choose -d 2 I only get xx.0 % or xx.5 %. With d=1.5 I always get xx.0 %, xx.3% or xx.7 % (Probably, these are thrids?). When I use d=1.7 I get nearly all decimal digits.



    Why is this the case?










    share|improve this question









    New contributor




    lukasl1991 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I try to measure per process CPU utilization. There are many answers to other questions which suggest to use top for this. My top call looks like this:



      top -b -n 2 -d <delay> -p <pid> | tail -1 | awk '{print $7}'


      My question is now how to choose the delay. Seemingly, the %CPU values I get, are highly dependent on the delay I choose. When I choose -d 1 (1 second) I only get xx.0 %, sometimes xx.9 %. When I choose -d 2 I only get xx.0 % or xx.5 %. With d=1.5 I always get xx.0 %, xx.3% or xx.7 % (Probably, these are thrids?). When I use d=1.7 I get nearly all decimal digits.



      Why is this the case?










      share|improve this question









      New contributor




      lukasl1991 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I try to measure per process CPU utilization. There are many answers to other questions which suggest to use top for this. My top call looks like this:



      top -b -n 2 -d <delay> -p <pid> | tail -1 | awk '{print $7}'


      My question is now how to choose the delay. Seemingly, the %CPU values I get, are highly dependent on the delay I choose. When I choose -d 1 (1 second) I only get xx.0 %, sometimes xx.9 %. When I choose -d 2 I only get xx.0 % or xx.5 %. With d=1.5 I always get xx.0 %, xx.3% or xx.7 % (Probably, these are thrids?). When I use d=1.7 I get nearly all decimal digits.



      Why is this the case?







      linux top cpu-usage






      share|improve this question









      New contributor




      lukasl1991 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      lukasl1991 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited Nov 23 at 8:45





















      New contributor




      lukasl1991 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 22 at 11:18









      lukasl1991

      12




      12




      New contributor




      lukasl1991 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      lukasl1991 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      lukasl1991 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.



























          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          lukasl1991 is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483422%2fmeasuring-cpu-usage-with-top-dependency-on-delay%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          lukasl1991 is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          lukasl1991 is a new contributor. Be nice, and check out our Code of Conduct.













          lukasl1991 is a new contributor. Be nice, and check out our Code of Conduct.












          lukasl1991 is a new contributor. Be nice, and check out our Code of Conduct.















           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483422%2fmeasuring-cpu-usage-with-top-dependency-on-delay%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Morgemoulin

          Scott Moir

          Souastre