You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.7KB

  1. /*
  2. * Copyright (c) 2016 The ZLToolKit project authors. All Rights Reserved.
  3. *
  4. * This file is part of ZLToolKit(https://github.com/ZLMediaKit/ZLToolKit).
  5. *
  6. * Use of this source code is governed by MIT license that can be found in the
  7. * LICENSE file in the root of the source tree. All contributing project authors
  8. * may be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include <csignal>
  11. #include <iostream>
  12. #include "Util/util.h"
  13. #include "Util/logger.h"
  14. #include "Util/TimeTicker.h"
  15. #include "Poller/EventPoller.h"
  16. using namespace std;
  17. using namespace toolkit;
  18. /**
  19. * cpu负载均衡测试
  20. * @return
  21. */
  22. int main() {
  23. static bool exit_flag = false;
  24. signal(SIGINT, [](int) { exit_flag = true; });
  25. //设置日志
  26. Logger::Instance().add(std::make_shared<ConsoleChannel>());
  27. Ticker ticker;
  28. while(!exit_flag){
  29. if(ticker.elapsedTime() > 1000){
  30. auto vec = EventPollerPool::Instance().getExecutorLoad();
  31. _StrPrinter printer;
  32. for(auto load : vec){
  33. printer << load << "-";
  34. }
  35. DebugL << "cpu负载:" << printer;
  36. EventPollerPool::Instance().getExecutorDelay([](const vector<int> &vec){
  37. _StrPrinter printer;
  38. for(auto delay : vec){
  39. printer << delay << "-";
  40. }
  41. DebugL << "cpu任务执行延时:" << printer;
  42. });
  43. ticker.resetTime();
  44. }
  45. EventPollerPool::Instance().getExecutor()->async([](){
  46. auto usec = rand() % 4000;
  47. //DebugL << usec;
  48. usleep(usec);
  49. });
  50. usleep(2000);
  51. }
  52. return 0;
  53. }