| 145 | friend class SamplerCell; |
| 146 | |
| 147 | Sampler(const MetricDef<MetricKind::kCumulative, HistogramProto, NumLabels>& |
| 148 | metric_def, |
| 149 | std::unique_ptr<Buckets> buckets) |
| 150 | : metric_def_(metric_def), |
| 151 | buckets_(std::move(buckets)), |
| 152 | registration_handle_(CollectionRegistry::Default()->Register( |
| 153 | &metric_def_, [&](MetricCollectorGetter getter) { |
| 154 | auto metric_collector = getter.Get(&metric_def_); |
| 155 | |
| 156 | mutex_lock l(mu_); |
| 157 | for (const auto& cell : cells_) { |
| 158 | metric_collector.CollectValue(cell.first, cell.second.value()); |
| 159 | } |
| 160 | })) { |
| 161 | if (registration_handle_) { |
| 162 | status_ = Status::OK(); |
| 163 | } else { |
| 164 | status_ = Status(tensorflow::error::Code::ALREADY_EXISTS, |
| 165 | "Another metric with the same name already exists."); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | mutable mutex mu_; |
| 170 | |