1 //
2 // Copyright (C) 2020 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 #include <android-base/strings.h>
17 #include <gflags/gflags.h>
18 #include <android-base/logging.h>
19 
20 #include "common/libs/utils/tee_logging.h"
21 #include "host/commands/metrics/metrics_defs.h"
22 #include "host/libs/config/cuttlefish_config.h"
23 
24 using cuttlefish::MetricsExitCodes;
25 
main(int argc,char ** argv)26 int main(int argc, char** argv) {
27   ::android::base::InitLogging(argv, android::base::StderrLogger);
28   google::ParseCommandLineFlags(&argc, &argv, true);
29 
30   auto config = cuttlefish::CuttlefishConfig::Get();
31 
32   CHECK(config) << "Could not open cuttlefish config";
33 
34   auto instance = config->ForDefaultInstance();
35   auto metrics_log_path = instance.PerInstancePath("metrics.log");
36 
37   if (config->run_as_daemon()) {
38     android::base::SetLogger(
39         cuttlefish::LogToFiles({metrics_log_path, instance.launcher_log_path()}));
40   } else {
41     android::base::SetLogger(
42         cuttlefish::LogToStderrAndFiles(
43             {metrics_log_path, instance.launcher_log_path()}));
44   }
45 
46   if (config->enable_metrics() != cuttlefish::CuttlefishConfig::kYes) {
47     LOG(ERROR) << "metrics not enabled, but metrics were launched.";
48     return cuttlefish::MetricsExitCodes::kInvalidHostConfiguration;
49   }
50 
51   while (true) {
52     // do nothing
53     sleep(std::numeric_limits<unsigned int>::max());
54   }
55   return cuttlefish::MetricsExitCodes::kMetricsError;
56 }
57