blob: 1cd853ff3efea4fb42c4817bff6a2211b49fc686 [file] [log] [blame]
Fyodor Kupolovca348512018-01-10 18:05:53 -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
17package com.android.server;
18
19import android.os.Binder;
20import android.os.ServiceManager;
21import android.os.SystemProperties;
22import android.util.Slog;
23
24import com.android.internal.os.BinderCallsStats;
25
26import java.io.FileDescriptor;
27import java.io.PrintWriter;
28
29public class BinderCallsStatsService extends Binder {
30
31 private static final String TAG = "BinderCallsStatsService";
32
Fyodor Kupolov3f3af612018-04-18 17:26:43 -070033 private static final String PERSIST_SYS_BINDER_CALLS_DETAILED_TRACKING
34 = "persist.sys.binder_calls_detailed_tracking";
Fyodor Kupolovca348512018-01-10 18:05:53 -080035
36 public static void start() {
37 BinderCallsStatsService service = new BinderCallsStatsService();
38 ServiceManager.addService("binder_calls_stats", service);
Fyodor Kupolov3f3af612018-04-18 17:26:43 -070039 boolean detailedTrackingEnabled = SystemProperties.getBoolean(
40 PERSIST_SYS_BINDER_CALLS_DETAILED_TRACKING, false);
Fyodor Kupolovca348512018-01-10 18:05:53 -080041
Fyodor Kupolov3f3af612018-04-18 17:26:43 -070042 if (detailedTrackingEnabled) {
Fyodor Kupolovca348512018-01-10 18:05:53 -080043 Slog.i(TAG, "Enabled CPU usage tracking for binder calls. Controlled by "
Fyodor Kupolov3f3af612018-04-18 17:26:43 -070044 + PERSIST_SYS_BINDER_CALLS_DETAILED_TRACKING
45 + " or via dumpsys binder_calls_stats --enable-detailed-tracking");
46 BinderCallsStats.getInstance().setDetailedTracking(true);
Fyodor Kupolovca348512018-01-10 18:05:53 -080047 }
48 }
49
Fyodor Kupolov3f3af612018-04-18 17:26:43 -070050 public static void reset() {
51 Slog.i(TAG, "Resetting stats");
52 BinderCallsStats.getInstance().reset();
53 }
54
Fyodor Kupolovca348512018-01-10 18:05:53 -080055 @Override
56 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Fyodor Kupolov3f3af612018-04-18 17:26:43 -070057 if (args != null) {
58 for (final String arg : args) {
Fyodor Kupolov32a71122018-04-25 10:41:01 -070059 if ("-a".equals(arg)) {
60 // We currently dump all information by default
61 continue;
62 } else if ("--reset".equals(arg)) {
Fyodor Kupolov3f3af612018-04-18 17:26:43 -070063 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 Kupolov3f3af612018-04-18 17:26:43 -070084 }
85 }
86 }
Fyodor Kupolovca348512018-01-10 18:05:53 -080087 BinderCallsStats.getInstance().dump(pw);
88 }
89}