From cf3829a69685b6e976c0e747467859190342a0eb Mon Sep 17 00:00:00 2001 From: Yao Chen Date: Tue, 5 Jun 2018 14:20:35 -0700 Subject: [PATCH] Disable statsd and make StatsLog no-op if ro.statsd.enable=false Bug: 79324611 Test: manually tested on marlin_svelte Change-Id: Ic7fbf86d7c295cb6b2f20e7f9a957d1ed74c42c0 --- cmds/statsd/statsd.rc | 3 +++ tools/stats_log_api_gen/Android.bp | 1 + tools/stats_log_api_gen/main.cpp | 12 +++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cmds/statsd/statsd.rc b/cmds/statsd/statsd.rc index f3492920940de..cbf2a8d5383d6 100644 --- a/cmds/statsd/statsd.rc +++ b/cmds/statsd/statsd.rc @@ -19,6 +19,9 @@ service statsd /system/bin/statsd group statsd log writepid /dev/cpuset/system-background/tasks +on property:ro.statsd.enable=false + stop statsd + on post-fs-data # Create directory for statsd mkdir /data/misc/stats-data/ 0770 statsd system diff --git a/tools/stats_log_api_gen/Android.bp b/tools/stats_log_api_gen/Android.bp index 280afadebc0f9..703a67b791be4 100644 --- a/tools/stats_log_api_gen/Android.bp +++ b/tools/stats_log_api_gen/Android.bp @@ -106,6 +106,7 @@ cc_library_shared { shared_libs: [ "liblog", "libutils", + "libcutils", ], static_libs: ["libstatssocket"], } diff --git a/tools/stats_log_api_gen/main.cpp b/tools/stats_log_api_gen/main.cpp index 638549d395b39..140653a490e1b 100644 --- a/tools/stats_log_api_gen/main.cpp +++ b/tools/stats_log_api_gen/main.cpp @@ -104,6 +104,7 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms, fprintf(out, "#include \n"); fprintf(out, "#include \n"); fprintf(out, "#include \n"); + fprintf(out, "#include \n"); fprintf(out, "#include \n"); fprintf(out, "#include \n"); fprintf(out, "#include \n"); @@ -114,6 +115,7 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms, fprintf(out, "namespace util {\n"); fprintf(out, "// the single event tag id for all stats logs\n"); fprintf(out, "const static int kStatsEventTag = 1937006964;\n"); + fprintf(out, "const static bool kStatsdEnabled = property_get_bool(\"ro.statsd.enable\", true);\n"); std::set kTruncatingAtomNames = {"mobile_radio_power_state_changed", "audio_state_changed", @@ -242,6 +244,7 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms, fprintf(out, "{\n"); argIndex = 1; + fprintf(out, " if (kStatsdEnabled) {\n"); fprintf(out, " stats_event_list event(kStatsEventTag);\n"); fprintf(out, " event << android::elapsedRealtimeNano();\n\n"); fprintf(out, " event << code;\n\n"); @@ -286,6 +289,9 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms, } fprintf(out, " return event.write(LOG_ID_STATS);\n"); + fprintf(out, " } else {\n"); + fprintf(out, " return 1;\n"); + fprintf(out, " }\n"); fprintf(out, "}\n"); fprintf(out, "\n"); } @@ -375,6 +381,7 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms, fprintf(out, "{\n"); argIndex = 1; + fprintf(out, " if (kStatsdEnabled) {\n"); fprintf(out, " stats_event_list event(kStatsEventTag);\n"); fprintf(out, " event << android::elapsedRealtimeNano();\n\n"); fprintf(out, " event << code;\n\n"); @@ -398,6 +405,9 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms, } fprintf(out, " return event.write(LOG_ID_STATS);\n"); + fprintf(out, " } else {\n"); + fprintf(out, " return 1;\n"); + fprintf(out, " }\n"); fprintf(out, "}\n"); fprintf(out, "\n"); } @@ -1193,4 +1203,4 @@ main(int argc, char const*const* argv) GOOGLE_PROTOBUF_VERIFY_VERSION; return android::stats_log_api_gen::run(argc, argv); -} \ No newline at end of file +}