summaryrefslogtreecommitdiffstats
path: root/libprofile
diff options
context:
space:
mode:
authorCalin Juravle <calin@google.com>2018-05-08 18:23:24 -0700
committerCalin Juravle <calin@google.com>2018-05-09 13:08:06 -0700
commitd5aeadeac0debd90d0a931c1d41bee6a2d32b209 (patch)
tree2d21d88d082bcd7c4be932a78d108b6fd62c8342 /libprofile
parent9926e4615d75cb6c9371e1766a14b0a80089ae18 (diff)
downloadart-d5aeadeac0debd90d0a931c1d41bee6a2d32b209.tar.gz
art-d5aeadeac0debd90d0a931c1d41bee6a2d32b209.tar.bz2
art-d5aeadeac0debd90d0a931c1d41bee6a2d32b209.zip
Clear the profile if we fail to add new methods or classes
We may fail to add new data in the profile if it contains outdated data (e.g. if the dex files we profiled were updated in the meantime). If this happens, clear the profile to ensure we don't keep around useless data. Test: m test-art-host, 595-profiling-saving Bug: 77839992 Bug: 79200824 Change-Id: I238d56ba4eeec96a3464e42f164d0e798f555ec4
Diffstat (limited to 'libprofile')
-rw-r--r--libprofile/profile/profile_compilation_info.cc12
-rw-r--r--libprofile/profile/profile_compilation_info.h3
-rw-r--r--libprofile/profile/profile_compilation_info_test.cc29
3 files changed, 41 insertions, 3 deletions
diff --git a/libprofile/profile/profile_compilation_info.cc b/libprofile/profile/profile_compilation_info.cc
index 0e0c3c5116..748e24e27c 100644
--- a/libprofile/profile/profile_compilation_info.cc
+++ b/libprofile/profile/profile_compilation_info.cc
@@ -96,9 +96,7 @@ ProfileCompilationInfo::ProfileCompilationInfo()
ProfileCompilationInfo::~ProfileCompilationInfo() {
VLOG(profiler) << Dumpable<MemStats>(allocator_.GetMemStats());
- for (DexFileData* data : info_) {
- delete data;
- }
+ ClearData();
}
void ProfileCompilationInfo::DexPcData::AddClass(uint16_t dex_profile_idx,
@@ -2106,4 +2104,12 @@ bool ProfileCompilationInfo::ProfileFilterFnAcceptAll(
return true;
}
+void ProfileCompilationInfo::ClearData() {
+ for (DexFileData* data : info_) {
+ delete data;
+ }
+ info_.clear();
+ profile_key_map_.clear();
+}
+
} // namespace art
diff --git a/libprofile/profile/profile_compilation_info.h b/libprofile/profile/profile_compilation_info.h
index 32c796c363..e28c5f17b6 100644
--- a/libprofile/profile/profile_compilation_info.h
+++ b/libprofile/profile/profile_compilation_info.h
@@ -445,6 +445,9 @@ class ProfileCompilationInfo {
// Checks if the profile is empty.
bool IsEmpty() const;
+ // Clears all the data from the profile.
+ void ClearData();
+
private:
enum ProfileLoadStatus {
kProfileLoadWouldOverwiteData,
diff --git a/libprofile/profile/profile_compilation_info_test.cc b/libprofile/profile/profile_compilation_info_test.cc
index b0f96492df..b3262a7a14 100644
--- a/libprofile/profile/profile_compilation_info_test.cc
+++ b/libprofile/profile/profile_compilation_info_test.cc
@@ -1339,4 +1339,33 @@ TEST_F(ProfileCompilationInfoTest, FilteredLoadingWithClasses) {
ASSERT_TRUE(loaded_info.Equals(expected_info));
}
+
+TEST_F(ProfileCompilationInfoTest, ClearData) {
+ ProfileCompilationInfo info;
+ for (uint16_t i = 0; i < 10; i++) {
+ ASSERT_TRUE(AddMethod("dex_location1", /* checksum */ 1, /* method_idx */ i, &info));
+ }
+ ASSERT_FALSE(IsEmpty(info));
+ info.ClearData();
+ ASSERT_TRUE(IsEmpty(info));
+}
+
+TEST_F(ProfileCompilationInfoTest, ClearDataAndSave) {
+ ProfileCompilationInfo info;
+ for (uint16_t i = 0; i < 10; i++) {
+ ASSERT_TRUE(AddMethod("dex_location1", /* checksum */ 1, /* method_idx */ i, &info));
+ }
+ info.ClearData();
+
+ ScratchFile profile;
+ ASSERT_TRUE(info.Save(GetFd(profile)));
+ ASSERT_EQ(0, profile.GetFile()->Flush());
+
+ // Check that we get back what we saved.
+ ProfileCompilationInfo loaded_info;
+ ASSERT_TRUE(profile.GetFile()->ResetOffset());
+ ASSERT_TRUE(loaded_info.Load(GetFd(profile)));
+ ASSERT_TRUE(loaded_info.Equals(info));
+}
+
} // namespace art