Hector Dearman | 86cfbe1 | 2018-03-22 11:58:42 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 23 | namespace perfetto { |
| 24 | |
| 25 | class 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 Maganti | 41844ed | 2018-05-23 14:41:43 +0100 | [diff] [blame] | 31 | uint64_t max_upload_bytes_override = 0; |
Hector Dearman | 86cfbe1 | 2018-03-22 11:58:42 +0000 | [diff] [blame] | 32 | }; |
| 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_ |