diff options
| author | 2018-04-10 23:55:06 +0000 | |
|---|---|---|
| committer | 2018-04-10 23:55:06 +0000 | |
| commit | 3ed866222dbccfa85378373a1e48d9e18eb499df (patch) | |
| tree | 6b28fff46a7abe1809bf6a5f311745386a0d7282 | |
| parent | de9d071fc12361d554dde13f3faede0b6d1fb9ec (diff) | |
| parent | ca5c0869f0e32014c0cbf48e48886d5b06956c75 (diff) | |
Merge "Logd retry throttling." into pi-dev
| -rw-r--r-- | tools/stats_log_api_gen/main.cpp | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/tools/stats_log_api_gen/main.cpp b/tools/stats_log_api_gen/main.cpp index 057772ffe013..4146e02cdd34 100644 --- a/tools/stats_log_api_gen/main.cpp +++ b/tools/stats_log_api_gen/main.cpp @@ -101,6 +101,7 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms, fprintf(out, "// This file is autogenerated\n"); fprintf(out, "\n"); + fprintf(out, "#include <mutex>\n"); fprintf(out, "#include <chrono>\n"); fprintf(out, "#include <thread>\n"); fprintf(out, "#include <log/log_event_list.h>\n"); @@ -150,9 +151,7 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms, fprintf(out, "};\n"); fprintf(out, "\n"); - fprintf(out, - "static std::map<int, int> " - "getAtomUidField() {\n"); + fprintf(out, "static std::map<int, int> getAtomUidField() {\n"); fprintf(out, " std::map<int, int> uidField;\n"); for (set<AtomDecl>::const_iterator atom = atoms.decls.begin(); atom != atoms.decls.end(); atom++) { @@ -206,6 +205,11 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms, "AtomsInfo::kStateAtomsFieldOptions = " "getStateAtomFieldOptions();\n"); + + fprintf(out, "int64_t lastRetryTimestampNs = -1;\n"); + fprintf(out, "const int64_t kMinRetryIntervalNs = NS_PER_SEC * 60 * 20; // 20 minutes\n"); + fprintf(out, "static std::mutex mLogdRetryMutex;\n"); + // Print write methods fprintf(out, "\n"); for (set<vector<java_type_t>>::const_iterator signature = atoms.signatures.begin(); @@ -317,7 +321,7 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms, fprintf(out, "{\n"); fprintf(out, " int ret = 0;\n"); - fprintf(out, " for(int retry = 0; retry < 3; ++retry) {\n"); + fprintf(out, " for(int retry = 0; retry < 2; ++retry) {\n"); fprintf(out, " ret = try_stats_write(code"); argIndex = 1; @@ -340,8 +344,15 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms, } fprintf(out, ");\n"); fprintf(out, " if (ret >= 0) { return retry; }\n"); - fprintf(out, - " std::this_thread::sleep_for(std::chrono::milliseconds(10 + 10 * retry));\n"); + + + fprintf(out, " {\n"); + fprintf(out, " std::lock_guard<std::mutex> lock(mLogdRetryMutex);\n"); + fprintf(out, " if ((android::elapsedRealtimeNano() - lastRetryTimestampNs) <= " + "kMinRetryIntervalNs) break;\n"); + fprintf(out, " lastRetryTimestampNs = android::elapsedRealtimeNano();\n"); + fprintf(out, " }\n"); + fprintf(out, " std::this_thread::sleep_for(std::chrono::milliseconds(10));\n"); fprintf(out, " }\n"); fprintf(out, " return ret;\n"); fprintf(out, "}\n"); @@ -408,7 +419,7 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms, fprintf(out, "{\n"); fprintf(out, " int ret = 0;\n"); - fprintf(out, " for(int retry = 0; retry < 3; ++retry) {\n"); + fprintf(out, " for(int retry = 0; retry < 2; ++retry) {\n"); fprintf(out, " ret = try_stats_write_non_chained(code"); argIndex = 1; @@ -419,8 +430,15 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms, } fprintf(out, ");\n"); fprintf(out, " if (ret >= 0) { return retry; }\n"); - fprintf(out, - " std::this_thread::sleep_for(std::chrono::milliseconds(10 + 10 * retry));\n"); + + fprintf(out, " {\n"); + fprintf(out, " std::lock_guard<std::mutex> lock(mLogdRetryMutex);\n"); + fprintf(out, " if ((android::elapsedRealtimeNano() - lastRetryTimestampNs) <= " + "kMinRetryIntervalNs) break;\n"); + fprintf(out, " lastRetryTimestampNs = android::elapsedRealtimeNano();\n"); + fprintf(out, " }\n"); + + fprintf(out, " std::this_thread::sleep_for(std::chrono::milliseconds(10));\n"); fprintf(out, " }\n"); fprintf(out, " return ret;\n"); fprintf(out, "}\n"); |