Loading tools/stats_log_api_gen/main.cpp +27 −9 Original line number Diff line number Diff line Loading @@ -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"); Loading Loading @@ -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++) { Loading Loading @@ -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(); Loading Loading @@ -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; Loading @@ -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"); Loading Loading @@ -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; Loading @@ -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"); Loading Loading
tools/stats_log_api_gen/main.cpp +27 −9 Original line number Diff line number Diff line Loading @@ -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"); Loading Loading @@ -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++) { Loading Loading @@ -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(); Loading Loading @@ -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; Loading @@ -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"); Loading Loading @@ -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; Loading @@ -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"); Loading