A SystemC productivity library for virtual platform development utilizing SCV and TLM2.0 https://www.minres.com/#opensource

perf_estimator.h 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*******************************************************************************
  2. * Copyright 2018 MINRES Technologies GmbH
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *******************************************************************************/
  16. #ifndef _SCC_PERFORMANCETRACER_H_
  17. #define _SCC_PERFORMANCETRACER_H_
  18. #include <boost/date_time/posix_time/posix_time.hpp>
  19. #include <systemc>
  20. namespace scc {
  21. /**
  22. * a performance estimator
  23. * it records the time stamps a various time points (start and end of simulation) and calculates
  24. * some performance figures
  25. */
  26. class perf_estimator : public sc_core::sc_module {
  27. //! some internal data structure to record a time stamp
  28. struct time_stamp {
  29. boost::posix_time::ptime wall_clock_stamp;
  30. double proc_clock_stamp;
  31. time_stamp()
  32. : wall_clock_stamp(boost::posix_time::microsec_clock::universal_time())
  33. , proc_clock_stamp(get_cpu_time()) {}
  34. time_stamp &operator=(const time_stamp &o) {
  35. wall_clock_stamp = o.wall_clock_stamp;
  36. proc_clock_stamp = o.proc_clock_stamp;
  37. return *this;
  38. }
  39. void set() {
  40. wall_clock_stamp = boost::posix_time::microsec_clock::universal_time();
  41. proc_clock_stamp = get_cpu_time();
  42. }
  43. private:
  44. static double get_cpu_time();
  45. };
  46. public:
  47. //! yes, we have some SystemC processes
  48. SC_HAS_PROCESS(perf_estimator);// NOLINT
  49. /**
  50. * default constructor
  51. */
  52. perf_estimator();
  53. /**
  54. * the destructor
  55. */
  56. virtual ~perf_estimator();
  57. protected:
  58. //! SystemC callbacks
  59. void start_of_simulation() override;
  60. void end_of_simulation() override;
  61. //! the recorded time stamps
  62. time_stamp sos, eos;
  63. };
  64. } /* namespace scc */
  65. #endif /* _SCC_PERFORMANCETRACER_H_ */