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 <stddef.h>
19
20#include <memory>
21#include <mutex>
22#include <optional>
23#include <string>
24#include <utility>
25#include <vector>
26
27namespace cuttlefish {
28
29// FetchTracer allows tracking the performance of fetch operations.
30// For each independing fetch, like fetching the host packages, a new trace
31// should be created. Each trace is then split in phases, each of which tracks
32// duration and, optionally, download size. The FetchTracer class is thread
33// safe, the FetchTracer::Trace is not and each trace should only be used from a
34// single thread.
36 public:
37 struct TraceImpl;
38 class Trace {
39 public:
40 explicit Trace(TraceImpl&);
41
42 void CompletePhase(std::string phase_name,
43 std::optional<size_t> size = std::nullopt);
44
45 private:
47 };
48
49 Trace NewTrace(std::string name);
50
51 std::string ToStyledString() const;
52 size_t TotalSizeBytes() const;
53
54 private:
55 std::vector<std::pair<std::string, std::shared_ptr<TraceImpl>>> traces_;
56 std::mutex traces_mtx_;
57};
58
59} // namespace cuttlefish
Definition: fetch_tracer.h:38
void CompletePhase(std::string phase_name, std::optional< size_t > size=std::nullopt)
Definition: fetch_tracer.cpp:105
Trace(TraceImpl &)
Definition: fetch_tracer.cpp:103
TraceImpl & impl_
Definition: fetch_tracer.h:46
Definition: fetch_tracer.h:35
std::mutex traces_mtx_
Definition: fetch_tracer.h:56
Trace NewTrace(std::string name)
Definition: fetch_tracer.cpp:116
std::vector< std::pair< std::string, std::shared_ptr< TraceImpl > > > traces_
Definition: fetch_tracer.h:55
size_t TotalSizeBytes() const
Definition: fetch_tracer.cpp:136
std::string ToStyledString() const
Definition: fetch_tracer.cpp:123
uint32_t size
Definition: io.h:2
char * name
Definition: libf2fs.c:1403
Definition: alloc_driver.h:20
Definition: fetch_tracer.cpp:44