Android-cuttlefish cvd tool
fetch_tracer.h
Go to the documentation of this file.
1//
2// Copyright (C) 2024 The Android Open Source Project
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#pragma once
17
18#include <memory>
19#include <mutex>
20#include <optional>
21#include <string>
22#include <utility>
23#include <vector>
24
25namespace cuttlefish {
26
27// FetchTracer allows tracking the performance of fetch operations.
28// For each independing fetch, like fetching the host packages, a new trace
29// should be created. Each trace is then split in phases, each of which tracks
30// duration and, optionally, download size. The FetchTracer class is thread
31// safe, the FetchTracer::Trace is not and each trace should only be used from a
32// single thread.
34 public:
35 struct TraceImpl;
36 class Trace {
37 public:
38 explicit Trace(TraceImpl&);
39
40 void CompletePhase(std::string phase_name,
41 std::optional<size_t> size = std::nullopt);
42
43 private:
45 };
46
47 Trace NewTrace(std::string name);
48
49 std::string ToStyledString() const;
50
51 private:
52 std::vector<std::pair<std::string, std::shared_ptr<TraceImpl>>> traces_;
53 std::mutex traces_mtx_;
54};
55
56} // namespace cuttlefish
Definition: fetch_tracer.h:36
void CompletePhase(std::string phase_name, std::optional< size_t > size=std::nullopt)
Definition: fetch_tracer.cpp:89
Trace(TraceImpl &)
Definition: fetch_tracer.cpp:87
TraceImpl & impl_
Definition: fetch_tracer.h:44
Definition: fetch_tracer.h:33
std::mutex traces_mtx_
Definition: fetch_tracer.h:53
Trace NewTrace(std::string name)
Definition: fetch_tracer.cpp:99
std::vector< std::pair< std::string, std::shared_ptr< TraceImpl > > > traces_
Definition: fetch_tracer.h:52
std::string ToStyledString() const
Definition: fetch_tracer.cpp:106
uint32_t size
Definition: io.h:2
Definition: alloc_utils.cpp:23
Definition: fetch_tracer.cpp:42