blob: 2411f97be5a1c2484fc4582bfba34f1833c719cc [file] [log] [blame]
Eric Laurent3528c932018-02-23 17:17:22 -08001/*
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
Ytai Ben-Tsvi1ea62c92021-11-10 14:38:27 -080017#pragma once
Eric Laurent3528c932018-02-23 17:17:22 -080018
Eric Laurent42896a02019-09-27 15:40:33 -070019#include <vector>
Eric Laurent3528c932018-02-23 17:17:22 -080020
Ytai Ben-Tsvi1ea62c92021-11-10 14:38:27 -080021#include <mediautils/TimerThread.h>
22
Eric Laurent3528c932018-02-23 17:17:22 -080023namespace android {
24
25// A class monitoring execution time for a code block (scoped variable) and causing an assert
26// if it exceeds a certain time
27
28class TimeCheck {
Ytai Ben-Tsvi1ea62c92021-11-10 14:38:27 -080029 public:
Eric Laurent3528c932018-02-23 17:17:22 -080030 // The default timeout is chosen to be less than system server watchdog timeout
31 static constexpr uint32_t kDefaultTimeOutMs = 5000;
32
Ytai Ben-Tsvi1ea62c92021-11-10 14:38:27 -080033 TimeCheck(const char* tag, uint32_t timeoutMs = kDefaultTimeOutMs);
34 ~TimeCheck();
35 static void setAudioHalPids(const std::vector<pid_t>& pids);
36 static std::vector<pid_t> getAudioHalPids();
Eric Laurent3528c932018-02-23 17:17:22 -080037
Ytai Ben-Tsvi1ea62c92021-11-10 14:38:27 -080038 private:
39 static TimerThread* getTimeCheckThread();
Eric Laurent42896a02019-09-27 15:40:33 -070040 static void accessAudioHalPids(std::vector<pid_t>* pids, bool update);
Ytai Ben-Tsvi1ea62c92021-11-10 14:38:27 -080041 static void crash(const char* tag);
Eric Laurent3528c932018-02-23 17:17:22 -080042
Ytai Ben-Tsvi1ea62c92021-11-10 14:38:27 -080043 const TimerThread::Handle mTimerHandle;
Eric Laurent3528c932018-02-23 17:17:22 -080044};
45
Ytai Ben-Tsvi1ea62c92021-11-10 14:38:27 -080046}; // namespace android