Fyodor Kupolov | ca34851 | 2018-01-10 18:05:53 -0800 | [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 | package com.android.server; |
| 18 | |
| 19 | import android.os.Binder; |
| 20 | import android.os.ServiceManager; |
| 21 | import android.os.SystemProperties; |
| 22 | import android.util.Slog; |
| 23 | |
| 24 | import com.android.internal.os.BinderCallsStats; |
| 25 | |
| 26 | import java.io.FileDescriptor; |
| 27 | import java.io.PrintWriter; |
| 28 | |
| 29 | public class BinderCallsStatsService extends Binder { |
| 30 | |
| 31 | private static final String TAG = "BinderCallsStatsService"; |
| 32 | |
Fyodor Kupolov | 3f3af61 | 2018-04-18 17:26:43 -0700 | [diff] [blame] | 33 | private static final String PERSIST_SYS_BINDER_CALLS_DETAILED_TRACKING |
| 34 | = "persist.sys.binder_calls_detailed_tracking"; |
Fyodor Kupolov | ca34851 | 2018-01-10 18:05:53 -0800 | [diff] [blame] | 35 | |
| 36 | public static void start() { |
| 37 | BinderCallsStatsService service = new BinderCallsStatsService(); |
| 38 | ServiceManager.addService("binder_calls_stats", service); |
Fyodor Kupolov | 3f3af61 | 2018-04-18 17:26:43 -0700 | [diff] [blame] | 39 | boolean detailedTrackingEnabled = SystemProperties.getBoolean( |
| 40 | PERSIST_SYS_BINDER_CALLS_DETAILED_TRACKING, false); |
Fyodor Kupolov | ca34851 | 2018-01-10 18:05:53 -0800 | [diff] [blame] | 41 | |
Fyodor Kupolov | 3f3af61 | 2018-04-18 17:26:43 -0700 | [diff] [blame] | 42 | if (detailedTrackingEnabled) { |
Fyodor Kupolov | ca34851 | 2018-01-10 18:05:53 -0800 | [diff] [blame] | 43 | Slog.i(TAG, "Enabled CPU usage tracking for binder calls. Controlled by " |
Fyodor Kupolov | 3f3af61 | 2018-04-18 17:26:43 -0700 | [diff] [blame] | 44 | + PERSIST_SYS_BINDER_CALLS_DETAILED_TRACKING |
| 45 | + " or via dumpsys binder_calls_stats --enable-detailed-tracking"); |
| 46 | BinderCallsStats.getInstance().setDetailedTracking(true); |
Fyodor Kupolov | ca34851 | 2018-01-10 18:05:53 -0800 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | |
Fyodor Kupolov | 3f3af61 | 2018-04-18 17:26:43 -0700 | [diff] [blame] | 50 | public static void reset() { |
| 51 | Slog.i(TAG, "Resetting stats"); |
| 52 | BinderCallsStats.getInstance().reset(); |
| 53 | } |
| 54 | |
Fyodor Kupolov | ca34851 | 2018-01-10 18:05:53 -0800 | [diff] [blame] | 55 | @Override |
| 56 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Fyodor Kupolov | 3f3af61 | 2018-04-18 17:26:43 -0700 | [diff] [blame] | 57 | if (args != null) { |
| 58 | for (final String arg : args) { |
Fyodor Kupolov | 32a7112 | 2018-04-25 10:41:01 -0700 | [diff] [blame] | 59 | if ("-a".equals(arg)) { |
| 60 | // We currently dump all information by default |
| 61 | continue; |
| 62 | } else if ("--reset".equals(arg)) { |
Fyodor Kupolov | 3f3af61 | 2018-04-18 17:26:43 -0700 | [diff] [blame] | 63 | reset(); |
| 64 | pw.println("binder_calls_stats reset."); |
| 65 | return; |
| 66 | } else if ("--enable-detailed-tracking".equals(arg)) { |
| 67 | SystemProperties.set(PERSIST_SYS_BINDER_CALLS_DETAILED_TRACKING, "1"); |
| 68 | BinderCallsStats.getInstance().setDetailedTracking(true); |
| 69 | pw.println("Detailed tracking enabled"); |
| 70 | return; |
| 71 | } else if ("--disable-detailed-tracking".equals(arg)) { |
| 72 | SystemProperties.set(PERSIST_SYS_BINDER_CALLS_DETAILED_TRACKING, ""); |
| 73 | BinderCallsStats.getInstance().setDetailedTracking(false); |
| 74 | pw.println("Detailed tracking disabled"); |
| 75 | return; |
| 76 | } else if ("-h".equals(arg)) { |
| 77 | pw.println("binder_calls_stats commands:"); |
| 78 | pw.println(" --reset: Reset stats"); |
| 79 | pw.println(" --enable-detailed-tracking: Enables detailed tracking"); |
| 80 | pw.println(" --disable-detailed-tracking: Disables detailed tracking"); |
| 81 | return; |
| 82 | } else { |
| 83 | pw.println("Unknown option: " + arg); |
Fyodor Kupolov | 3f3af61 | 2018-04-18 17:26:43 -0700 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | } |
Fyodor Kupolov | ca34851 | 2018-01-10 18:05:53 -0800 | [diff] [blame] | 87 | BinderCallsStats.getInstance().dump(pw); |
| 88 | } |
| 89 | } |