Lines Matching refs:out

98 static int write_stats_log_cpp(FILE *out, const Atoms &atoms,
101 fprintf(out, "// This file is autogenerated\n");
102 fprintf(out, "\n");
104 fprintf(out, "#include <mutex>\n");
105 fprintf(out, "#include <chrono>\n");
106 fprintf(out, "#include <thread>\n");
107 fprintf(out, "#include <cutils/properties.h>\n");
108 fprintf(out, "#include <stats_event_list.h>\n");
109 fprintf(out, "#include <log/log.h>\n");
110 fprintf(out, "#include <statslog.h>\n");
111 fprintf(out, "#include <utils/SystemClock.h>\n");
112 fprintf(out, "\n");
114 fprintf(out, "namespace android {\n");
115 fprintf(out, "namespace util {\n");
116 fprintf(out, "// the single event tag id for all stats logs\n");
117 fprintf(out, "const static int kStatsEventTag = 1937006964;\n");
118 fprintf(out, "const static bool kStatsdEnabled = property_get_bool(\"ro.statsd.enable\", true);\n");
126 fprintf(out,
134 fprintf(out, " %s,\n", constant.c_str());
137 fprintf(out, "};\n");
138 fprintf(out, "\n");
140 fprintf(out,
148 fprintf(out, " %s,\n", constant.c_str());
153 fprintf(out, "};\n");
154 fprintf(out, "\n");
156 fprintf(out, "static std::map<int, int> getAtomUidField() {\n");
157 fprintf(out, " std::map<int, int> uidField;\n");
163 fprintf(out,
167 fprintf(out, " uidField[static_cast<int>(%s)] = %d;\n",
171 fprintf(out, " return uidField;\n");
172 fprintf(out, "};\n");
174 fprintf(out,
178 fprintf(out,
181 fprintf(out, " std::map<int, StateAtomFieldOptions> options;\n");
182 fprintf(out, " StateAtomFieldOptions opt;\n");
188 fprintf(out,
192 fprintf(out, " opt.primaryFields.clear();\n");
194 fprintf(out, " opt.primaryFields.push_back(%d);\n", field);
197 fprintf(out, " opt.exclusiveField = %d;\n", atom->exclusiveField);
198 fprintf(out, " options[static_cast<int>(%s)] = opt;\n",
202 fprintf(out, " return options;\n");
203 fprintf(out, " }\n");
205 fprintf(out,
211 fprintf(out, "int64_t lastRetryTimestampNs = -1;\n");
212 fprintf(out, "const int64_t kMinRetryIntervalNs = NS_PER_SEC * 60 * 20; // 20 minutes\n");
213 fprintf(out, "static std::mutex mLogdRetryMutex;\n");
216 fprintf(out, "\n");
221 fprintf(out, "int\n");
222 fprintf(out, "try_stats_write(int32_t code");
229 fprintf(out, ", const std::vector<%s>& %s",
233 fprintf(out, ", const %s* %s, size_t %s_length",
239 fprintf(out, ", %s arg%d", cpp_type_name(*arg), argIndex);
243 fprintf(out, ")\n");
245 fprintf(out, "{\n");
247 fprintf(out, " if (kStatsdEnabled) {\n");
248 fprintf(out, " stats_event_list event(kStatsEventTag);\n");
249 fprintf(out, " event << android::elapsedRealtimeNano();\n\n");
250 fprintf(out, " event << code;\n\n");
256 fprintf(out, " if (%s_length != %s.size()) {\n",
258 fprintf(out, " return -EINVAL;\n");
259 fprintf(out, " }\n");
262 fprintf(out, "\n event.begin();\n");
263 fprintf(out, " for (size_t i = 0; i < %s_length; ++i) {\n",
265 fprintf(out, " event.begin();\n");
268 fprintf(out, " if (%s[i] != NULL) {\n", chainField.name.c_str());
269 fprintf(out, " event << %s[i];\n", chainField.name.c_str());
270 fprintf(out, " } else {\n");
271 fprintf(out, " event << \"\";\n");
272 fprintf(out, " }\n");
274 fprintf(out, " event << %s[i];\n", chainField.name.c_str());
277 fprintf(out, " event.end();\n");
278 fprintf(out, " }\n");
279 fprintf(out, " event.end();\n\n");
282 fprintf(out, " if (arg%d == NULL) {\n", argIndex);
283 fprintf(out, " arg%d = \"\";\n", argIndex);
284 fprintf(out, " }\n");
286 fprintf(out, " event << arg%d;\n", argIndex);
291 fprintf(out, " return event.write(LOG_ID_STATS);\n");
292 fprintf(out, " } else {\n");
293 fprintf(out, " return 1;\n");
294 fprintf(out, " }\n");
295 fprintf(out, "}\n");
296 fprintf(out, "\n");
303 fprintf(out, "int \n");
304 fprintf(out, "stats_write(int32_t code");
311 fprintf(out, ", const std::vector<%s>& %s",
315 fprintf(out, ", const %s* %s, size_t %s_length",
321 fprintf(out, ", %s arg%d", cpp_type_name(*arg), argIndex);
325 fprintf(out, ")\n");
327 fprintf(out, "{\n");
328 fprintf(out, " int ret = 0;\n");
330 fprintf(out, " for(int retry = 0; retry < 2; ++retry) {\n");
331 fprintf(out, " ret = try_stats_write(code");
339 fprintf(out, ", %s",
342 fprintf(out, ", %s, %s_length",
347 fprintf(out, ", arg%d", argIndex);
351 fprintf(out, ");\n");
352 fprintf(out, " if (ret >= 0) { return retry; }\n");
355 fprintf(out, " {\n");
356 fprintf(out, " std::lock_guard<std::mutex> lock(mLogdRetryMutex);\n");
357 fprintf(out, " if ((android::elapsedRealtimeNano() - lastRetryTimestampNs) <= "
359 fprintf(out, " lastRetryTimestampNs = android::elapsedRealtimeNano();\n");
360 fprintf(out, " }\n");
361 fprintf(out, " std::this_thread::sleep_for(std::chrono::milliseconds(10));\n");
362 fprintf(out, " }\n");
363 fprintf(out, " return ret;\n");
364 fprintf(out, "}\n");
365 fprintf(out, "\n");
372 fprintf(out, "int\n");
373 fprintf(out, "try_stats_write_non_chained(int32_t code");
377 fprintf(out, ", %s arg%d", cpp_type_name(*arg), argIndex);
380 fprintf(out, ")\n");
382 fprintf(out, "{\n");
384 fprintf(out, " if (kStatsdEnabled) {\n");
385 fprintf(out, " stats_event_list event(kStatsEventTag);\n");
386 fprintf(out, " event << android::elapsedRealtimeNano();\n\n");
387 fprintf(out, " event << code;\n\n");
391 fprintf(out, " event.begin();\n\n");
392 fprintf(out, " event.begin();\n");
395 fprintf(out, " if (arg%d == NULL) {\n", argIndex);
396 fprintf(out, " arg%d = \"\";\n", argIndex);
397 fprintf(out, " }\n");
399 fprintf(out, " event << arg%d;\n", argIndex);
401 fprintf(out, " event.end();\n\n");
402 fprintf(out, " event.end();\n\n");
407 fprintf(out, " return event.write(LOG_ID_STATS);\n");
408 fprintf(out, " } else {\n");
409 fprintf(out, " return 1;\n");
410 fprintf(out, " }\n");
411 fprintf(out, "}\n");
412 fprintf(out, "\n");
419 fprintf(out, "int\n");
420 fprintf(out, "stats_write_non_chained(int32_t code");
424 fprintf(out, ", %s arg%d", cpp_type_name(*arg), argIndex);
427 fprintf(out, ")\n");
429 fprintf(out, "{\n");
431 fprintf(out, " int ret = 0;\n");
432 fprintf(out, " for(int retry = 0; retry < 2; ++retry) {\n");
433 fprintf(out, " ret = try_stats_write_non_chained(code");
438 fprintf(out, ", arg%d", argIndex);
441 fprintf(out, ");\n");
442 fprintf(out, " if (ret >= 0) { return retry; }\n");
444 fprintf(out, " {\n");
445 fprintf(out, " std::lock_guard<std::mutex> lock(mLogdRetryMutex);\n");
446 fprintf(out, " if ((android::elapsedRealtimeNano() - lastRetryTimestampNs) <= "
448 fprintf(out, " lastRetryTimestampNs = android::elapsedRealtimeNano();\n");
449 fprintf(out, " }\n");
451 fprintf(out, " std::this_thread::sleep_for(std::chrono::milliseconds(10));\n");
452 fprintf(out, " }\n");
453 fprintf(out, " return ret;\n");
454 fprintf(out, "}\n");
456 fprintf(out, "\n");
461 fprintf(out, "\n");
462 fprintf(out, "} // namespace util\n");
463 fprintf(out, "} // namespace android\n");
477 FILE* out, const string& method_name, const string& atom_code_name,
479 fprintf(out, " * Usage: %s(StatsLog.%s", method_name.c_str(), atom_code_name.c_str());
485 fprintf(out, ", const std::vector<%s>& %s",
489 fprintf(out, ", const %s* %s, size_t %s_length",
495 fprintf(out, ", %s %s", cpp_type_name(field->javaType), field->name.c_str());
498 fprintf(out, ");\n");
502 FILE* out, const string& method_name, const set<vector<java_type_t>>& signatures,
506 fprintf(out, "int %s(int32_t code ", method_name.c_str());
513 fprintf(out, ", const std::vector<%s>& %s",
516 fprintf(out, ", const %s* %s, size_t %s_length",
522 fprintf(out, ", %s arg%d", cpp_type_name(*arg), argIndex);
526 fprintf(out, ");\n");
532 write_stats_log_header(FILE* out, const Atoms& atoms, const AtomDecl &attributionDecl)
535 fprintf(out, "// This file is autogenerated\n");
536 fprintf(out, "\n");
537 fprintf(out, "#pragma once\n");
538 fprintf(out, "\n");
539 fprintf(out, "#include <stdint.h>\n");
540 fprintf(out, "#include <vector>\n");
541 fprintf(out, "#include <map>\n");
542 fprintf(out, "#include <set>\n");
543 fprintf(out, "\n");
545 fprintf(out, "namespace android {\n");
546 fprintf(out, "namespace util {\n");
547 fprintf(out, "\n");
548 fprintf(out, "/*\n");
549 fprintf(out, " * API For logging statistics events.\n");
550 fprintf(out, " */\n");
551 fprintf(out, "\n");
552 fprintf(out, "/**\n");
553 fprintf(out, " * Constants for atom codes.\n");
554 fprintf(out, " */\n");
555 fprintf(out, "enum {\n");
565 fprintf(out, "\n");
566 fprintf(out, " /**\n");
567 fprintf(out, " * %s %s\n", atom->message.c_str(), atom->name.c_str());
568 write_cpp_usage(out, "stats_write", constant, *atom, attributionDecl);
572 write_cpp_usage(out, "stats_write_non_chained", constant, *non_chained_decl->second,
575 fprintf(out, " */\n");
577 fprintf(out, " %s = %d%s\n", constant.c_str(), atom->code, comma);
583 fprintf(out, "\n");
584 fprintf(out, "};\n");
585 fprintf(out, "\n");
587 fprintf(out, "struct StateAtomFieldOptions {\n");
588 fprintf(out, " std::vector<int> primaryFields;\n");
589 fprintf(out, " int exclusiveField;\n");
590 fprintf(out, "};\n");
591 fprintf(out, "\n");
593 fprintf(out, "struct AtomsInfo {\n");
594 fprintf(out,
597 fprintf(out, " const static std::map<int, int> kAtomsWithUidField;\n");
598 fprintf(out,
600 fprintf(out,
603 fprintf(out, "};\n");
605 fprintf(out, "const static int kMaxPushedAtomId = %d;\n\n",
609 fprintf(out, "//\n");
610 fprintf(out, "// Write methods\n");
611 fprintf(out, "//\n");
612 write_cpp_method_header(out, "stats_write", atoms.signatures, attributionDecl);
614 fprintf(out, "//\n");
615 fprintf(out, "// Write flattened methods\n");
616 fprintf(out, "//\n");
617 write_cpp_method_header(out, "stats_write_non_chained", atoms.non_chained_signatures,
620 fprintf(out, "\n");
621 fprintf(out, "} // namespace util\n");
622 fprintf(out, "} // namespace android\n");
628 FILE* out, const string& method_name, const string& atom_code_name,
630 fprintf(out, " * Usage: StatsLog.%s(StatsLog.%s",
636 fprintf(out, ", %s[] %s",
640 fprintf(out, ", %s %s", java_type_name(field->javaType), field->name.c_str());
643 fprintf(out, ");\n");
647 FILE* out, const string& method_name, const set<vector<java_type_t>>& signatures,
651 fprintf(out, " public static native int %s(int code", method_name.c_str());
657 fprintf(out, ", %s[] %s",
661 fprintf(out, ", %s arg%d", java_type_name(*arg), argIndex);
665 fprintf(out, ");\n");
671 write_stats_log_java(FILE* out, const Atoms& atoms, const AtomDecl &attributionDecl)
674 fprintf(out, "// This file is autogenerated\n");
675 fprintf(out, "\n");
676 fprintf(out, "package android.util;\n");
677 fprintf(out, "\n");
678 fprintf(out, "\n");
679 fprintf(out, "/**\n");
680 fprintf(out, " * API For logging statistics events.\n");
681 fprintf(out, " * @hide\n");
682 fprintf(out, " */\n");
683 fprintf(out, "public class StatsLogInternal {\n");
684 fprintf(out, " // Constants for atom codes.\n");
693 fprintf(out, "\n");
694 fprintf(out, " /**\n");
695 fprintf(out, " * %s %s\n", atom->message.c_str(), atom->name.c_str());
696 write_java_usage(out, "write", constant, *atom, attributionDecl);
699 write_java_usage(out, "write_non_chained", constant, *non_chained_decl->second,
702 fprintf(out, " */\n");
703 fprintf(out, " public static final int %s = %d;\n", constant.c_str(), atom->code);
705 fprintf(out, "\n");
708 fprintf(out, " // Constants for enum values.\n\n");
714 fprintf(out, " // Values for %s.%s\n", atom->message.c_str(),
718 fprintf(out, " public static final int %s__%s__%s = %d;\n",
724 fprintf(out, "\n");
730 fprintf(out, " // Write methods\n");
731 write_java_method(out, "write", atoms.signatures, attributionDecl);
732 write_java_method(out, "write_non_chained", atoms.non_chained_signatures, attributionDecl);
734 fprintf(out, "}\n");
853 write_stats_log_jni(FILE* out, const string& java_method_name, const string& cpp_method_name,
861 fprintf(out, "static int\n");
862 fprintf(out, "%s(JNIEnv* env, jobject clazz UNUSED, jint code",
869 fprintf(out, ", %s %s", jni_array_type_name(chainField.javaType),
873 fprintf(out, ", %s arg%d", jni_type_name(*arg), argIndex);
877 fprintf(out, ")\n");
879 fprintf(out, "{\n");
888 fprintf(out, " const char* str%d;\n", argIndex);
889 fprintf(out, " if (arg%d != NULL) {\n", argIndex);
890 fprintf(out, " str%d = env->GetStringUTFChars(arg%d, NULL);\n",
892 fprintf(out, " } else {\n");
893 fprintf(out, " str%d = NULL;\n", argIndex);
894 fprintf(out, " }\n");
898 fprintf(out, " size_t %s_length = env->GetArrayLength(%s);\n",
901 fprintf(out, " if (%s_length != %s_length) {\n",
904 fprintf(out, " return -EINVAL;\n");
905 fprintf(out, " }\n");
908 fprintf(out, " jint* %s_array = env->GetIntArrayElements(%s, NULL);\n",
911 fprintf(out, " std::vector<%s> %s_vec;\n",
913 fprintf(out, " std::vector<ScopedUtfChars*> scoped_%s_vec;\n",
915 fprintf(out, " for (size_t i = 0; i < %s_length; ++i) {\n",
917 fprintf(out, " jstring jstr = "
920 fprintf(out, " if (jstr == NULL) {\n");
921 fprintf(out, " %s_vec.push_back(NULL);\n",
923 fprintf(out, " } else {\n");
924 fprintf(out, " ScopedUtfChars* scoped_%s = "
927 fprintf(out, " %s_vec.push_back(scoped_%s->c_str());\n",
929 fprintf(out, " scoped_%s_vec.push_back(scoped_%s);\n",
931 fprintf(out, " }\n");
932 fprintf(out, " }\n");
934 fprintf(out, "\n");
942 fprintf(out, " (void)env;\n");
947 fprintf(out, " int ret = android::util::%s(code", cpp_method_name.c_str());
953 fprintf(out, ", (const %s*)%s_array, %s_length",
957 fprintf(out, ", %s_vec", chainField.name.c_str());
962 fprintf(out, ", (%s)%s%d", cpp_type_name(*arg), argName, argIndex);
966 fprintf(out, ");\n");
967 fprintf(out, "\n");
974 fprintf(out, " if (str%d != NULL) {\n", argIndex);
975 fprintf(out, " env->ReleaseStringUTFChars(arg%d, str%d);\n",
977 fprintf(out, " }\n");
981 fprintf(out, " env->ReleaseIntArrayElements(%s, %s_array, 0);\n",
984 fprintf(out, " for (size_t i = 0; i < scoped_%s_vec.size(); ++i) {\n",
986 fprintf(out, " delete scoped_%s_vec[i];\n", chainField.name.c_str());
987 fprintf(out, " }\n");
993 fprintf(out, " return ret;\n");
995 fprintf(out, "}\n");
996 fprintf(out, "\n");
1003 void write_jni_registration(FILE* out, const string& java_method_name,
1007 fprintf(out, " { \"%s\", \"%s\", (void*)%s },\n",
1015 write_stats_log_jni(FILE* out, const Atoms& atoms, const AtomDecl &attributionDecl)
1018 fprintf(out, "// This file is autogenerated\n");
1019 fprintf(out, "\n");
1021 fprintf(out, "#include <statslog.h>\n");
1022 fprintf(out, "\n");
1023 fprintf(out, "#include <nativehelper/JNIHelp.h>\n");
1024 fprintf(out, "#include <nativehelper/ScopedUtfChars.h>\n");
1025 fprintf(out, "#include <utils/Vector.h>\n");
1026 fprintf(out, "#include \"core_jni_helpers.h\"\n");
1027 fprintf(out, "#include \"jni.h\"\n");
1028 fprintf(out, "\n");
1029 fprintf(out, "#define UNUSED __attribute__((__unused__))\n");
1030 fprintf(out, "\n");
1032 fprintf(out, "namespace android {\n");
1033 fprintf(out, "\n");
1035 write_stats_log_jni(out, "write", "stats_write", atoms.signatures, attributionDecl);
1036 write_stats_log_jni(out, "write_non_chained", "stats_write_non_chained",
1040 fprintf(out, "/*\n");
1041 fprintf(out, " * JNI registration.\n");
1042 fprintf(out, " */\n");
1043 fprintf(out, "static const JNINativeMethod gRegisterMethods[] = {\n");
1044 write_jni_registration(out, "write", atoms.signatures, attributionDecl);
1045 write_jni_registration(out, "write_non_chained", atoms.non_chained_signatures, attributionDecl);
1046 fprintf(out, "};\n");
1047 fprintf(out, "\n");
1050 fprintf(out, "int register_android_util_StatsLog(JNIEnv* env) {\n");
1051 fprintf(out, " return RegisterMethodsOrDie(\n");
1052 fprintf(out, " env,\n");
1053 fprintf(out, " \"android/util/StatsLog\",\n");
1054 fprintf(out, " gRegisterMethods, NELEM(gRegisterMethods));\n");
1055 fprintf(out, "}\n");
1057 fprintf(out, "\n");
1058 fprintf(out, "} // namespace android\n");
1145 FILE* out = fopen(cppFilename.c_str(), "w");
1146 if (out == NULL) {
1151 out, atoms, attributionDecl);
1152 fclose(out);
1157 FILE* out = fopen(headerFilename.c_str(), "w");
1158 if (out == NULL) {
1163 out, atoms, attributionDecl);
1164 fclose(out);
1169 FILE* out = fopen(javaFilename.c_str(), "w");
1170 if (out == NULL) {
1175 out, atoms, attributionDecl);
1176 fclose(out);
1181 FILE* out = fopen(jniFilename.c_str(), "w");
1182 if (out == NULL) {
1187 out, atoms, attributionDecl);
1188 fclose(out);