blob: 2ed451610354d8ae8888fa30ff35c3fbca086749 [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
33 private static final String PERSIST_SYS_BINDER_CPU_STATS_TRACKING
34 = "persist.sys.binder_cpu_stats_tracking";
35
36 public static void start() {
37 BinderCallsStatsService service = new BinderCallsStatsService();
38 ServiceManager.addService("binder_calls_stats", service);
39 // TODO Enable by default on eng/userdebug builds
40 boolean trackingEnabledDefault = false;
41 boolean trackingEnabled = SystemProperties.getBoolean(PERSIST_SYS_BINDER_CPU_STATS_TRACKING,
42 trackingEnabledDefault);
43
44 if (trackingEnabled) {
45 Slog.i(TAG, "Enabled CPU usage tracking for binder calls. Controlled by "
46 + PERSIST_SYS_BINDER_CPU_STATS_TRACKING);
47 BinderCallsStats.getInstance().setTrackingEnabled(true);
48 }
49 }
50
51 @Override
52 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
53 BinderCallsStats.getInstance().dump(pw);
54 }
55}