mirror of https://github.com/M66B/FairEmail.git
Added sync stats
This commit is contained in:
parent
cf7468d009
commit
a6a7c43c14
|
@ -499,7 +499,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
||||||
account, browsable,
|
account, browsable,
|
||||||
(IMAPStore) state.iservice.getStore(), state.ifolder, (MimeMessage) isub[j],
|
(IMAPStore) state.iservice.getStore(), state.ifolder, (MimeMessage) isub[j],
|
||||||
true, true,
|
true, true,
|
||||||
rules, astate);
|
rules, astate, null);
|
||||||
found++;
|
found++;
|
||||||
}
|
}
|
||||||
if (message != null && criteria != null /* browsed */)
|
if (message != null && criteria != null /* browsed */)
|
||||||
|
|
|
@ -1095,6 +1095,8 @@ class Core {
|
||||||
List<EntityRule> rules = db.rule().getEnabledRules(folder.id);
|
List<EntityRule> rules = db.rule().getEnabledRules(folder.id);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
SyncStats stats = new SyncStats();
|
||||||
|
|
||||||
MimeMessage imessage = (MimeMessage) ifolder.getMessageByUID(uid);
|
MimeMessage imessage = (MimeMessage) ifolder.getMessageByUID(uid);
|
||||||
if (imessage == null)
|
if (imessage == null)
|
||||||
throw new MessageRemovedException();
|
throw new MessageRemovedException();
|
||||||
|
@ -1115,7 +1117,7 @@ class Core {
|
||||||
}
|
}
|
||||||
ifolder.fetch(new Message[]{imessage}, fp);
|
ifolder.fetch(new Message[]{imessage}, fp);
|
||||||
|
|
||||||
EntityMessage message = synchronizeMessage(context, account, folder, istore, ifolder, imessage, false, download, rules, state);
|
EntityMessage message = synchronizeMessage(context, account, folder, istore, ifolder, imessage, false, download, rules, state, stats);
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
if (account.isGmail() && EntityFolder.USER.equals(folder.type))
|
if (account.isGmail() && EntityFolder.USER.equals(folder.type))
|
||||||
try {
|
try {
|
||||||
|
@ -1128,8 +1130,10 @@ class Core {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (download)
|
if (download)
|
||||||
downloadMessage(context, account, folder, istore, ifolder, imessage, message.id, state);
|
downloadMessage(context, account, folder, istore, ifolder, imessage, message.id, state, stats);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EntityLog.log(context, folder.name + " fetch stats " + stats);
|
||||||
} finally {
|
} finally {
|
||||||
((IMAPMessage) imessage).invalidateHeaders();
|
((IMAPMessage) imessage).invalidateHeaders();
|
||||||
}
|
}
|
||||||
|
@ -1362,6 +1366,9 @@ class Core {
|
||||||
parts.isPlainOnly(),
|
parts.isPlainOnly(),
|
||||||
HtmlHelper.getPreview(body),
|
HtmlHelper.getPreview(body),
|
||||||
parts.getWarnings(message.warning));
|
parts.getWarnings(message.warning));
|
||||||
|
|
||||||
|
if (body != null)
|
||||||
|
EntityLog.log(context, "Operation body size=" + body.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void onAttachment(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, EntityOperation op, IMAPFolder ifolder) throws JSONException, MessagingException, IOException {
|
private static void onAttachment(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, EntityOperation op, IMAPFolder ifolder) throws JSONException, MessagingException, IOException {
|
||||||
|
@ -1390,6 +1397,9 @@ class Core {
|
||||||
|
|
||||||
// Download attachment
|
// Download attachment
|
||||||
parts.downloadAttachment(context, attachment);
|
parts.downloadAttachment(context, attachment);
|
||||||
|
|
||||||
|
if (attachment.size != null)
|
||||||
|
EntityLog.log(context, "Operation attachment size=" + attachment.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void onExists(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, EntityOperation op, IMAPFolder ifolder) throws MessagingException {
|
private static void onExists(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, EntityOperation op, IMAPFolder ifolder) throws MessagingException {
|
||||||
|
@ -1950,6 +1960,8 @@ class Core {
|
||||||
IMAPStore istore, final IMAPFolder ifolder, State state) throws JSONException, MessagingException, IOException {
|
IMAPStore istore, final IMAPFolder ifolder, State state) throws JSONException, MessagingException, IOException {
|
||||||
final DB db = DB.getInstance(context);
|
final DB db = DB.getInstance(context);
|
||||||
try {
|
try {
|
||||||
|
SyncStats stats = new SyncStats();
|
||||||
|
|
||||||
// Legacy
|
// Legacy
|
||||||
if (jargs.length() == 0)
|
if (jargs.length() == 0)
|
||||||
jargs = folder.getSyncArgs();
|
jargs = folder.getSyncArgs();
|
||||||
|
@ -2059,9 +2071,11 @@ class Core {
|
||||||
}
|
}
|
||||||
if (imessages == null)
|
if (imessages == null)
|
||||||
imessages = new Message[0];
|
imessages = new Message[0];
|
||||||
Log.i(folder.name + " remote count=" + imessages.length +
|
|
||||||
" search=" + (SystemClock.elapsedRealtime() - search) + " ms");
|
|
||||||
|
|
||||||
|
stats.search_ms = (SystemClock.elapsedRealtime() - search);
|
||||||
|
Log.i(folder.name + " remote count=" + imessages.length + " search=" + stats.search_ms + " ms");
|
||||||
|
|
||||||
|
long fetch = SystemClock.elapsedRealtime();
|
||||||
FetchProfile fp = new FetchProfile();
|
FetchProfile fp = new FetchProfile();
|
||||||
fp.add(UIDFolder.FetchProfileItem.UID); // To check if message exists
|
fp.add(UIDFolder.FetchProfileItem.UID); // To check if message exists
|
||||||
fp.add(FetchProfile.Item.FLAGS); // To update existing messages
|
fp.add(FetchProfile.Item.FLAGS); // To update existing messages
|
||||||
|
@ -2069,8 +2083,9 @@ class Core {
|
||||||
fp.add(GmailFolder.FetchProfileItem.LABELS);
|
fp.add(GmailFolder.FetchProfileItem.LABELS);
|
||||||
ifolder.fetch(imessages, fp);
|
ifolder.fetch(imessages, fp);
|
||||||
|
|
||||||
long fetch = SystemClock.elapsedRealtime();
|
stats.flags = imessages.length;
|
||||||
Log.i(folder.name + " remote fetched=" + (SystemClock.elapsedRealtime() - fetch) + " ms");
|
stats.flags_ms = (SystemClock.elapsedRealtime() - fetch);
|
||||||
|
Log.i(folder.name + " remote fetched=" + stats.flags_ms + " ms");
|
||||||
|
|
||||||
// Sort for finding referenced/replied-to messages
|
// Sort for finding referenced/replied-to messages
|
||||||
// Sorting on date/time would be better, but requires fetching the headers
|
// Sorting on date/time would be better, but requires fetching the headers
|
||||||
|
@ -2102,6 +2117,7 @@ class Core {
|
||||||
if (!ifolder.isOpen())
|
if (!ifolder.isOpen())
|
||||||
throw new FolderClosedException(ifolder, "UID FETCH");
|
throw new FolderClosedException(ifolder, "UID FETCH");
|
||||||
|
|
||||||
|
long getuid = SystemClock.elapsedRealtime();
|
||||||
MessagingException ex = (MessagingException) ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
|
MessagingException ex = (MessagingException) ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
|
||||||
@Override
|
@Override
|
||||||
public Object doCommand(IMAPProtocol protocol) {
|
public Object doCommand(IMAPProtocol protocol) {
|
||||||
|
@ -2173,8 +2189,9 @@ class Core {
|
||||||
if (ex != null)
|
if (ex != null)
|
||||||
throw ex;
|
throw ex;
|
||||||
|
|
||||||
long getuid = SystemClock.elapsedRealtime();
|
stats.uids = uids.size();
|
||||||
Log.i(folder.name + " remote uids=" + (SystemClock.elapsedRealtime() - getuid) + " ms");
|
stats.uids_ms = (SystemClock.elapsedRealtime() - getuid);
|
||||||
|
Log.i(folder.name + " remote uids=" + stats.uids_ms + " ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete local messages not at remote
|
// Delete local messages not at remote
|
||||||
|
@ -2215,8 +2232,9 @@ class Core {
|
||||||
if (full.size() > 0) {
|
if (full.size() > 0) {
|
||||||
long headers = SystemClock.elapsedRealtime();
|
long headers = SystemClock.elapsedRealtime();
|
||||||
ifolder.fetch(full.toArray(new Message[0]), fp);
|
ifolder.fetch(full.toArray(new Message[0]), fp);
|
||||||
Log.i(folder.name + " fetched headers=" + full.size() +
|
stats.headers += full.size();
|
||||||
" " + (SystemClock.elapsedRealtime() - headers) + " ms");
|
stats.headers_ms += (SystemClock.elapsedRealtime() - headers);
|
||||||
|
Log.i(folder.name + " fetched headers=" + full.size() + " " + stats.headers_ms + " ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
int free = Log.getFreeMemMb();
|
int free = Log.getFreeMemMb();
|
||||||
|
@ -2250,7 +2268,7 @@ class Core {
|
||||||
account, folder,
|
account, folder,
|
||||||
istore, ifolder, (MimeMessage) isub[j],
|
istore, ifolder, (MimeMessage) isub[j],
|
||||||
false, download && initialize == 0,
|
false, download && initialize == 0,
|
||||||
rules, state);
|
rules, state, stats);
|
||||||
ids[from + j] = (message == null || message.ui_hide ? null : message.id);
|
ids[from + j] = (message == null || message.ui_hide ? null : message.id);
|
||||||
} catch (MessageRemovedException ex) {
|
} catch (MessageRemovedException ex) {
|
||||||
Log.w(folder.name, ex);
|
Log.w(folder.name, ex);
|
||||||
|
@ -2318,7 +2336,8 @@ class Core {
|
||||||
context,
|
context,
|
||||||
account, folder,
|
account, folder,
|
||||||
istore, ifolder,
|
istore, ifolder,
|
||||||
(MimeMessage) isub[j], ids[from + j], state);
|
(MimeMessage) isub[j], ids[from + j],
|
||||||
|
state, stats);
|
||||||
} catch (FolderClosedException ex) {
|
} catch (FolderClosedException ex) {
|
||||||
throw ex;
|
throw ex;
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
|
@ -2351,6 +2370,8 @@ class Core {
|
||||||
db.folder().setFolderLastSync(folder.id, new Date().getTime());
|
db.folder().setFolderLastSync(folder.id, new Date().getTime());
|
||||||
db.folder().setFolderError(folder.id, null);
|
db.folder().setFolderError(folder.id, null);
|
||||||
|
|
||||||
|
stats.total = (SystemClock.elapsedRealtime() - search);
|
||||||
|
EntityLog.log(context, folder.name + " sync stats " + stats);
|
||||||
} finally {
|
} finally {
|
||||||
Log.i(folder.name + " end sync state=" + state);
|
Log.i(folder.name + " end sync state=" + state);
|
||||||
db.folder().setFolderSyncState(folder.id, null);
|
db.folder().setFolderSyncState(folder.id, null);
|
||||||
|
@ -2362,7 +2383,7 @@ class Core {
|
||||||
EntityAccount account, EntityFolder folder,
|
EntityAccount account, EntityFolder folder,
|
||||||
IMAPStore istore, IMAPFolder ifolder, MimeMessage imessage,
|
IMAPStore istore, IMAPFolder ifolder, MimeMessage imessage,
|
||||||
boolean browsed, boolean download,
|
boolean browsed, boolean download,
|
||||||
List<EntityRule> rules, State state) throws MessagingException, IOException {
|
List<EntityRule> rules, State state, SyncStats stats) throws MessagingException, IOException {
|
||||||
|
|
||||||
long uid = ifolder.getUID(imessage);
|
long uid = ifolder.getUID(imessage);
|
||||||
if (uid < 0) {
|
if (uid < 0) {
|
||||||
|
@ -2672,6 +2693,8 @@ class Core {
|
||||||
parts.isPlainOnly(),
|
parts.isPlainOnly(),
|
||||||
HtmlHelper.getPreview(body),
|
HtmlHelper.getPreview(body),
|
||||||
parts.getWarnings(message.warning));
|
parts.getWarnings(message.warning));
|
||||||
|
if (stats != null && body != null)
|
||||||
|
stats.content += body.length();
|
||||||
Log.i(folder.name + " inline downloaded message id=" + message.id +
|
Log.i(folder.name + " inline downloaded message id=" + message.id +
|
||||||
" size=" + message.size + "/" + (body == null ? null : body.length()));
|
" size=" + message.size + "/" + (body == null ? null : body.length()));
|
||||||
|
|
||||||
|
@ -2996,7 +3019,7 @@ class Core {
|
||||||
Context context,
|
Context context,
|
||||||
EntityAccount account, EntityFolder folder,
|
EntityAccount account, EntityFolder folder,
|
||||||
IMAPStore istore, IMAPFolder ifolder,
|
IMAPStore istore, IMAPFolder ifolder,
|
||||||
MimeMessage imessage, long id, State state) throws MessagingException, IOException {
|
MimeMessage imessage, long id, State state, SyncStats stats) throws MessagingException, IOException {
|
||||||
if (state.getNetworkState().isRoaming())
|
if (state.getNetworkState().isRoaming())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -3060,6 +3083,8 @@ class Core {
|
||||||
parts.isPlainOnly(),
|
parts.isPlainOnly(),
|
||||||
HtmlHelper.getPreview(body),
|
HtmlHelper.getPreview(body),
|
||||||
parts.getWarnings(message.warning));
|
parts.getWarnings(message.warning));
|
||||||
|
if (stats != null && body != null)
|
||||||
|
stats.content += body.length();
|
||||||
Log.i(folder.name + " downloaded message id=" + message.id +
|
Log.i(folder.name + " downloaded message id=" + message.id +
|
||||||
" size=" + message.size + "/" + (body == null ? null : body.length()));
|
" size=" + message.size + "/" + (body == null ? null : body.length()));
|
||||||
|
|
||||||
|
@ -3074,6 +3099,8 @@ class Core {
|
||||||
(attachment.size != null && attachment.size < maxSize))
|
(attachment.size != null && attachment.size < maxSize))
|
||||||
try {
|
try {
|
||||||
parts.downloadAttachment(context, attachment);
|
parts.downloadAttachment(context, attachment);
|
||||||
|
if (stats != null && attachment.size != null)
|
||||||
|
stats.attachments += attachment.size;
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
Log.e(folder.name, ex);
|
Log.e(folder.name, ex);
|
||||||
db.attachment().setError(attachment.id, Log.formatThrowable(ex, false));
|
db.attachment().setError(attachment.id, Log.formatThrowable(ex, false));
|
||||||
|
@ -4045,4 +4072,28 @@ class Core {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class SyncStats {
|
||||||
|
long search_ms;
|
||||||
|
int flags;
|
||||||
|
int uids;
|
||||||
|
long flags_ms;
|
||||||
|
long uids_ms;
|
||||||
|
int headers;
|
||||||
|
long headers_ms;
|
||||||
|
long content;
|
||||||
|
long attachments;
|
||||||
|
long total;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "search=" + search_ms + " ms" +
|
||||||
|
" flags=" + flags + "/" + flags_ms + " ms" +
|
||||||
|
" uids=" + uids + "/" + uids_ms + " ms" +
|
||||||
|
" headers=" + headers + "/" + headers_ms + " ms" +
|
||||||
|
" content=" + Helper.humanReadableByteCount(content) +
|
||||||
|
" attachments=" + Helper.humanReadableByteCount(attachments) +
|
||||||
|
" total=" + total;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue