summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJin Qian2017-07-17 17:06:11 -0500
committerJin Qian2017-07-17 17:51:30 -0500
commit8847c62579282cd67a80d7354ccf26064aaed4e5 (patch)
treea953c099cd73fb6aa8df4c804047e28a7c7eefc6 /storaged
parente6dfd45f001f72c4566620a8c9180f563991d93b (diff)
downloadplatform-system-core-8847c62579282cd67a80d7354ccf26064aaed4e5.tar.gz
platform-system-core-8847c62579282cd67a80d7354ccf26064aaed4e5.tar.xz
platform-system-core-8847c62579282cd67a80d7354ccf26064aaed4e5.zip
storaged: record userdata space utilization
Update disk space utilization together with diskstats since we will use free space size to co-relate disk performance. Bug: 63629306 Change-Id: I4e5694aaff3b71aa56db451f1bc92ccfb07e5086
Diffstat (limited to 'storaged')
-rw-r--r--storaged/include/storaged.h3
-rw-r--r--storaged/include/storaged_info.h37
-rw-r--r--storaged/main.cpp2
-rw-r--r--storaged/storaged.cpp7
-rw-r--r--storaged/storaged_info.cpp56
5 files changed, 75 insertions, 30 deletions
diff --git a/storaged/include/storaged.h b/storaged/include/storaged.h
index 514798bff..fa6840638 100644
--- a/storaged/include/storaged.h
+++ b/storaged/include/storaged.h
@@ -256,6 +256,7 @@ private:
256 uid_monitor mUidm; 256 uid_monitor mUidm;
257 time_t mStarttime; 257 time_t mStarttime;
258 sp<IBatteryPropertiesRegistrar> battery_properties; 258 sp<IBatteryPropertiesRegistrar> battery_properties;
259 std::unique_ptr<storage_info_t> storage_info;
259public: 260public:
260 storaged_t(void); 261 storaged_t(void);
261 ~storaged_t() {} 262 ~storaged_t() {}
@@ -285,6 +286,8 @@ public:
285 void init_battery_service(); 286 void init_battery_service();
286 virtual void batteryPropertiesChanged(struct BatteryProperties props); 287 virtual void batteryPropertiesChanged(struct BatteryProperties props);
287 void binderDied(const wp<IBinder>& who); 288 void binderDied(const wp<IBinder>& who);
289
290 void report_storage_info();
288}; 291};
289 292
290// Eventlog tag 293// Eventlog tag
diff --git a/storaged/include/storaged_info.h b/storaged/include/storaged_info.h
index 913c814ac..7d04c7a0d 100644
--- a/storaged/include/storaged_info.h
+++ b/storaged/include/storaged_info.h
@@ -27,39 +27,46 @@ using namespace std;
27class storage_info_t { 27class storage_info_t {
28protected: 28protected:
29 FRIEND_TEST(storaged_test, storage_info_t); 29 FRIEND_TEST(storaged_test, storage_info_t);
30 // emmc lifetime
30 uint16_t eol; // pre-eol (end of life) information 31 uint16_t eol; // pre-eol (end of life) information
31 uint16_t lifetime_a; // device life time estimation (type A) 32 uint16_t lifetime_a; // device life time estimation (type A)
32 uint16_t lifetime_b; // device life time estimation (type B) 33 uint16_t lifetime_b; // device life time estimation (type B)
33 string version; // version string 34 string version; // version string
35 // free space
36 const string userdata_path = "/data";
37 uint64_t userdata_total_kb;
38 uint64_t userdata_free_kb;
39
40 storage_info_t() : eol(0), lifetime_a(0), lifetime_b(0),
41 userdata_total_kb(0), userdata_free_kb(0) {}
34 void publish(); 42 void publish();
43 storage_info_t* s_info;
35public: 44public:
36 storage_info_t() : eol(0), lifetime_a(0), lifetime_b(0) {} 45 static storage_info_t* get_storage_info();
37 virtual ~storage_info_t() {} 46 virtual ~storage_info_t() {}
38 virtual bool report() = 0; 47 virtual void report() {};
48 void refresh();
39}; 49};
40 50
41class emmc_info_t : public storage_info_t { 51class emmc_info_t : public storage_info_t {
42private: 52private:
43 const string emmc_sysfs = "/sys/bus/mmc/devices/mmc0:0001/";
44 const string emmc_debugfs = "/d/mmc0/mmc0:0001/ext_csd";
45 const char* emmc_ver_str[9] = {
46 "4.0", "4.1", "4.2", "4.3", "Obsolete", "4.41", "4.5", "5.0", "5.1"
47 };
48public:
49 virtual ~emmc_info_t() {}
50 bool report();
51 bool report_sysfs(); 53 bool report_sysfs();
52 bool report_debugfs(); 54 bool report_debugfs();
55public:
56 static const string emmc_sysfs;
57 static const string emmc_debugfs;
58 static const char* emmc_ver_str[];
59
60 virtual ~emmc_info_t() {}
61 virtual void report();
53}; 62};
54 63
55class ufs_info_t : public storage_info_t { 64class ufs_info_t : public storage_info_t {
56private:
57 const string health_file = "/sys/devices/soc/624000.ufshc/health";
58public: 65public:
66 static const string health_file;
67
59 virtual ~ufs_info_t() {} 68 virtual ~ufs_info_t() {}
60 bool report(); 69 virtual void report();
61}; 70};
62 71
63void report_storage_health();
64
65#endif /* _STORAGED_INFO_H_ */ 72#endif /* _STORAGED_INFO_H_ */
diff --git a/storaged/main.cpp b/storaged/main.cpp
index 4d1e43014..6b82904d2 100644
--- a/storaged/main.cpp
+++ b/storaged/main.cpp
@@ -49,6 +49,7 @@ void* storaged_main(void* /* unused */) {
49 storaged = new storaged_t(); 49 storaged = new storaged_t();
50 50
51 storaged->init_battery_service(); 51 storaged->init_battery_service();
52 storaged->report_storage_info();
52 53
53 LOG_TO(SYSTEM, INFO) << "storaged: Start"; 54 LOG_TO(SYSTEM, INFO) << "storaged: Start";
54 55
@@ -113,7 +114,6 @@ int main(int argc, char** argv) {
113 } 114 }
114 115
115 if (flag_main_service) { // start main thread 116 if (flag_main_service) { // start main thread
116 report_storage_health();
117 // Start the main thread of storaged 117 // Start the main thread of storaged
118 pthread_t storaged_main_thread; 118 pthread_t storaged_main_thread;
119 errno = pthread_create(&storaged_main_thread, NULL, storaged_main, NULL); 119 errno = pthread_create(&storaged_main_thread, NULL, storaged_main, NULL);
diff --git a/storaged/storaged.cpp b/storaged/storaged.cpp
index 54d429cd8..06afea693 100644
--- a/storaged/storaged.cpp
+++ b/storaged/storaged.cpp
@@ -200,6 +200,10 @@ void storaged_t::binderDied(const wp<IBinder>& who) {
200 } 200 }
201} 201}
202 202
203void storaged_t::report_storage_info() {
204 storage_info->report();
205}
206
203/* storaged_t */ 207/* storaged_t */
204storaged_t::storaged_t(void) { 208storaged_t::storaged_t(void) {
205 if (access(MMC_DISK_STATS_PATH, R_OK) < 0 && access(SDA_DISK_STATS_PATH, R_OK) < 0) { 209 if (access(MMC_DISK_STATS_PATH, R_OK) < 0 && access(SDA_DISK_STATS_PATH, R_OK) < 0) {
@@ -222,6 +226,8 @@ storaged_t::storaged_t(void) {
222 mConfig.periodic_chores_interval_uid_io = 226 mConfig.periodic_chores_interval_uid_io =
223 property_get_int32("ro.storaged.uid_io.interval", DEFAULT_PERIODIC_CHORES_INTERVAL_UID_IO); 227 property_get_int32("ro.storaged.uid_io.interval", DEFAULT_PERIODIC_CHORES_INTERVAL_UID_IO);
224 228
229 storage_info.reset(storage_info_t::get_storage_info());
230
225 mStarttime = time(NULL); 231 mStarttime = time(NULL);
226} 232}
227 233
@@ -229,6 +235,7 @@ void storaged_t::event(void) {
229 if (mConfig.diskstats_available) { 235 if (mConfig.diskstats_available) {
230 mDiskStats.update(); 236 mDiskStats.update();
231 mDsm.update(); 237 mDsm.update();
238 storage_info->refresh();
232 if (mTimer && (mTimer % mConfig.periodic_chores_interval_disk_stats_publish) == 0) { 239 if (mTimer && (mTimer % mConfig.periodic_chores_interval_disk_stats_publish) == 0) {
233 mDiskStats.publish(); 240 mDiskStats.publish();
234 } 241 }
diff --git a/storaged/storaged_info.cpp b/storaged/storaged_info.cpp
index 434bd74ae..b5fb13e0c 100644
--- a/storaged/storaged_info.cpp
+++ b/storaged/storaged_info.cpp
@@ -18,6 +18,7 @@
18 18
19#include <stdio.h> 19#include <stdio.h>
20#include <string.h> 20#include <string.h>
21#include <sys/statvfs.h>
21 22
22#include <android-base/file.h> 23#include <android-base/file.h>
23#include <android-base/parseint.h> 24#include <android-base/parseint.h>
@@ -30,13 +31,42 @@
30using namespace std; 31using namespace std;
31using namespace android::base; 32using namespace android::base;
32 33
33void report_storage_health() 34const string emmc_info_t::emmc_sysfs = "/sys/bus/mmc/devices/mmc0:0001/";
35const string emmc_info_t::emmc_debugfs = "/d/mmc0/mmc0:0001/ext_csd";
36const char* emmc_info_t::emmc_ver_str[9] = {
37 "4.0", "4.1", "4.2", "4.3", "Obsolete", "4.41", "4.5", "5.0", "5.1"
38};
39
40const string ufs_info_t::health_file = "/sys/devices/soc/624000.ufshc/health";
41
42static bool FileExists(const std::string& filename)
43{
44 struct stat buffer;
45 return stat(filename.c_str(), &buffer) == 0;
46}
47
48storage_info_t* storage_info_t::get_storage_info()
49{
50 if (FileExists(emmc_info_t::emmc_sysfs) ||
51 FileExists(emmc_info_t::emmc_debugfs)) {
52 return new emmc_info_t;
53 }
54 if (FileExists(ufs_info_t::health_file)) {
55 return new ufs_info_t;
56 }
57 return new storage_info_t;
58}
59
60void storage_info_t::refresh()
34{ 61{
35 emmc_info_t mmc; 62 struct statvfs buf;
36 ufs_info_t ufs; 63 if (statvfs(userdata_path.c_str(), &buf) != 0) {
64 PLOG_TO(SYSTEM, WARNING) << "Failed to get userdata info";
65 return;
66 }
37 67
38 mmc.report(); 68 userdata_total_kb = buf.f_bsize * buf.f_blocks >> 10;
39 ufs.report(); 69 userdata_free_kb = buf.f_bfree * buf.f_blocks >> 10;
40} 70}
41 71
42void storage_info_t::publish() 72void storage_info_t::publish()
@@ -46,13 +76,12 @@ void storage_info_t::publish()
46 << LOG_ID_EVENTS; 76 << LOG_ID_EVENTS;
47} 77}
48 78
49bool emmc_info_t::report() 79void emmc_info_t::report()
50{ 80{
51 if (!report_sysfs() && !report_debugfs()) 81 if (!report_sysfs() && !report_debugfs())
52 return false; 82 return;
53 83
54 publish(); 84 publish();
55 return true;
56} 85}
57 86
58bool emmc_info_t::report_sysfs() 87bool emmc_info_t::report_sysfs()
@@ -136,21 +165,21 @@ bool emmc_info_t::report_debugfs()
136 return true; 165 return true;
137} 166}
138 167
139bool ufs_info_t::report() 168void ufs_info_t::report()
140{ 169{
141 string buffer; 170 string buffer;
142 if (!ReadFileToString(health_file, &buffer)) { 171 if (!ReadFileToString(health_file, &buffer)) {
143 return false; 172 return;
144 } 173 }
145 174
146 vector<string> lines = Split(buffer, "\n"); 175 vector<string> lines = Split(buffer, "\n");
147 if (lines.empty()) { 176 if (lines.empty()) {
148 return false; 177 return;
149 } 178 }
150 179
151 char rev[8]; 180 char rev[8];
152 if (sscanf(lines[0].c_str(), "ufs version: 0x%7s\n", rev) < 1) { 181 if (sscanf(lines[0].c_str(), "ufs version: 0x%7s\n", rev) < 1) {
153 return false; 182 return;
154 } 183 }
155 184
156 version = "ufs " + string(rev); 185 version = "ufs " + string(rev);
@@ -175,10 +204,9 @@ bool ufs_info_t::report()
175 } 204 }
176 205
177 if (eol == 0 || (lifetime_a == 0 && lifetime_b == 0)) { 206 if (eol == 0 || (lifetime_a == 0 && lifetime_b == 0)) {
178 return false; 207 return;
179 } 208 }
180 209
181 publish(); 210 publish();
182 return true;
183} 211}
184 212