use of com.android.server.content.SyncStorageEngine.AuthorityInfo in project platform_frameworks_base by android.
the class SyncManager method dumpRecentHistory.
private void dumpRecentHistory(PrintWriter pw) {
final ArrayList<SyncStorageEngine.SyncHistoryItem> items = mSyncStorageEngine.getSyncHistory();
if (items != null && items.size() > 0) {
final Map<String, AuthoritySyncStats> authorityMap = Maps.newHashMap();
long totalElapsedTime = 0;
long totalTimes = 0;
final int N = items.size();
int maxAuthority = 0;
int maxAccount = 0;
for (SyncStorageEngine.SyncHistoryItem item : items) {
SyncStorageEngine.AuthorityInfo authorityInfo = mSyncStorageEngine.getAuthority(item.authorityId);
final String authorityName;
final String accountKey;
if (authorityInfo != null) {
authorityName = authorityInfo.target.provider;
accountKey = authorityInfo.target.account.name + "/" + authorityInfo.target.account.type + " u" + authorityInfo.target.userId;
} else {
authorityName = "Unknown";
accountKey = "Unknown";
}
int length = authorityName.length();
if (length > maxAuthority) {
maxAuthority = length;
}
length = accountKey.length();
if (length > maxAccount) {
maxAccount = length;
}
final long elapsedTime = item.elapsedTime;
totalElapsedTime += elapsedTime;
totalTimes++;
AuthoritySyncStats authoritySyncStats = authorityMap.get(authorityName);
if (authoritySyncStats == null) {
authoritySyncStats = new AuthoritySyncStats(authorityName);
authorityMap.put(authorityName, authoritySyncStats);
}
authoritySyncStats.elapsedTime += elapsedTime;
authoritySyncStats.times++;
final Map<String, AccountSyncStats> accountMap = authoritySyncStats.accountMap;
AccountSyncStats accountSyncStats = accountMap.get(accountKey);
if (accountSyncStats == null) {
accountSyncStats = new AccountSyncStats(accountKey);
accountMap.put(accountKey, accountSyncStats);
}
accountSyncStats.elapsedTime += elapsedTime;
accountSyncStats.times++;
}
if (totalElapsedTime > 0) {
pw.println();
pw.printf("Detailed Statistics (Recent history): " + "%d (# of times) %ds (sync time)\n", totalTimes, totalElapsedTime / 1000);
final List<AuthoritySyncStats> sortedAuthorities = new ArrayList<AuthoritySyncStats>(authorityMap.values());
Collections.sort(sortedAuthorities, new Comparator<AuthoritySyncStats>() {
@Override
public int compare(AuthoritySyncStats lhs, AuthoritySyncStats rhs) {
// reverse order
int compare = Integer.compare(rhs.times, lhs.times);
if (compare == 0) {
compare = Long.compare(rhs.elapsedTime, lhs.elapsedTime);
}
return compare;
}
});
final int maxLength = Math.max(maxAuthority, maxAccount + 3);
final int padLength = 2 + 2 + maxLength + 2 + 10 + 11;
final char[] chars = new char[padLength];
Arrays.fill(chars, '-');
final String separator = new String(chars);
final String authorityFormat = String.format(" %%-%ds: %%-9s %%-11s\n", maxLength + 2);
final String accountFormat = String.format(" %%-%ds: %%-9s %%-11s\n", maxLength);
pw.println(separator);
for (AuthoritySyncStats authoritySyncStats : sortedAuthorities) {
String name = authoritySyncStats.name;
long elapsedTime;
int times;
String timeStr;
String timesStr;
elapsedTime = authoritySyncStats.elapsedTime;
times = authoritySyncStats.times;
timeStr = String.format("%ds/%d%%", elapsedTime / 1000, elapsedTime * 100 / totalElapsedTime);
timesStr = String.format("%d/%d%%", times, times * 100 / totalTimes);
pw.printf(authorityFormat, name, timesStr, timeStr);
final List<AccountSyncStats> sortedAccounts = new ArrayList<AccountSyncStats>(authoritySyncStats.accountMap.values());
Collections.sort(sortedAccounts, new Comparator<AccountSyncStats>() {
@Override
public int compare(AccountSyncStats lhs, AccountSyncStats rhs) {
// reverse order
int compare = Integer.compare(rhs.times, lhs.times);
if (compare == 0) {
compare = Long.compare(rhs.elapsedTime, lhs.elapsedTime);
}
return compare;
}
});
for (AccountSyncStats stats : sortedAccounts) {
elapsedTime = stats.elapsedTime;
times = stats.times;
timeStr = String.format("%ds/%d%%", elapsedTime / 1000, elapsedTime * 100 / totalElapsedTime);
timesStr = String.format("%d/%d%%", times, times * 100 / totalTimes);
pw.printf(accountFormat, stats.name, timesStr, timeStr);
}
pw.println(separator);
}
}
pw.println();
pw.println("Recent Sync History");
final String format = " %-" + maxAccount + "s %-" + maxAuthority + "s %s\n";
final Map<String, Long> lastTimeMap = Maps.newHashMap();
final PackageManager pm = mContext.getPackageManager();
for (int i = 0; i < N; i++) {
SyncStorageEngine.SyncHistoryItem item = items.get(i);
SyncStorageEngine.AuthorityInfo authorityInfo = mSyncStorageEngine.getAuthority(item.authorityId);
final String authorityName;
final String accountKey;
if (authorityInfo != null) {
authorityName = authorityInfo.target.provider;
accountKey = authorityInfo.target.account.name + "/" + authorityInfo.target.account.type + " u" + authorityInfo.target.userId;
} else {
authorityName = "Unknown";
accountKey = "Unknown";
}
final long elapsedTime = item.elapsedTime;
final Time time = new Time();
final long eventTime = item.eventTime;
time.set(eventTime);
final String key = authorityName + "/" + accountKey;
final Long lastEventTime = lastTimeMap.get(key);
final String diffString;
if (lastEventTime == null) {
diffString = "";
} else {
final long diff = (lastEventTime - eventTime) / 1000;
if (diff < 60) {
diffString = String.valueOf(diff);
} else if (diff < 3600) {
diffString = String.format("%02d:%02d", diff / 60, diff % 60);
} else {
final long sec = diff % 3600;
diffString = String.format("%02d:%02d:%02d", diff / 3600, sec / 60, sec % 60);
}
}
lastTimeMap.put(key, eventTime);
pw.printf(" #%-3d: %s %8s %5.1fs %8s", i + 1, formatTime(eventTime), SyncStorageEngine.SOURCES[item.source], ((float) elapsedTime) / 1000, diffString);
pw.printf(format, accountKey, authorityName, SyncOperation.reasonToString(pm, item.reason));
if (item.event != SyncStorageEngine.EVENT_STOP || item.upstreamActivity != 0 || item.downstreamActivity != 0) {
pw.printf(" event=%d upstreamActivity=%d downstreamActivity=%d\n", item.event, item.upstreamActivity, item.downstreamActivity);
}
if (item.mesg != null && !SyncStorageEngine.MESG_SUCCESS.equals(item.mesg)) {
pw.printf(" mesg=%s\n", item.mesg);
}
}
pw.println();
pw.println("Recent Sync History Extras");
for (int i = 0; i < N; i++) {
final SyncStorageEngine.SyncHistoryItem item = items.get(i);
final Bundle extras = item.extras;
if (extras == null || extras.size() == 0) {
continue;
}
final SyncStorageEngine.AuthorityInfo authorityInfo = mSyncStorageEngine.getAuthority(item.authorityId);
final String authorityName;
final String accountKey;
if (authorityInfo != null) {
authorityName = authorityInfo.target.provider;
accountKey = authorityInfo.target.account.name + "/" + authorityInfo.target.account.type + " u" + authorityInfo.target.userId;
} else {
authorityName = "Unknown";
accountKey = "Unknown";
}
final Time time = new Time();
final long eventTime = item.eventTime;
time.set(eventTime);
pw.printf(" #%-3d: %s %8s ", i + 1, formatTime(eventTime), SyncStorageEngine.SOURCES[item.source]);
pw.printf(format, accountKey, authorityName, extras);
}
}
}
use of com.android.server.content.SyncStorageEngine.AuthorityInfo in project android_frameworks_base by DirtyUnicorns.
the class SyncManager method dumpRecentHistory.
private void dumpRecentHistory(PrintWriter pw) {
final ArrayList<SyncStorageEngine.SyncHistoryItem> items = mSyncStorageEngine.getSyncHistory();
if (items != null && items.size() > 0) {
final Map<String, AuthoritySyncStats> authorityMap = Maps.newHashMap();
long totalElapsedTime = 0;
long totalTimes = 0;
final int N = items.size();
int maxAuthority = 0;
int maxAccount = 0;
for (SyncStorageEngine.SyncHistoryItem item : items) {
SyncStorageEngine.AuthorityInfo authorityInfo = mSyncStorageEngine.getAuthority(item.authorityId);
final String authorityName;
final String accountKey;
if (authorityInfo != null) {
authorityName = authorityInfo.target.provider;
accountKey = authorityInfo.target.account.name + "/" + authorityInfo.target.account.type + " u" + authorityInfo.target.userId;
} else {
authorityName = "Unknown";
accountKey = "Unknown";
}
int length = authorityName.length();
if (length > maxAuthority) {
maxAuthority = length;
}
length = accountKey.length();
if (length > maxAccount) {
maxAccount = length;
}
final long elapsedTime = item.elapsedTime;
totalElapsedTime += elapsedTime;
totalTimes++;
AuthoritySyncStats authoritySyncStats = authorityMap.get(authorityName);
if (authoritySyncStats == null) {
authoritySyncStats = new AuthoritySyncStats(authorityName);
authorityMap.put(authorityName, authoritySyncStats);
}
authoritySyncStats.elapsedTime += elapsedTime;
authoritySyncStats.times++;
final Map<String, AccountSyncStats> accountMap = authoritySyncStats.accountMap;
AccountSyncStats accountSyncStats = accountMap.get(accountKey);
if (accountSyncStats == null) {
accountSyncStats = new AccountSyncStats(accountKey);
accountMap.put(accountKey, accountSyncStats);
}
accountSyncStats.elapsedTime += elapsedTime;
accountSyncStats.times++;
}
if (totalElapsedTime > 0) {
pw.println();
pw.printf("Detailed Statistics (Recent history): " + "%d (# of times) %ds (sync time)\n", totalTimes, totalElapsedTime / 1000);
final List<AuthoritySyncStats> sortedAuthorities = new ArrayList<AuthoritySyncStats>(authorityMap.values());
Collections.sort(sortedAuthorities, new Comparator<AuthoritySyncStats>() {
@Override
public int compare(AuthoritySyncStats lhs, AuthoritySyncStats rhs) {
// reverse order
int compare = Integer.compare(rhs.times, lhs.times);
if (compare == 0) {
compare = Long.compare(rhs.elapsedTime, lhs.elapsedTime);
}
return compare;
}
});
final int maxLength = Math.max(maxAuthority, maxAccount + 3);
final int padLength = 2 + 2 + maxLength + 2 + 10 + 11;
final char[] chars = new char[padLength];
Arrays.fill(chars, '-');
final String separator = new String(chars);
final String authorityFormat = String.format(" %%-%ds: %%-9s %%-11s\n", maxLength + 2);
final String accountFormat = String.format(" %%-%ds: %%-9s %%-11s\n", maxLength);
pw.println(separator);
for (AuthoritySyncStats authoritySyncStats : sortedAuthorities) {
String name = authoritySyncStats.name;
long elapsedTime;
int times;
String timeStr;
String timesStr;
elapsedTime = authoritySyncStats.elapsedTime;
times = authoritySyncStats.times;
timeStr = String.format("%ds/%d%%", elapsedTime / 1000, elapsedTime * 100 / totalElapsedTime);
timesStr = String.format("%d/%d%%", times, times * 100 / totalTimes);
pw.printf(authorityFormat, name, timesStr, timeStr);
final List<AccountSyncStats> sortedAccounts = new ArrayList<AccountSyncStats>(authoritySyncStats.accountMap.values());
Collections.sort(sortedAccounts, new Comparator<AccountSyncStats>() {
@Override
public int compare(AccountSyncStats lhs, AccountSyncStats rhs) {
// reverse order
int compare = Integer.compare(rhs.times, lhs.times);
if (compare == 0) {
compare = Long.compare(rhs.elapsedTime, lhs.elapsedTime);
}
return compare;
}
});
for (AccountSyncStats stats : sortedAccounts) {
elapsedTime = stats.elapsedTime;
times = stats.times;
timeStr = String.format("%ds/%d%%", elapsedTime / 1000, elapsedTime * 100 / totalElapsedTime);
timesStr = String.format("%d/%d%%", times, times * 100 / totalTimes);
pw.printf(accountFormat, stats.name, timesStr, timeStr);
}
pw.println(separator);
}
}
pw.println();
pw.println("Recent Sync History");
final String format = " %-" + maxAccount + "s %-" + maxAuthority + "s %s\n";
final Map<String, Long> lastTimeMap = Maps.newHashMap();
final PackageManager pm = mContext.getPackageManager();
for (int i = 0; i < N; i++) {
SyncStorageEngine.SyncHistoryItem item = items.get(i);
SyncStorageEngine.AuthorityInfo authorityInfo = mSyncStorageEngine.getAuthority(item.authorityId);
final String authorityName;
final String accountKey;
if (authorityInfo != null) {
authorityName = authorityInfo.target.provider;
accountKey = authorityInfo.target.account.name + "/" + authorityInfo.target.account.type + " u" + authorityInfo.target.userId;
} else {
authorityName = "Unknown";
accountKey = "Unknown";
}
final long elapsedTime = item.elapsedTime;
final Time time = new Time();
final long eventTime = item.eventTime;
time.set(eventTime);
final String key = authorityName + "/" + accountKey;
final Long lastEventTime = lastTimeMap.get(key);
final String diffString;
if (lastEventTime == null) {
diffString = "";
} else {
final long diff = (lastEventTime - eventTime) / 1000;
if (diff < 60) {
diffString = String.valueOf(diff);
} else if (diff < 3600) {
diffString = String.format("%02d:%02d", diff / 60, diff % 60);
} else {
final long sec = diff % 3600;
diffString = String.format("%02d:%02d:%02d", diff / 3600, sec / 60, sec % 60);
}
}
lastTimeMap.put(key, eventTime);
pw.printf(" #%-3d: %s %8s %5.1fs %8s", i + 1, formatTime(eventTime), SyncStorageEngine.SOURCES[item.source], ((float) elapsedTime) / 1000, diffString);
pw.printf(format, accountKey, authorityName, SyncOperation.reasonToString(pm, item.reason));
if (item.event != SyncStorageEngine.EVENT_STOP || item.upstreamActivity != 0 || item.downstreamActivity != 0) {
pw.printf(" event=%d upstreamActivity=%d downstreamActivity=%d\n", item.event, item.upstreamActivity, item.downstreamActivity);
}
if (item.mesg != null && !SyncStorageEngine.MESG_SUCCESS.equals(item.mesg)) {
pw.printf(" mesg=%s\n", item.mesg);
}
}
pw.println();
pw.println("Recent Sync History Extras");
for (int i = 0; i < N; i++) {
final SyncStorageEngine.SyncHistoryItem item = items.get(i);
final Bundle extras = item.extras;
if (extras == null || extras.size() == 0) {
continue;
}
final SyncStorageEngine.AuthorityInfo authorityInfo = mSyncStorageEngine.getAuthority(item.authorityId);
final String authorityName;
final String accountKey;
if (authorityInfo != null) {
authorityName = authorityInfo.target.provider;
accountKey = authorityInfo.target.account.name + "/" + authorityInfo.target.account.type + " u" + authorityInfo.target.userId;
} else {
authorityName = "Unknown";
accountKey = "Unknown";
}
final Time time = new Time();
final long eventTime = item.eventTime;
time.set(eventTime);
pw.printf(" #%-3d: %s %8s ", i + 1, formatTime(eventTime), SyncStorageEngine.SOURCES[item.source]);
pw.printf(format, accountKey, authorityName, extras);
}
}
}
use of com.android.server.content.SyncStorageEngine.AuthorityInfo in project android_frameworks_base by AOSPA.
the class SyncManager method dumpSyncState.
protected void dumpSyncState(PrintWriter pw) {
pw.print("data connected: ");
pw.println(mDataConnectionIsConnected);
pw.print("auto sync: ");
List<UserInfo> users = getAllUsers();
if (users != null) {
for (UserInfo user : users) {
pw.print("u" + user.id + "=" + mSyncStorageEngine.getMasterSyncAutomatically(user.id) + " ");
}
pw.println();
}
pw.print("memory low: ");
pw.println(mStorageIsLow);
pw.print("device idle: ");
pw.println(mDeviceIsIdle);
pw.print("reported active: ");
pw.println(mReportedSyncActive);
final AccountAndUser[] accounts = AccountManagerService.getSingleton().getAllAccounts();
pw.print("accounts: ");
if (accounts != INITIAL_ACCOUNTS_ARRAY) {
pw.println(accounts.length);
} else {
pw.println("not known yet");
}
final long now = SystemClock.elapsedRealtime();
pw.print("now: ");
pw.print(now);
pw.println(" (" + formatTime(System.currentTimeMillis()) + ")");
pw.println(" (HH:MM:SS)");
pw.print("uptime: ");
pw.print(DateUtils.formatElapsedTime(now / 1000));
pw.println(" (HH:MM:SS)");
pw.print("time spent syncing: ");
pw.print(DateUtils.formatElapsedTime(mSyncHandler.mSyncTimeTracker.timeSpentSyncing() / 1000));
pw.print(" (HH:MM:SS), sync ");
pw.print(mSyncHandler.mSyncTimeTracker.mLastWasSyncing ? "" : "not ");
pw.println("in progress");
pw.println();
pw.println("Active Syncs: " + mActiveSyncContexts.size());
final PackageManager pm = mContext.getPackageManager();
for (SyncManager.ActiveSyncContext activeSyncContext : mActiveSyncContexts) {
final long durationInSeconds = (now - activeSyncContext.mStartTime) / 1000;
pw.print(" ");
pw.print(DateUtils.formatElapsedTime(durationInSeconds));
pw.print(" - ");
pw.print(activeSyncContext.mSyncOperation.dump(pm, false));
pw.println();
}
// Join the installed sync adapter with the accounts list and emit for everything.
pw.println();
pw.println("Sync Status");
for (AccountAndUser account : accounts) {
pw.printf("Account %s u%d %s\n", account.account.name, account.userId, account.account.type);
pw.println("=======================================================================");
final PrintTable table = new PrintTable(12);
table.set(0, 0, // 0
"Authority", // 1
"Syncable", // 2
"Enabled", // 3
"Delay", // 4
"Loc", // 5
"Poll", // 6
"Per", // 7
"Serv", // 8
"User", // 9
"Tot", // 10
"Time", // 11
"Last Sync");
final List<RegisteredServicesCache.ServiceInfo<SyncAdapterType>> sorted = Lists.newArrayList();
sorted.addAll(mSyncAdapters.getAllServices(account.userId));
Collections.sort(sorted, new Comparator<RegisteredServicesCache.ServiceInfo<SyncAdapterType>>() {
@Override
public int compare(RegisteredServicesCache.ServiceInfo<SyncAdapterType> lhs, RegisteredServicesCache.ServiceInfo<SyncAdapterType> rhs) {
return lhs.type.authority.compareTo(rhs.type.authority);
}
});
for (RegisteredServicesCache.ServiceInfo<SyncAdapterType> syncAdapterType : sorted) {
if (!syncAdapterType.type.accountType.equals(account.account.type)) {
continue;
}
int row = table.getNumRows();
Pair<AuthorityInfo, SyncStatusInfo> syncAuthoritySyncStatus = mSyncStorageEngine.getCopyOfAuthorityWithSyncStatus(new SyncStorageEngine.EndPoint(account.account, syncAdapterType.type.authority, account.userId));
SyncStorageEngine.AuthorityInfo settings = syncAuthoritySyncStatus.first;
SyncStatusInfo status = syncAuthoritySyncStatus.second;
String authority = settings.target.provider;
if (authority.length() > 50) {
authority = authority.substring(authority.length() - 50);
}
table.set(row, 0, authority, settings.syncable, settings.enabled);
table.set(row, 4, status.numSourceLocal, status.numSourcePoll, status.numSourcePeriodic, status.numSourceServer, status.numSourceUser, status.numSyncs, DateUtils.formatElapsedTime(status.totalElapsedTime / 1000));
int row1 = row;
if (settings.delayUntil > now) {
table.set(row1++, 12, "D: " + (settings.delayUntil - now) / 1000);
if (settings.backoffTime > now) {
table.set(row1++, 12, "B: " + (settings.backoffTime - now) / 1000);
table.set(row1++, 12, settings.backoffDelay / 1000);
}
}
if (status.lastSuccessTime != 0) {
table.set(row1++, 11, SyncStorageEngine.SOURCES[status.lastSuccessSource] + " " + "SUCCESS");
table.set(row1++, 11, formatTime(status.lastSuccessTime));
}
if (status.lastFailureTime != 0) {
table.set(row1++, 11, SyncStorageEngine.SOURCES[status.lastFailureSource] + " " + "FAILURE");
table.set(row1++, 11, formatTime(status.lastFailureTime));
//noinspection UnusedAssignment
table.set(row1++, 11, status.lastFailureMesg);
}
}
table.writeTo(pw);
}
}
use of com.android.server.content.SyncStorageEngine.AuthorityInfo in project android_frameworks_base by ResurrectionRemix.
the class SyncManager method dumpSyncState.
protected void dumpSyncState(PrintWriter pw) {
pw.print("data connected: ");
pw.println(mDataConnectionIsConnected);
pw.print("auto sync: ");
List<UserInfo> users = getAllUsers();
if (users != null) {
for (UserInfo user : users) {
pw.print("u" + user.id + "=" + mSyncStorageEngine.getMasterSyncAutomatically(user.id) + " ");
}
pw.println();
}
pw.print("memory low: ");
pw.println(mStorageIsLow);
pw.print("device idle: ");
pw.println(mDeviceIsIdle);
pw.print("reported active: ");
pw.println(mReportedSyncActive);
final AccountAndUser[] accounts = AccountManagerService.getSingleton().getAllAccounts();
pw.print("accounts: ");
if (accounts != INITIAL_ACCOUNTS_ARRAY) {
pw.println(accounts.length);
} else {
pw.println("not known yet");
}
final long now = SystemClock.elapsedRealtime();
pw.print("now: ");
pw.print(now);
pw.println(" (" + formatTime(System.currentTimeMillis()) + ")");
pw.println(" (HH:MM:SS)");
pw.print("uptime: ");
pw.print(DateUtils.formatElapsedTime(now / 1000));
pw.println(" (HH:MM:SS)");
pw.print("time spent syncing: ");
pw.print(DateUtils.formatElapsedTime(mSyncHandler.mSyncTimeTracker.timeSpentSyncing() / 1000));
pw.print(" (HH:MM:SS), sync ");
pw.print(mSyncHandler.mSyncTimeTracker.mLastWasSyncing ? "" : "not ");
pw.println("in progress");
pw.println();
pw.println("Active Syncs: " + mActiveSyncContexts.size());
final PackageManager pm = mContext.getPackageManager();
for (SyncManager.ActiveSyncContext activeSyncContext : mActiveSyncContexts) {
final long durationInSeconds = (now - activeSyncContext.mStartTime) / 1000;
pw.print(" ");
pw.print(DateUtils.formatElapsedTime(durationInSeconds));
pw.print(" - ");
pw.print(activeSyncContext.mSyncOperation.dump(pm, false));
pw.println();
}
// Join the installed sync adapter with the accounts list and emit for everything.
pw.println();
pw.println("Sync Status");
for (AccountAndUser account : accounts) {
pw.printf("Account %s u%d %s\n", account.account.name, account.userId, account.account.type);
pw.println("=======================================================================");
final PrintTable table = new PrintTable(12);
table.set(0, 0, // 0
"Authority", // 1
"Syncable", // 2
"Enabled", // 3
"Delay", // 4
"Loc", // 5
"Poll", // 6
"Per", // 7
"Serv", // 8
"User", // 9
"Tot", // 10
"Time", // 11
"Last Sync");
final List<RegisteredServicesCache.ServiceInfo<SyncAdapterType>> sorted = Lists.newArrayList();
sorted.addAll(mSyncAdapters.getAllServices(account.userId));
Collections.sort(sorted, new Comparator<RegisteredServicesCache.ServiceInfo<SyncAdapterType>>() {
@Override
public int compare(RegisteredServicesCache.ServiceInfo<SyncAdapterType> lhs, RegisteredServicesCache.ServiceInfo<SyncAdapterType> rhs) {
return lhs.type.authority.compareTo(rhs.type.authority);
}
});
for (RegisteredServicesCache.ServiceInfo<SyncAdapterType> syncAdapterType : sorted) {
if (!syncAdapterType.type.accountType.equals(account.account.type)) {
continue;
}
int row = table.getNumRows();
Pair<AuthorityInfo, SyncStatusInfo> syncAuthoritySyncStatus = mSyncStorageEngine.getCopyOfAuthorityWithSyncStatus(new SyncStorageEngine.EndPoint(account.account, syncAdapterType.type.authority, account.userId));
SyncStorageEngine.AuthorityInfo settings = syncAuthoritySyncStatus.first;
SyncStatusInfo status = syncAuthoritySyncStatus.second;
String authority = settings.target.provider;
if (authority.length() > 50) {
authority = authority.substring(authority.length() - 50);
}
table.set(row, 0, authority, settings.syncable, settings.enabled);
table.set(row, 4, status.numSourceLocal, status.numSourcePoll, status.numSourcePeriodic, status.numSourceServer, status.numSourceUser, status.numSyncs, DateUtils.formatElapsedTime(status.totalElapsedTime / 1000));
int row1 = row;
if (settings.delayUntil > now) {
table.set(row1++, 12, "D: " + (settings.delayUntil - now) / 1000);
if (settings.backoffTime > now) {
table.set(row1++, 12, "B: " + (settings.backoffTime - now) / 1000);
table.set(row1++, 12, settings.backoffDelay / 1000);
}
}
if (status.lastSuccessTime != 0) {
table.set(row1++, 11, SyncStorageEngine.SOURCES[status.lastSuccessSource] + " " + "SUCCESS");
table.set(row1++, 11, formatTime(status.lastSuccessTime));
}
if (status.lastFailureTime != 0) {
table.set(row1++, 11, SyncStorageEngine.SOURCES[status.lastFailureSource] + " " + "FAILURE");
table.set(row1++, 11, formatTime(status.lastFailureTime));
//noinspection UnusedAssignment
table.set(row1++, 11, status.lastFailureMesg);
}
}
table.writeTo(pw);
}
}
use of com.android.server.content.SyncStorageEngine.AuthorityInfo in project android_frameworks_base by crdroidandroid.
the class SyncManager method dumpRecentHistory.
private void dumpRecentHistory(PrintWriter pw) {
final ArrayList<SyncStorageEngine.SyncHistoryItem> items = mSyncStorageEngine.getSyncHistory();
if (items != null && items.size() > 0) {
final Map<String, AuthoritySyncStats> authorityMap = Maps.newHashMap();
long totalElapsedTime = 0;
long totalTimes = 0;
final int N = items.size();
int maxAuthority = 0;
int maxAccount = 0;
for (SyncStorageEngine.SyncHistoryItem item : items) {
SyncStorageEngine.AuthorityInfo authorityInfo = mSyncStorageEngine.getAuthority(item.authorityId);
final String authorityName;
final String accountKey;
if (authorityInfo != null) {
authorityName = authorityInfo.target.provider;
accountKey = authorityInfo.target.account.name + "/" + authorityInfo.target.account.type + " u" + authorityInfo.target.userId;
} else {
authorityName = "Unknown";
accountKey = "Unknown";
}
int length = authorityName.length();
if (length > maxAuthority) {
maxAuthority = length;
}
length = accountKey.length();
if (length > maxAccount) {
maxAccount = length;
}
final long elapsedTime = item.elapsedTime;
totalElapsedTime += elapsedTime;
totalTimes++;
AuthoritySyncStats authoritySyncStats = authorityMap.get(authorityName);
if (authoritySyncStats == null) {
authoritySyncStats = new AuthoritySyncStats(authorityName);
authorityMap.put(authorityName, authoritySyncStats);
}
authoritySyncStats.elapsedTime += elapsedTime;
authoritySyncStats.times++;
final Map<String, AccountSyncStats> accountMap = authoritySyncStats.accountMap;
AccountSyncStats accountSyncStats = accountMap.get(accountKey);
if (accountSyncStats == null) {
accountSyncStats = new AccountSyncStats(accountKey);
accountMap.put(accountKey, accountSyncStats);
}
accountSyncStats.elapsedTime += elapsedTime;
accountSyncStats.times++;
}
if (totalElapsedTime > 0) {
pw.println();
pw.printf("Detailed Statistics (Recent history): " + "%d (# of times) %ds (sync time)\n", totalTimes, totalElapsedTime / 1000);
final List<AuthoritySyncStats> sortedAuthorities = new ArrayList<AuthoritySyncStats>(authorityMap.values());
Collections.sort(sortedAuthorities, new Comparator<AuthoritySyncStats>() {
@Override
public int compare(AuthoritySyncStats lhs, AuthoritySyncStats rhs) {
// reverse order
int compare = Integer.compare(rhs.times, lhs.times);
if (compare == 0) {
compare = Long.compare(rhs.elapsedTime, lhs.elapsedTime);
}
return compare;
}
});
final int maxLength = Math.max(maxAuthority, maxAccount + 3);
final int padLength = 2 + 2 + maxLength + 2 + 10 + 11;
final char[] chars = new char[padLength];
Arrays.fill(chars, '-');
final String separator = new String(chars);
final String authorityFormat = String.format(" %%-%ds: %%-9s %%-11s\n", maxLength + 2);
final String accountFormat = String.format(" %%-%ds: %%-9s %%-11s\n", maxLength);
pw.println(separator);
for (AuthoritySyncStats authoritySyncStats : sortedAuthorities) {
String name = authoritySyncStats.name;
long elapsedTime;
int times;
String timeStr;
String timesStr;
elapsedTime = authoritySyncStats.elapsedTime;
times = authoritySyncStats.times;
timeStr = String.format("%ds/%d%%", elapsedTime / 1000, elapsedTime * 100 / totalElapsedTime);
timesStr = String.format("%d/%d%%", times, times * 100 / totalTimes);
pw.printf(authorityFormat, name, timesStr, timeStr);
final List<AccountSyncStats> sortedAccounts = new ArrayList<AccountSyncStats>(authoritySyncStats.accountMap.values());
Collections.sort(sortedAccounts, new Comparator<AccountSyncStats>() {
@Override
public int compare(AccountSyncStats lhs, AccountSyncStats rhs) {
// reverse order
int compare = Integer.compare(rhs.times, lhs.times);
if (compare == 0) {
compare = Long.compare(rhs.elapsedTime, lhs.elapsedTime);
}
return compare;
}
});
for (AccountSyncStats stats : sortedAccounts) {
elapsedTime = stats.elapsedTime;
times = stats.times;
timeStr = String.format("%ds/%d%%", elapsedTime / 1000, elapsedTime * 100 / totalElapsedTime);
timesStr = String.format("%d/%d%%", times, times * 100 / totalTimes);
pw.printf(accountFormat, stats.name, timesStr, timeStr);
}
pw.println(separator);
}
}
pw.println();
pw.println("Recent Sync History");
final String format = " %-" + maxAccount + "s %-" + maxAuthority + "s %s\n";
final Map<String, Long> lastTimeMap = Maps.newHashMap();
final PackageManager pm = mContext.getPackageManager();
for (int i = 0; i < N; i++) {
SyncStorageEngine.SyncHistoryItem item = items.get(i);
SyncStorageEngine.AuthorityInfo authorityInfo = mSyncStorageEngine.getAuthority(item.authorityId);
final String authorityName;
final String accountKey;
if (authorityInfo != null) {
authorityName = authorityInfo.target.provider;
accountKey = authorityInfo.target.account.name + "/" + authorityInfo.target.account.type + " u" + authorityInfo.target.userId;
} else {
authorityName = "Unknown";
accountKey = "Unknown";
}
final long elapsedTime = item.elapsedTime;
final Time time = new Time();
final long eventTime = item.eventTime;
time.set(eventTime);
final String key = authorityName + "/" + accountKey;
final Long lastEventTime = lastTimeMap.get(key);
final String diffString;
if (lastEventTime == null) {
diffString = "";
} else {
final long diff = (lastEventTime - eventTime) / 1000;
if (diff < 60) {
diffString = String.valueOf(diff);
} else if (diff < 3600) {
diffString = String.format("%02d:%02d", diff / 60, diff % 60);
} else {
final long sec = diff % 3600;
diffString = String.format("%02d:%02d:%02d", diff / 3600, sec / 60, sec % 60);
}
}
lastTimeMap.put(key, eventTime);
pw.printf(" #%-3d: %s %8s %5.1fs %8s", i + 1, formatTime(eventTime), SyncStorageEngine.SOURCES[item.source], ((float) elapsedTime) / 1000, diffString);
pw.printf(format, accountKey, authorityName, SyncOperation.reasonToString(pm, item.reason));
if (item.event != SyncStorageEngine.EVENT_STOP || item.upstreamActivity != 0 || item.downstreamActivity != 0) {
pw.printf(" event=%d upstreamActivity=%d downstreamActivity=%d\n", item.event, item.upstreamActivity, item.downstreamActivity);
}
if (item.mesg != null && !SyncStorageEngine.MESG_SUCCESS.equals(item.mesg)) {
pw.printf(" mesg=%s\n", item.mesg);
}
}
pw.println();
pw.println("Recent Sync History Extras");
for (int i = 0; i < N; i++) {
final SyncStorageEngine.SyncHistoryItem item = items.get(i);
final Bundle extras = item.extras;
if (extras == null || extras.size() == 0) {
continue;
}
final SyncStorageEngine.AuthorityInfo authorityInfo = mSyncStorageEngine.getAuthority(item.authorityId);
final String authorityName;
final String accountKey;
if (authorityInfo != null) {
authorityName = authorityInfo.target.provider;
accountKey = authorityInfo.target.account.name + "/" + authorityInfo.target.account.type + " u" + authorityInfo.target.userId;
} else {
authorityName = "Unknown";
accountKey = "Unknown";
}
final Time time = new Time();
final long eventTime = item.eventTime;
time.set(eventTime);
pw.printf(" #%-3d: %s %8s ", i + 1, formatTime(eventTime), SyncStorageEngine.SOURCES[item.source]);
pw.printf(format, accountKey, authorityName, extras);
}
}
}
Aggregations