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
17 #include <algorithm>
18 #include "runtime/device/ascend/profiling/reporter/desc_reporter.h"
19 #include "runtime/device/ascend/profiling/profiling_manager.h"
20 #include "utils/log_adapter.h"
21
22 namespace {
23 constexpr size_t kReportMaxLen = 1024;
24 }
25 namespace mindspore {
26 namespace device {
27 namespace ascend {
28 DescReporter::~DescReporter() = default;
29
ReportByLine(const std::string & data,const std::string & file_name) const30 void DescReporter::ReportByLine(const std::string &data, const std::string &file_name) const {
31 auto tot_size = data.size();
32 size_t cur_size = 0;
33 while (cur_size < tot_size) {
34 size_t remain_size = tot_size - cur_size;
35 size_t report_size = std::min(remain_size, kReportMaxLen);
36
37 ReporterData report_data{};
38 report_data.deviceId = device_id_;
39 report_data.dataLen = report_size;
40 report_data.data = (unsigned char *)data.c_str() + cur_size;
41 auto ret = memcpy_s(report_data.tag, MSPROF_ENGINE_MAX_TAG_LEN + 1, file_name.c_str(), file_name.length());
42 if (ret != 0) {
43 MS_LOG(EXCEPTION) << "Memcpy_s report data tag failed";
44 }
45 auto report_ret = ProfilingManager::GetInstance().CallMsprofReport(NOT_NULL(&report_data));
46 if (report_ret != 0) {
47 MS_LOG(EXCEPTION) << "Report data failed";
48 }
49 if (report_size == 0) {
50 MS_LOG(WARNING) << "Report_size is 0";
51 break;
52 }
53 cur_size += report_size;
54 }
55 }
56
ReportAllLine()57 void DescReporter::ReportAllLine() {
58 for (const auto &desc : prof_desc_list_) {
59 MS_EXCEPTION_IF_NULL(desc);
60 auto data = desc->ToString();
61 ReportByLine(data, file_name_);
62 }
63 }
64 } // namespace ascend
65 } // namespace device
66 } // namespace mindspore
67