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

monitor.cc 1.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  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. #include <vector>
  17. #include "dataset/core/config_manager.h"
  18. #include "dataset/engine/perf/monitor.h"
  19. #include "dataset/engine/execution_tree.h"
  20. namespace mindspore {
  21. namespace dataset {
  22. Monitor::Monitor(ExecutionTree *tree) : tree_(tree) {
  23. std::shared_ptr<ConfigManager> cfg = GlobalContext::config_manager();
  24. sampling_interval_ = cfg->monitor_sampling_interval();
  25. max_samples_ = 0;
  26. cur_row_ = 0;
  27. }
  28. Status Monitor::operator()() {
  29. // Register this thread with TaskManager to receive proper interrupt signal.
  30. TaskManager::FindMe()->Post();
  31. // Keep sampling if
  32. // 1) Monitor Task is not interrupted by TaskManager AND
  33. // 2) Iterator has not received EOF
  34. while (!this_thread::is_interrupted() && !(tree_->isFinished())) {
  35. for (auto &node : tree_->GetProfilingManager()->GetSamplingNodes()) {
  36. RETURN_IF_NOT_OK(node.second->Sample());
  37. std::this_thread::sleep_for(std::chrono::milliseconds(sampling_interval_));
  38. }
  39. }
  40. // Output all profiling data upon request.
  41. tree_->GetProfilingManager()->SaveProfilingData();
  42. return Status::OK();
  43. }
  44. } // namespace dataset
  45. } // namespace mindspore