atimer.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. *openPilot Log - A FOSS Pilot Logbook Application
  3. *Copyright (C) 2020 Felix Turowsky
  4. *
  5. *This program is free software: you can redistribute it and/or modify
  6. *it under the terms of the GNU General Public License as published by
  7. *the Free Software Foundation, either version 3 of the License, or
  8. *(at your option) any later version.
  9. *
  10. *This program is distributed in the hope that it will be useful,
  11. *but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. *GNU General Public License for more details.
  14. *
  15. *You should have received a copy of the GNU General Public License
  16. *along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. #include "atimer.h"
  19. ATimer::ATimer(QObject *parent) : QObject(parent)
  20. {
  21. start = std::chrono::high_resolution_clock::now();
  22. if(parent == nullptr) {
  23. DEB << "Starting Timer... ";
  24. } else {
  25. DEB << "Starting Timer for: " << parent->objectName();
  26. }
  27. }
  28. ATimer::~ATimer()
  29. {
  30. stop = std::chrono::high_resolution_clock::now();
  31. if(parent() == nullptr) {
  32. DEB << "Execution time: "
  33. << std::chrono::duration_cast<std::chrono::milliseconds>(stop - start).count()
  34. << "milliseconds.";
  35. } else {
  36. DEB << "Execution time for: " << parent()->objectName() << ": "
  37. << std::chrono::duration_cast<std::chrono::milliseconds>(stop - start).count()
  38. << "milliseconds.";
  39. }
  40. }
  41. long ATimer::timeNow()
  42. {
  43. intermediate_point = std::chrono::high_resolution_clock::now();
  44. if(parent() == nullptr) {
  45. DEB << "Intermediate time: "
  46. << std::chrono::duration_cast<std::chrono::milliseconds>(intermediate_point - start).count()
  47. << "milliseconds.";
  48. } else {
  49. DEB << "Intermediate time for: " << parent()->objectName() << ": "
  50. << std::chrono::duration_cast<std::chrono::milliseconds>(intermediate_point - start).count()
  51. << "milliseconds.";
  52. }
  53. return std::chrono::duration_cast<std::chrono::milliseconds>(intermediate_point - start).count();
  54. }