• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 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  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "profiler/device/ascend/ascend_profiling.h"
17 #include <string>
18 #include "pybind_api/api_register.h"
19 #include "utils/log_adapter.h"
20 #include "utils/utils.h"
21 
22 namespace mindspore {
23 namespace profiler {
24 namespace ascend {
25 std::shared_ptr<AscendProfiler> AscendProfiler::ascend_profiler_ = std::make_shared<AscendProfiler>();
26 
GetInstance()27 std::shared_ptr<AscendProfiler> &AscendProfiler::GetInstance() { return ascend_profiler_; }
28 
StepProfilingEnable(const bool enable_flag)29 void AscendProfiler::StepProfilingEnable(const bool enable_flag) {
30   MS_LOG(INFO) << "Start profiling";
31   enable_flag_ = enable_flag;
32 }
33 
Start(const std::string & profiling_options)34 void AscendProfiler::Start(const std::string &profiling_options) {
35   profiling_options_ = profiling_options;
36   StepProfilingEnable(true);
37 }
38 
Stop()39 void AscendProfiler::Stop() {
40   MS_LOG(INFO) << "Stop profiling";
41   StepProfilingEnable(false);
42 }
43 
__anond89ca1d80102(const py::module *m) 44 REGISTER_PYBIND_DEFINE(AscendProfiler_, ([](const py::module *m) {
45                          (void)py::class_<AscendProfiler, std::shared_ptr<AscendProfiler>>(*m, "AscendProfiler")
46                            .def_static("get_instance", &AscendProfiler::GetInstance, "AscendProfiler get_instance.")
47                            .def("start", &AscendProfiler::Start, py::arg("profiling_options"), "start")
48                            .def("stop", &AscendProfiler::Stop, "stop");
49                        }));
50 }  // namespace ascend
51 }  // namespace profiler
52 }  // namespace mindspore
53