Bash Shell takes variable amount of time to load

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0















I use bash on Ubuntu 18.04. I have added a lot of functions and a lot of scripts are sourced in my bashrc. I am able to time the total time it takes to load my terminal, sometimes it takes 0.9 seconds to more than a minute. And this happens randomly, not that only at the first time it takes more time.



How can I log and analyze how much time each command in bashrc takes to execute. I hope that the logs are generated every time automatically and when it is slow I could analyse the cause of it.



Any suggestions as to what can be done.



Secondly, would preload daemon be useful to speedup the loading of the terminal. I am not sure about it.










share|improve this question
























  • It's not a duplicate. I want time measurement for each command individually.

    – Nikhil
    Feb 27 at 23:38






  • 1





    Your terminal very probably starts up very quickly. You seem to be talking about your shell.

    – JdeBP
    Feb 27 at 23:54











  • use the command time to time commands eg. time source ./somefuncsA.bash

    – X Tian
    Feb 28 at 14:00















0















I use bash on Ubuntu 18.04. I have added a lot of functions and a lot of scripts are sourced in my bashrc. I am able to time the total time it takes to load my terminal, sometimes it takes 0.9 seconds to more than a minute. And this happens randomly, not that only at the first time it takes more time.



How can I log and analyze how much time each command in bashrc takes to execute. I hope that the logs are generated every time automatically and when it is slow I could analyse the cause of it.



Any suggestions as to what can be done.



Secondly, would preload daemon be useful to speedup the loading of the terminal. I am not sure about it.










share|improve this question
























  • It's not a duplicate. I want time measurement for each command individually.

    – Nikhil
    Feb 27 at 23:38






  • 1





    Your terminal very probably starts up very quickly. You seem to be talking about your shell.

    – JdeBP
    Feb 27 at 23:54











  • use the command time to time commands eg. time source ./somefuncsA.bash

    – X Tian
    Feb 28 at 14:00













0












0








0








I use bash on Ubuntu 18.04. I have added a lot of functions and a lot of scripts are sourced in my bashrc. I am able to time the total time it takes to load my terminal, sometimes it takes 0.9 seconds to more than a minute. And this happens randomly, not that only at the first time it takes more time.



How can I log and analyze how much time each command in bashrc takes to execute. I hope that the logs are generated every time automatically and when it is slow I could analyse the cause of it.



Any suggestions as to what can be done.



Secondly, would preload daemon be useful to speedup the loading of the terminal. I am not sure about it.










share|improve this question
















I use bash on Ubuntu 18.04. I have added a lot of functions and a lot of scripts are sourced in my bashrc. I am able to time the total time it takes to load my terminal, sometimes it takes 0.9 seconds to more than a minute. And this happens randomly, not that only at the first time it takes more time.



How can I log and analyze how much time each command in bashrc takes to execute. I hope that the logs are generated every time automatically and when it is slow I could analyse the cause of it.



Any suggestions as to what can be done.



Secondly, would preload daemon be useful to speedup the loading of the terminal. I am not sure about it.







bash logs performance bashrc time






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 28 at 0:44







Nikhil

















asked Feb 27 at 23:31









NikhilNikhil

367215




367215












  • It's not a duplicate. I want time measurement for each command individually.

    – Nikhil
    Feb 27 at 23:38






  • 1





    Your terminal very probably starts up very quickly. You seem to be talking about your shell.

    – JdeBP
    Feb 27 at 23:54











  • use the command time to time commands eg. time source ./somefuncsA.bash

    – X Tian
    Feb 28 at 14:00

















  • It's not a duplicate. I want time measurement for each command individually.

    – Nikhil
    Feb 27 at 23:38






  • 1





    Your terminal very probably starts up very quickly. You seem to be talking about your shell.

    – JdeBP
    Feb 27 at 23:54











  • use the command time to time commands eg. time source ./somefuncsA.bash

    – X Tian
    Feb 28 at 14:00
















It's not a duplicate. I want time measurement for each command individually.

– Nikhil
Feb 27 at 23:38





It's not a duplicate. I want time measurement for each command individually.

– Nikhil
Feb 27 at 23:38




1




1





Your terminal very probably starts up very quickly. You seem to be talking about your shell.

– JdeBP
Feb 27 at 23:54





Your terminal very probably starts up very quickly. You seem to be talking about your shell.

– JdeBP
Feb 27 at 23:54













use the command time to time commands eg. time source ./somefuncsA.bash

– X Tian
Feb 28 at 14:00





use the command time to time commands eg. time source ./somefuncsA.bash

