Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 1 | /* |
yro | 0feae94 | 2017-11-15 14:38:48 -0800 | [diff] [blame] | 2 | * Copyright (C) 2017 The Android Open Source Project |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 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 | |
Yao Chen | 49954cd | 2018-04-18 13:48:02 -0700 | [diff] [blame] | 17 | #define DEBUG false // STOPSHIP if true |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 18 | #include "Log.h" |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 19 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 20 | #include "StatsService.h" |
Yao Chen | 49954cd | 2018-04-18 13:48:02 -0700 | [diff] [blame] | 21 | #include "socket/StatsSocketListener.h" |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 22 | |
| 23 | #include <binder/IInterface.h> |
| 24 | #include <binder/IPCThreadState.h> |
| 25 | #include <binder/IServiceManager.h> |
| 26 | #include <binder/ProcessState.h> |
| 27 | #include <binder/Status.h> |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 28 | #include <utils/Looper.h> |
| 29 | #include <utils/StrongPointer.h> |
| 30 | |
George Burgess IV | ef8262c | 2018-04-23 09:32:41 -0700 | [diff] [blame] | 31 | #include <memory> |
| 32 | |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 33 | #include <stdio.h> |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 34 | #include <sys/stat.h> |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 35 | #include <sys/types.h> |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 36 | #include <unistd.h> |
| 37 | |
| 38 | using namespace android; |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 39 | using namespace android::os::statsd; |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 40 | |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 41 | /** |
| 42 | * Thread function data. |
| 43 | */ |
| 44 | struct log_reader_thread_data { |
| 45 | sp<StatsService> service; |
| 46 | }; |
| 47 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 48 | int main(int /*argc*/, char** /*argv*/) { |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 49 | // Set up the looper |
| 50 | sp<Looper> looper(Looper::prepare(0 /* opts */)); |
| 51 | |
| 52 | // Set up the binder |
| 53 | sp<ProcessState> ps(ProcessState::self()); |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 54 | ps->setThreadPoolMaxThreadCount(9); |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 55 | ps->startThreadPool(); |
| 56 | ps->giveThreadPoolName(); |
| 57 | IPCThreadState::self()->disableBackgroundScheduling(true); |
| 58 | |
| 59 | // Create the service |
| 60 | sp<StatsService> service = new StatsService(looper); |
| 61 | if (defaultServiceManager()->addService(String16("stats"), service) != 0) { |
| 62 | ALOGE("Failed to add service"); |
| 63 | return -1; |
| 64 | } |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 65 | service->sayHiToStatsCompanion(); |
| 66 | |
Yao Chen | 49954cd | 2018-04-18 13:48:02 -0700 | [diff] [blame] | 67 | service->Startup(); |
| 68 | |
| 69 | sp<StatsSocketListener> socketListener = new StatsSocketListener(service); |
| 70 | |
Yao Chen | 49954cd | 2018-04-18 13:48:02 -0700 | [diff] [blame] | 71 | ALOGI("using statsd socket"); |
| 72 | // Backlog and /proc/sys/net/unix/max_dgram_qlen set to large value |
| 73 | if (socketListener->startListener(600)) { |
| 74 | exit(1); |
| 75 | } |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 76 | |
| 77 | // Loop forever -- the reports run on this thread in a handler, and the |
| 78 | // binder calls remain responsive in their pool of one thread. |
| 79 | while (true) { |
| 80 | looper->pollAll(-1 /* timeoutMillis */); |
| 81 | } |
| 82 | ALOGW("statsd escaped from its loop."); |
| 83 | |
| 84 | return 1; |
| 85 | } |