class ImgDiagTest : public CommonRuntimeTest { protected: void SetUp() override {
CommonRuntimeTest::SetUp();
// We loaded the runtime with an explicit image. Therefore the image space must exist.
std::vector<gc::space::ImageSpace*> image_spaces =
Runtime::Current()->GetHeap()->GetBootImageSpaces();
ASSERT_TRUE(!image_spaces.empty());
boot_image_location_ = image_spaces[0]->GetImageLocation();
}
void SetUpRuntimeOptions(RuntimeOptions* options) override { // Needs to live until CommonRuntimeTest::SetUp finishes, since we pass it a cstring.
runtime_args_image_ = android::base::StringPrintf("-Ximage:%s", GetCoreArtLocation().c_str());
options->push_back(std::make_pair(runtime_args_image_, nullptr));
}
// Path to the imgdiag(d?)[32|64] binary.
std::string GetImgDiagFilePath() {
std::string path = GetArtBinDir() + '/' + kImgDiagBinaryName; if (kIsDebugBuild) {
path += 'd';
}
std::string path32 = path + "32"; // If we have both a 32-bit and a 64-bit build, the 32-bit file will have a 32 suffix. if (OS::FileExists(path32.c_str()) && !Is64BitInstructionSet(kRuntimeISA)) { return path32; // Only a single build exists, so the filename never has an extra suffix.
} else { return path;
}
}
// Run imgdiag with a custom boot image location. bool Exec(pid_t image_diff_pid, const std::string& boot_image, std::string* error_msg) { // Invoke 'img_diag' against the current process. // This should succeed because we have a runtime and so it should // be able to map in the boot.art and do a diff for it.
std::string file_path = GetImgDiagFilePath();
EXPECT_TRUE(OS::FileExists(file_path.c_str())) << file_path << " should be a valid file path";
// Run imgdiag --image-diff-pid=$image_diff_pid and wait until it's done with a 0 exit code.
std::vector<std::string> exec_argv = {
file_path, "--image-diff-pid=" + std::to_string(image_diff_pid), "--zygote-diff-pid=" + std::to_string(image_diff_pid), "--runtime-arg",
GetClassPathOption("-Xbootclasspath:", GetLibCoreDexFileNames()), "--runtime-arg",
GetClassPathOption("-Xbootclasspath-locations:", GetLibCoreDexLocations()), "--boot-image=" + boot_image
}; if (::android::base::GetBoolProperty("dalvik.vm.allow_profile_code", false)) {
exec_argv.push_back("--allow-profile-code");
}
return ::art::Exec(exec_argv, error_msg);
}
// Run imgdiag with the default boot image location. bool ExecDefaultBootImage(pid_t image_diff_pid, std::string* error_msg) { return Exec(image_diff_pid, boot_image_location_, error_msg);
}
#ifdefined (ART_TARGET)
TEST_F(ImgDiagTest, ImageDiffPidSelf) { #else // Can't run this test on the host, it will fail when trying to open /proc/kpagestats // because it's root read-only.
TEST_F(ImgDiagTest, DISABLED_ImageDiffPidSelf) { #endif // Invoke 'img_diag' against the current process. // This should succeed because we have a runtime and so it should // be able to map in the boot.art and do a diff for it.
// Not allowed to read /proc/kpagestats on VM/SBC (in the same way as on host).
TEST_DISABLED_ON_VM();
TEST_DISABLED_ON_SBC();
// Run imgdiag --image-diff-pid=$(self pid) and wait until it's done with a 0 exit code.
std::string error_msg;
ASSERT_TRUE(ExecDefaultBootImage(getpid(), &error_msg)) << "Failed to execute -- because: "
<< error_msg;
}
TEST_F(ImgDiagTest, ImageDiffBadPid) { // Invoke 'img_diag' against a non-existing process. This should fail.
// Run imgdiag --image-diff-pid=some_bad_pid and wait until it's done with a 0 exit code.
std::string error_msg;
ASSERT_FALSE(ExecDefaultBootImage(kImgDiagGuaranteedBadPid,
&error_msg)) << "Incorrectly executed";
UNUSED(error_msg);
}
} // namespace art
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.