– X Tian
Feb 28 at 14:00










2 Answers
2






active

oldest

votes


















2














You could print timestamps using the Bash tracing mechanism, given that t is expanded in $PS4:



$ PS4='+ t> ' bash -x -c "sleep 1; sleep 2; sleep 3"
+ 18:41:05> sleep 1
+ 18:41:06> sleep 2
+ 18:41:08> sleep 3


It should be easy to apply this to tracing your .bashrc and/or .profile etc.






share|improve this answer






























    0














    1. You could put the time command before each command in your .bashrc

    2. To direct the output of the time command (and not the command output itself) to a log file, reference this question

    3. You'll probably want to echo out something useful to the log file before each command so that you can identify which command is being timed in the logs.

    4. (optional) You may also want to run date at the beginning of your .bashrc and direct the output to the log file so that you can see which login event is being timed.





    share|improve this answer






















      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',
      autoActivateHeartbeat: false,
      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
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f503444%2fbash-shell-takes-variable-amount-of-time-to-load%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      You could print timestamps using the Bash tracing mechanism, given that t is expanded in $PS4:



      $ PS4='+ t> ' bash -x -c "sleep 1; sleep 2; sleep 3"
      + 18:41:05> sleep 1
      + 18:41:06> sleep 2
      + 18:41:08> sleep 3


      It should be easy to apply this to tracing your .bashrc and/or .profile etc.






      share|improve this answer



























        2














        You could print timestamps using the Bash tracing mechanism, given that t is expanded in $PS4:



        $ PS4='+ t> ' bash -x -c "sleep 1; sleep 2; sleep 3"
        + 18:41:05> sleep 1
        + 18:41:06> sleep 2
        + 18:41:08> sleep 3


        It should be easy to apply this to tracing your .bashrc and/or .profile etc.






        share|improve this answer

























          2












          2








          2







          You could print timestamps using the Bash tracing mechanism, given that t is expanded in $PS4:



          $ PS4='+ t> ' bash -x -c "sleep 1; sleep 2; sleep 3"
          + 18:41:05> sleep 1
          + 18:41:06> sleep 2
          + 18:41:08> sleep 3


          It should be easy to apply this to tracing your .bashrc and/or .profile etc.






          share|improve this answer













          You could print timestamps using the Bash tracing mechanism, given that t is expanded in $PS4:



          $ PS4='+ t> ' bash -x -c "sleep 1; sleep 2; sleep 3"
          + 18:41:05> sleep 1
          + 18:41:06> sleep 2
          + 18:41:08> sleep 3


          It should be easy to apply this to tracing your .bashrc and/or .profile etc.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 28 at 18:41









          Toby SpeightToby Speight

          5,37711132




          5,37711132























              0














              1. You could put the time command before each command in your .bashrc

              2. To direct the output of the time command (and not the command output itself) to a log file, reference this question

              3. You'll probably want to echo out something useful to the log file before each command so that you can identify which command is being timed in the logs.

              4. (optional) You may also want to run date at the beginning of your .bashrc and direct the output to the log file so that you can see which login event is being timed.





              share|improve this answer



























                0














                1. You could put the time command before each command in your .bashrc

                2. To direct the output of the time command (and not the command output itself) to a log file, reference this question

                3. You'll probably want to echo out something useful to the log file before each command so that you can identify which command is being timed in the logs.

                4. (optional) You may also want to run date at the beginning of your .bashrc and direct the output to the log file so that you can see which login event is being timed.





                share|improve this answer

























                  0












                  0








                  0







                  1. You could put the time command before each command in your .bashrc

                  2. To direct the output of the time command (and not the command output itself) to a log file, reference this question

                  3. You'll probably want to echo out something useful to the log file before each command so that you can identify which command is being timed in the logs.

                  4. (optional) You may also want to run date at the beginning of your .bashrc and direct the output to the log file so that you can see which login event is being timed.





                  share|improve this answer













                  1. You could put the time command before each command in your .bashrc

                  2. To direct the output of the time command (and not the command output itself) to a log file, reference this question

                  3. You'll probably want to echo out something useful to the log file before each command so that you can identify which command is being timed in the logs.

                  4. (optional) You may also want to run date at the beginning of your .bashrc and direct the output to the log file so that you can see which login event is being timed.






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 28 at 0:49









                  CrypteyaCrypteya

                  414118




                  414118



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f503444%2fbash-shell-takes-variable-amount-of-time-to-load%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

                      How to check contact read email or not when send email to Individual?

                      Bahrain

                      Postfix configuration issue with fips on centos 7; mailgun relay