BVB Source Codes

mars Show process_cpu_clocks.hpp Source code

Return Download mars: download process_cpu_clocks.hpp Source code - Download mars Source code - Type:.hpp
  1. //  boost process_timer.cpp  -----------------------------------------------------------//
  2.  
  3. //  Copyright Beman Dawes 1994, 2006, 2008
  4. //  Copyright 2009-2010 Vicente J. Botet Escriba
  5. //  Copyright (c) Microsoft Corporation 2014
  6.  
  7. //  Distributed under the Boost Software License, Version 1.0.
  8. //  See http://www.boost.org/LICENSE_1_0.txt
  9.  
  10. //  See http://www.boost.org/libs/chrono for documentation.
  11.  
  12. //--------------------------------------------------------------------------------------//
  13. #ifndef BOOST_CHRONO_DETAIL_INLINED_WIN_PROCESS_CLOCK_HPP
  14. #define BOOST_CHRONO_DETAIL_INLINED_WIN_PROCESS_CLOCK_HPP
  15.  
  16. #include <boost/chrono/config.hpp>
  17. //#include <boost/chrono/system_clocks.hpp>
  18. #include <boost/chrono/process_cpu_clocks.hpp>
  19. #include <cassert>
  20. #include <time.h>
  21.  
  22. #include <boost/detail/winapi/GetLastError.hpp>
  23. #include <boost/detail/winapi/GetCurrentProcess.hpp>
  24. #if BOOST_PLAT_WINDOWS_DESKTOP
  25. #include <boost/detail/winapi/GetProcessTimes.hpp>
  26. #endif
  27.  
  28. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost
  29. {
  30. namespace chrono
  31. {
  32.  
  33. process_real_cpu_clock::time_point process_real_cpu_clock::now() BOOST_NOEXCEPT
  34. {
  35.     clock_t c = ::clock();
  36.     if ( c == clock_t(-1) ) // error
  37.     {
  38.       BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
  39.     }
  40.     typedef ratio_divide<giga, ratio<CLOCKS_PER_SEC> >::type R;
  41.     return time_point(
  42.       duration(static_cast<rep>(c)*R::num/R::den)
  43.     );
  44. }
  45.  
  46. #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
  47. process_real_cpu_clock::time_point process_real_cpu_clock::now(
  48.         system::error_code & ec)
  49. {
  50.     clock_t c = ::clock();
  51.     if ( c == clock_t(-1) ) // error
  52.     {
  53.             mars_boost::throw_exception(
  54.                     system::system_error(
  55.                             errno,
  56.                             BOOST_CHRONO_SYSTEM_CATEGORY,
  57.                             "chrono::process_real_cpu_clock" ));
  58.     }
  59.     if (!BOOST_CHRONO_IS_THROWS(ec))
  60.     {
  61.       ec.clear();
  62.     }
  63.     typedef ratio_divide<giga, ratio<CLOCKS_PER_SEC> >::type R;
  64.     return time_point(
  65.       duration(static_cast<rep>(c)*R::num/R::den)
  66.     );
  67. }
  68. #endif
  69.  
  70. #if BOOST_PLAT_WINDOWS_DESKTOP
  71. process_user_cpu_clock::time_point process_user_cpu_clock::now() BOOST_NOEXCEPT
  72. {
  73.  
  74.     //  note that Windows uses 100 nanosecond ticks for FILETIME
  75.     mars_boost::detail::winapi::FILETIME_ creation, exit, user_time, system_time;
  76.  
  77.     if ( mars_boost::detail::winapi::GetProcessTimes(
  78.             mars_boost::detail::winapi::GetCurrentProcess(), &creation, &exit,
  79.             &system_time, &user_time ) )
  80.     {
  81.         return time_point(duration(
  82.                 ((static_cast<process_user_cpu_clock::rep>(user_time.dwHighDateTime) << 32)
  83.                   | user_time.dwLowDateTime) * 100
  84.                 ));
  85.     }
  86.     else
  87.     {
  88.         BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
  89.         return time_point();
  90.     }
  91.  
  92. }
  93.  
  94. #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
  95. process_user_cpu_clock::time_point process_user_cpu_clock::now(
  96.         system::error_code & ec)
  97. {
  98.  
  99.     //  note that Windows uses 100 nanosecond ticks for FILETIME
  100.     mars_boost::detail::winapi::FILETIME_ creation, exit, user_time, system_time;
  101.  
  102.     if ( mars_boost::detail::winapi::GetProcessTimes(
  103.             mars_boost::detail::winapi::GetCurrentProcess(), &creation, &exit,
  104.             &system_time, &user_time ) )
  105.     {
  106.         if (!BOOST_CHRONO_IS_THROWS(ec))
  107.         {
  108.             ec.clear();
  109.         }
  110.         return time_point(duration(
  111.                 ((static_cast<process_user_cpu_clock::rep>(user_time.dwHighDateTime) << 32)
  112.                   | user_time.dwLowDateTime) * 100
  113.                 ));
  114.     }
  115.     else
  116.     {
  117.         mars_boost::detail::winapi::DWORD_ cause = mars_boost::detail::winapi::GetLastError();
  118.         if (BOOST_CHRONO_IS_THROWS(ec))
  119.         {
  120.             mars_boost::throw_exception(
  121.                     system::system_error(
  122.                             cause,
  123.                             BOOST_CHRONO_SYSTEM_CATEGORY,
  124.                             "chrono::process_user_cpu_clock" ));
  125.         }
  126.         else
  127.         {
  128.             ec.assign( cause, BOOST_CHRONO_SYSTEM_CATEGORY );
  129.             return time_point();
  130.         }
  131.     }
  132.  
  133. }
  134. #endif
  135.  
  136. process_system_cpu_clock::time_point process_system_cpu_clock::now() BOOST_NOEXCEPT
  137. {
  138.  
  139.     //  note that Windows uses 100 nanosecond ticks for FILETIME
  140.     mars_boost::detail::winapi::FILETIME_ creation, exit, user_time, system_time;
  141.  
  142.     if ( mars_boost::detail::winapi::GetProcessTimes(
  143.             mars_boost::detail::winapi::GetCurrentProcess(), &creation, &exit,
  144.             &system_time, &user_time ) )
  145.     {
  146.         return time_point(duration(
  147.                 ((static_cast<process_system_cpu_clock::rep>(system_time.dwHighDateTime) << 32)
  148.                                     | system_time.dwLowDateTime) * 100
  149.                 ));
  150.     }
  151.     else
  152.     {
  153.       BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
  154.       return time_point();
  155.     }
  156.  
  157. }
  158.  
  159. #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
  160. process_system_cpu_clock::time_point process_system_cpu_clock::now(
  161.         system::error_code & ec)
  162. {
  163.  
  164.     //  note that Windows uses 100 nanosecond ticks for FILETIME
  165.     mars_boost::detail::winapi::FILETIME_ creation, exit, user_time, system_time;
  166.  
  167.     if ( mars_boost::detail::winapi::GetProcessTimes(
  168.             mars_boost::detail::winapi::GetCurrentProcess(), &creation, &exit,
  169.             &system_time, &user_time ) )
  170.     {
  171.         if (!BOOST_CHRONO_IS_THROWS(ec))
  172.         {
  173.             ec.clear();
  174.         }
  175.         return time_point(duration(
  176.                 ((static_cast<process_system_cpu_clock::rep>(system_time.dwHighDateTime) << 32)
  177.                                     | system_time.dwLowDateTime) * 100
  178.                 ));
  179.     }
  180.     else
  181.     {
  182.         mars_boost::detail::winapi::DWORD_ cause = mars_boost::detail::winapi::GetLastError();
  183.         if (BOOST_CHRONO_IS_THROWS(ec))
  184.         {
  185.             mars_boost::throw_exception(
  186.                     system::system_error(
  187.                             cause,
  188.                             BOOST_CHRONO_SYSTEM_CATEGORY,
  189.                             "chrono::process_system_cpu_clock" ));
  190.         }
  191.         else
  192.         {
  193.             ec.assign( cause, BOOST_CHRONO_SYSTEM_CATEGORY );
  194.             return time_point();
  195.         }
  196.     }
  197.  
  198. }
  199. #endif
  200.  
  201. process_cpu_clock::time_point process_cpu_clock::now()  BOOST_NOEXCEPT
  202. {
  203.  
  204.     //  note that Windows uses 100 nanosecond ticks for FILETIME
  205.     mars_boost::detail::winapi::FILETIME_ creation, exit, user_time, system_time;
  206.  
  207.     if ( mars_boost::detail::winapi::GetProcessTimes(
  208.             mars_boost::detail::winapi::GetCurrentProcess(), &creation, &exit,
  209.             &system_time, &user_time ) )
  210.     {
  211.         time_point::rep r(process_real_cpu_clock::now().time_since_epoch().count()
  212.                             ,
  213.                 ((static_cast<process_user_cpu_clock::rep>(user_time.dwHighDateTime) << 32)
  214.                         | user_time.dwLowDateTime
  215.                 ) * 100,
  216.                 ((static_cast<process_system_cpu_clock::rep>(system_time.dwHighDateTime) << 32)
  217.                         | system_time.dwLowDateTime
  218.                 ) * 100
  219.         );
  220.         return time_point(duration(r));
  221.     }
  222.     else
  223.     {
  224.       BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
  225.       return time_point();
  226.     }
  227.  
  228. }
  229.  
  230. #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
  231. process_cpu_clock::time_point process_cpu_clock::now(
  232.         system::error_code & ec )
  233. {
  234.  
  235.     //  note that Windows uses 100 nanosecond ticks for FILETIME
  236.     mars_boost::detail::winapi::FILETIME_ creation, exit, user_time, system_time;
  237.  
  238.     if ( mars_boost::detail::winapi::GetProcessTimes(
  239.             mars_boost::detail::winapi::GetCurrentProcess(), &creation, &exit,
  240.             &system_time, &user_time ) )
  241.     {
  242.         if (!BOOST_CHRONO_IS_THROWS(ec))
  243.         {
  244.             ec.clear();
  245.         }
  246.         time_point::rep r(process_real_cpu_clock::now().time_since_epoch().count()
  247.                             ,
  248.                 ((static_cast<process_user_cpu_clock::rep>(user_time.dwHighDateTime) << 32)
  249.                         | user_time.dwLowDateTime
  250.                 ) * 100,
  251.                 ((static_cast<process_system_cpu_clock::rep>(system_time.dwHighDateTime) << 32)
  252.                         | system_time.dwLowDateTime
  253.                 ) * 100
  254.         );
  255.         return time_point(duration(r));
  256.     }
  257.     else
  258.     {
  259.         mars_boost::detail::winapi::DWORD_ cause = mars_boost::detail::winapi::GetLastError();
  260.         if (BOOST_CHRONO_IS_THROWS(ec))
  261.         {
  262.             mars_boost::throw_exception(
  263.                     system::system_error(
  264.                             cause,
  265.                             BOOST_CHRONO_SYSTEM_CATEGORY,
  266.                             "chrono::process_cpu_clock" ));
  267.         }
  268.         else
  269.         {
  270.             ec.assign( cause, BOOST_CHRONO_SYSTEM_CATEGORY );
  271.             return time_point();
  272.         }
  273.     }
  274.  
  275. }
  276. #endif
  277. #endif
  278. } // namespace chrono
  279. } // namespace mars_boost
  280.  
  281. #endif
  282.  
downloadprocess_cpu_clocks.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top