• 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  * 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 "minddata/dataset/util/rdr.h"
17 #include "minddata/dataset/util/log_adapter.h"
18 
19 namespace mindspore {
20 namespace dataset {
21 const int32_t kMdRdrRecordLimit = 10;
22 
ToString()23 std::string MDChannelInfo::ToString() {
24   std::ostringstream ss;
25   {
26     std::unique_lock<std::mutex> lock(mutex_);
27     ss << "preprocess_batch: " << preprocess_batch_ << "; ";
28     ss << "batch_queue: ";
29     for (uint32_t i = 0; i < batch_queue_.size(); i++) {
30       ss << batch_queue_.at(i);
31       if (i < batch_queue_.size() - 1) {
32         ss << ", ";
33       }
34     }
35 
36     ss << "; push_start_time: ";
37     for (uint32_t i = 0; i < push_start_time_.size(); i++) {
38       ss << push_start_time_.at(i);
39       if (i < push_start_time_.size() - 1) {
40         ss << ", ";
41       }
42     }
43 
44     ss << "; push_end_time: ";
45     for (uint32_t i = 0; i < push_end_time_.size(); i++) {
46       ss << push_end_time_.at(i);
47       if (i < push_end_time_.size() - 1) {
48         ss << ", ";
49       }
50     }
51     ss << ".";
52   }
53   return ss.str();
54 }
55 
RecordBatchQueue(int64_t batch_queue_size)56 Status MDChannelInfo::RecordBatchQueue(int64_t batch_queue_size) {
57   {
58     std::unique_lock<std::mutex> lock(mutex_);
59     if (batch_queue_.size() == kMdRdrRecordLimit) {
60       batch_queue_.pop_front();
61     }
62     batch_queue_.push_back(batch_queue_size);
63   }
64   return Status::OK();
65 }
66 
RecordPreprocessBatch(int64_t preprocess_batch)67 Status MDChannelInfo::RecordPreprocessBatch(int64_t preprocess_batch) {
68   {
69     std::unique_lock<std::mutex> lock(mutex_);
70     preprocess_batch_ = preprocess_batch;
71   }
72   return Status::OK();
73 }
74 
RecordPushStartTime()75 Status MDChannelInfo::RecordPushStartTime() {
76   {
77     std::unique_lock<std::mutex> lock(mutex_);
78     if (push_start_time_.size() == kMdRdrRecordLimit) {
79       push_start_time_.pop_front();
80     }
81     push_start_time_.push_back(GetTimeString());
82   }
83   return Status::OK();
84 }
85 
RecordPushEndTime()86 Status MDChannelInfo::RecordPushEndTime() {
87   {
88     std::unique_lock<std::mutex> lock(mutex_);
89     if (push_end_time_.size() == kMdRdrRecordLimit) {
90       push_end_time_.pop_front();
91     }
92     push_end_time_.push_back(GetTimeString());
93   }
94   return Status::OK();
95 }
96 }  // namespace dataset
97 }  // namespace mindspore
98