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 bool allow_user_build_tracing = false; 31 base::TimeSeconds current_time = base::TimeSeconds(0); 32 uint64_t max_upload_bytes_override = 0; 33 }; 34 35 RateLimiter(); 36 virtual ~RateLimiter(); 37 38 bool ShouldTrace(const Args& args); 39 bool OnTraceDone(const Args& args, bool success, uint64_t bytes); 40 41 bool ClearState(); 42 43 // virtual for testing. 44 virtual bool LoadState(PerfettoCmdState* state); 45 46 // virtual for testing. 47 virtual bool SaveState(const PerfettoCmdState& state); 48 49 bool StateFileExists(); 50 virtual std::string GetStateFilePath() const; 51 52 private: 53 PerfettoCmdState state_{}; 54 }; 55 56 } // namespace perfetto 57 58 #endif // SRC_PERFETTO_CMD_RATE_LIMITER_H_ 59