blob: 0d89b7da619de4d6c1903abf9bc61ec029ac5ba6 [file] [log] [blame]
Hector Dearman86cfbe12018-03-22 11:58:42 +00001/*
2 * Copyright (C) 2018 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
17#ifndef SRC_PERFETTO_CMD_RATE_LIMITER_H_
18#define SRC_PERFETTO_CMD_RATE_LIMITER_H_
19
20#include "perfetto/base/time.h"
21#include "src/perfetto_cmd/perfetto_cmd_state.pb.h"
22
23namespace perfetto {
24
25class RateLimiter {
26 public:
27 struct Args {
28 bool is_dropbox = false;
29 bool ignore_guardrails = false;
30 base::TimeSeconds current_time = base::TimeSeconds(0);
Lalit Maganti41844ed2018-05-23 14:41:43 +010031 uint64_t max_upload_bytes_override = 0;
Hector Dearman86cfbe12018-03-22 11:58:42 +000032 };
33
34 RateLimiter();
35 virtual ~RateLimiter();
36
37 bool ShouldTrace(const Args& args);
38 bool OnTraceDone(const Args& args, bool success, size_t bytes);
39
40 bool ClearState();
41
42 // virtual for testing.
43 virtual bool LoadState(PerfettoCmdState* state);
44
45 // virtual for testing.
46 virtual bool SaveState(const PerfettoCmdState& state);
47
48 bool StateFileExists();
49 virtual std::string GetStateFilePath() const;
50
51 private:
52 PerfettoCmdState state_{};
53};
54
55} // namespace perfetto
56
57#endif // SRC_PERFETTO_CMD_RATE_LIMITER_H_