|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +#pragma once |
| 19 | +#include "common/status.h" |
| 20 | +#include "io/fs/file_reader.h" |
| 21 | +#include "util/runtime_profile.h" |
| 22 | + |
| 23 | +namespace doris { |
| 24 | + |
| 25 | +namespace io { |
| 26 | + |
| 27 | +class TracingFileReader : public FileReader { |
| 28 | +public: |
| 29 | + TracingFileReader(doris::io::FileReaderSPtr inner, FileReaderStats* stats) |
| 30 | + : _inner(std::move(inner)), _stats(stats) {} |
| 31 | + |
| 32 | + Status read_at_impl(size_t offset, Slice result, size_t* bytes_read, |
| 33 | + const IOContext* io_ctx) override { |
| 34 | + SCOPED_RAW_TIMER(&_stats->read_time_ns); |
| 35 | + Status st = _inner->read_at(offset, result, bytes_read, io_ctx); |
| 36 | + _stats->read_calls++; |
| 37 | + _stats->read_bytes += *bytes_read; |
| 38 | + return st; |
| 39 | + } |
| 40 | + |
| 41 | + Status close() override { return _inner->close(); } |
| 42 | + const doris::io::Path& path() const override { return _inner->path(); } |
| 43 | + size_t size() const override { return _inner->size(); } |
| 44 | + bool closed() const override { return _inner->closed(); } |
| 45 | + const std::string& get_data_dir_path() override { return _inner->get_data_dir_path(); } |
| 46 | + |
| 47 | + void _collect_profile_at_runtime() override { return _inner->collect_profile_at_runtime(); } |
| 48 | + void _collect_profile_before_close() override { return _inner->collect_profile_before_close(); } |
| 49 | + |
| 50 | + FileReaderStats* stats() const { return _stats; } |
| 51 | + |
| 52 | +private: |
| 53 | + doris::io::FileReaderSPtr _inner; |
| 54 | + FileReaderStats* _stats; |
| 55 | +}; |
| 56 | + |
| 57 | +} // namespace io |
| 58 | +} // namespace doris |
0 commit comments