Improve ProfileSaver to cache data and do minimal I/O
This CLs introducing caching to further optimize the I/O performed by
the ProfileSaver. The cache stats are also recorded.
Resolved classes are captured and cached after 2 seconds but written
later during application lifetime.
Methods are also cached and the write got smarter to avoid
reading/writing them if it's not needed.
On non scientific experiments the size of the cache reaches just a few
hundreds uint16_t values kept in set, so its impact is minimal.
In terms of how much data we write. In the same non scientific
experiments this reduces the total bytes written by at least 2-3x. In
the first few minutes of after the boot gmscore writes ~3KB (down from
9kb) and quicksearchlauncher writes ~20KB (down from 40KB).
Bug: 27600652
(cherry picked from commit 85f7bf3bbfa17d65ff77e3e826b5f7aff45838a9)
Change-Id: I6ecb04ce81b281d1c1538060dbbaeeeb08906775
diff --git a/runtime/jit/offline_profiling_info.h b/runtime/jit/offline_profiling_info.h
index fb07f8c..2c819f1 100644
--- a/runtime/jit/offline_profiling_info.h
+++ b/runtime/jit/offline_profiling_info.h
@@ -49,14 +49,23 @@
const std::set<DexCacheResolvedClasses>& resolved_classes,
uint64_t* bytes_written = nullptr);
+ // Add the given methods and classes to the current profile object.
+ bool AddMethodsAndClasses(const std::vector<ArtMethod*>& methods,
+ const std::set<DexCacheResolvedClasses>& resolved_classes);
// Loads profile information from the given file descriptor.
bool Load(int fd);
- // Loads the data from another ProfileCompilationInfo object.
- bool Load(const ProfileCompilationInfo& info);
+ // Merge the data from another ProfileCompilationInfo into the current object.
+ bool MergeWith(const ProfileCompilationInfo& info);
// Saves the profile data to the given file descriptor.
bool Save(int fd);
+ // Loads and merges profile information from the given file into the current
+ // object and tries to save it back to disk.
+ bool MergeAndSave(const std::string& filename, uint64_t* bytes_written);
+
// Returns the number of methods that were profiled.
uint32_t GetNumberOfMethods() const;
+ // Returns the number of resolved classes that were profiled.
+ uint32_t GetNumberOfResolvedClasses() const;
// Returns true if the method reference is present in the profiling info.
bool ContainsMethod(const MethodReference& method_ref) const;
@@ -71,8 +80,8 @@
std::string DumpInfo(const std::vector<const DexFile*>* dex_files,
bool print_full_dex_location = true) const;
- // For testing purposes.
bool Equals(const ProfileCompilationInfo& other);
+
static std::string GetProfileDexFileKey(const std::string& dex_location);
// Returns the class descriptors for all of the classes in the profiles' class sets.
@@ -80,6 +89,9 @@
// profile info stuff to generate a map back to the dex location.
std::set<DexCacheResolvedClasses> GetResolvedClasses() const;
+ // Clears the resolved classes from the current object.
+ void ClearResolvedClasses();
+
private:
struct DexFileData {
explicit DexFileData(uint32_t location_checksum) : checksum(location_checksum) {}