|
|
DescriptionAdd additional histograms with suffixes to ImportantFileWriter.
Additional histograms are added to the ImportantFileWriter code to
monitor system error codes, and find out exact reasons for failures.
Furthermore, histogram suffixes are introduced to discriminate
users of the ImportantFileWriter code. As an example, two services
(BookmarkStorage and FeedbackReport) are now using the suffixes,
which can be further utilized in other services.
The original ImportantFile.TempFileFailures histogram will also
be dynamically suffixed.
[email protected]
TEST=New histograms and suffixes will appear.
BUG=
Review-Url: https://codereview.chromium.org/2920223002
Cr-Commit-Position: refs/heads/master@{#480783}
Committed: https://chromium.googlesource.com/chromium/src/+/4ae8d1757f7b5a0cb85497205a80ed2a572a5165
Patch Set 1 #
Total comments: 7
Patch Set 2 : Fix problems pointed by code reviewers. #
Total comments: 4
Patch Set 3 : Fix more problems pointed by code reviewers. #
Total comments: 6
Patch Set 4 : Fix histogram suffix to use string reference instead of StringPiece. #
Total comments: 4
Patch Set 5 : Revert histogram suffix to use StringPiece instead of string reference. #
Total comments: 2
Patch Set 6 : Minor fix of std::string::append. #
Messages
Total messages: 51 (27 generated)
Description was changed from ========== Add additional histograms with suffixes to ImportantFileWriter. Additional histograms are added to the ImportantFileWriter code to monitor system error codes, and find out exact reasons for failures. Furthermore, histogram suffixes are introduced to discriminate users of the ImportantFileWriter code. As an example, two services (BookmarkStorage and FeedbackReport) are now using the suffixes, which can be further utilized in other services. The original ImportantFile.TempFileFailures histogram will also be dynamically suffixed. [email protected] TEST=New histograms and suffixes will appear. BUG= ========== to ========== Add additional histograms with suffixes to ImportantFileWriter. Additional histograms are added to the ImportantFileWriter code to monitor system error codes, and find out exact reasons for failures. Furthermore, histogram suffixes are introduced to discriminate users of the ImportantFileWriter code. As an example, two services (BookmarkStorage and FeedbackReport) are now using the suffixes, which can be further utilized in other services. The original ImportantFile.TempFileFailures histogram will also be dynamically suffixed. [email protected] TEST=New histograms and suffixes will appear. BUG= ==========
[email protected] changed reviewers: + [email protected], [email protected]
The CQ bit was checked by [email protected] to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at: https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was unchecked by [email protected]
Dry run: No L-G-T-M from a valid reviewer yet. CQ run can only be started once the patch has received an L-G-T-M from a full committer. Even if an L-G-T-M may have been provided, it was from a non-committer,_not_ a full super star committer. Committers are members of the group "project-chromium-committers". Note that this has nothing to do with OWNERS files.
[email protected] changed reviewers: + [email protected]
+dcheng for base changes https://codereview.chromium.org/2920223002/diff/1/base/files/important_file_w... File base/files/important_file_writer.h (right): https://codereview.chromium.org/2920223002/diff/1/base/files/important_file_w... base/files/important_file_writer.h:58: std::string histogram_suffix = std::string()); const std::string& on all of these. https://codereview.chromium.org/2920223002/diff/1/base/files/important_file_w... base/files/important_file_writer.h:151: std::string histogram_suffix_; const
https://codereview.chromium.org/2920223002/diff/1/base/files/important_file_w... File base/files/important_file_writer.cc (right): https://codereview.chromium.org/2920223002/diff/1/base/files/important_file_w... base/files/important_file_writer.cc:58: DynamicUmaHistogramEnumeration(const char* histogram_name, can you use the function version from https://cs.chromium.org/chromium/src/base/metrics/histogram_functions.h?q=his... ?
https://codereview.chromium.org/2920223002/diff/1/base/files/important_file_w... File base/files/important_file_writer.h (right): https://codereview.chromium.org/2920223002/diff/1/base/files/important_file_w... base/files/important_file_writer.h:58: std::string histogram_suffix = std::string()); On 2017/06/05 16:50:33, sky wrote: > const std::string& on all of these. Or maybe just pass as const char* since it's always a literal, so we can avoid creating the string temporary at all hopfeully.
Thank you for the valuable comments. Did my best to improve the code. https://codereview.chromium.org/2920223002/diff/1/base/files/important_file_w... File base/files/important_file_writer.cc (right): https://codereview.chromium.org/2920223002/diff/1/base/files/important_file_w... base/files/important_file_writer.cc:58: DynamicUmaHistogramEnumeration(const char* histogram_name, On 2017/06/05 18:17:30, rkaplow wrote: > can you use the function version from > https://cs.chromium.org/chromium/src/base/metrics/histogram_functions.h?q=his... > ? Acknowledged. https://codereview.chromium.org/2920223002/diff/1/base/files/important_file_w... File base/files/important_file_writer.h (right): https://codereview.chromium.org/2920223002/diff/1/base/files/important_file_w... base/files/important_file_writer.h:58: std::string histogram_suffix = std::string()); On 2017/06/05 18:23:59, dcheng wrote: > On 2017/06/05 16:50:33, sky wrote: > > const std::string& on all of these. > > Or maybe just pass as const char* since it's always a literal, so we can avoid > creating the string temporary at all hopfeully. Acknowledged. https://codereview.chromium.org/2920223002/diff/1/base/files/important_file_w... base/files/important_file_writer.h:151: std::string histogram_suffix_; On 2017/06/05 16:50:33, sky wrote: > const Acknowledged.
My personal opinion is that this is a lot of complexity, and I'm not sure it's the right tradeoff. Part of me just isn't super happy to see that the new helper needs to use some template magic to try to guarantee safety. One alternate approach would be to provide a status callback that interested callers could use to log the result--and otherwise just log a normal UMA. Would this be a reasonable thing to do? Then we can just use the standard UMA_HISTOGRAM_ENUMERATION macros. https://codereview.chromium.org/2920223002/diff/20001/base/files/important_fi... File base/files/important_file_writer.cc (right): https://codereview.chromium.org/2920223002/diff/20001/base/files/important_fi... base/files/important_file_writer.cc:66: strlen(histogram_suffix) + 1; // Also account for a dot. To be honest, I don't know that it's worth the effort to calculate the length to reserve, but maybe someone will have an alternate opinion. I think it'd be easier to read if it was just += / append() https://codereview.chromium.org/2920223002/diff/20001/base/files/important_fi... base/files/important_file_writer.cc:100: path, *data, histogram_suffix.c_str()); No need to call c_str() for this
Thank you for the comments and remarks! Agree that template magic is probably not the right solution for the local helper. Replaced the template condition with static assert. Unfortunately the solution with a status callback would not be satisfactory, since one might expect mass automated statistics on file failures. Certainly we would be able to delegate suffixed histogram filling to the interested clients, but the latter would seem to lead to unnecessary code duplication and lack for some kind of generality. Base extension would be a generalized solution. https://codereview.chromium.org/2920223002/diff/20001/base/files/important_fi... File base/files/important_file_writer.cc (right): https://codereview.chromium.org/2920223002/diff/20001/base/files/important_fi... base/files/important_file_writer.cc:66: strlen(histogram_suffix) + 1; // Also account for a dot. On 2017/06/07 22:56:39, dcheng wrote: > To be honest, I don't know that it's worth the effort to calculate the length to > reserve, but maybe someone will have an alternate opinion. I think it'd be > easier to read if it was just += / append() I agree that one additional reallocation is worth the better readability of the code. Hopefully it doesn't look like premature pessimization. Fixed. https://codereview.chromium.org/2920223002/diff/20001/base/files/important_fi... base/files/important_file_writer.cc:100: path, *data, histogram_suffix.c_str()); On 2017/06/07 22:56:39, dcheng wrote: > No need to call c_str() for this Done.
lgtm
The CQ bit was checked by [email protected] to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at: https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was unchecked by [email protected]
Dry run: Try jobs failed on following builders: linux_chromium_rel_ng on master.tryserver.chromium.linux (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.linux/builders/linux_chromium_...)
The CQ bit was checked by [email protected] to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at: https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was unchecked by [email protected]
Dry run: This issue passed the CQ dry run.
The CQ bit was checked by [email protected]
CQ is trying da patch. Follow status at: https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was unchecked by [email protected]
Try jobs failed on following builders: chromium_presubmit on master.tryserver.chromium.linux (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.linux/builders/chromium_presub...)
[email protected] changed reviewers: + [email protected]
ptal dcheng, please review the changles in important_file_writer. blundell, please check bookmark_storage.cc and give owner's approval if possible. afakhry: please check feedback_report.cc and give owner's approval if possible.
//components/bookmarks lgtm
feedback_report.cc lgtm
Just small nits around the use of StringPiece. I don't feel strongly about the arguments to the constructor, but fixing WriteFileAtomically() and the UMA helper would be nice. https://codereview.chromium.org/2920223002/diff/40001/base/files/important_fi... File base/files/important_file_writer.cc (right): https://codereview.chromium.org/2920223002/diff/40001/base/files/important_fi... base/files/important_file_writer.cc:58: const char* histogram_suffix, And histogram_suffix would use const std::string& as well, since it starts as a std::string anyway. https://codereview.chromium.org/2920223002/diff/40001/base/files/important_fi... File base/files/important_file_writer.h (right): https://codereview.chromium.org/2920223002/diff/40001/base/files/important_fi... base/files/important_file_writer.h:58: StringPiece histogram_suffix = StringPiece()); Looking around, it seems like the only time |data| and |histogram_suffix| are not already std::string objects is in tests. StringPiece construction is pretty inexpensive, but it's not free. Let's just pass these by const std::string& here. https://codereview.chromium.org/2920223002/diff/40001/base/files/important_fi... base/files/important_file_writer.h:67: StringPiece histogram_suffix = StringPiece()); For this: While string piece is nice when the input can be either std::string or const char*, it seems like const char* would be sufficient here. Though I guess it would make suffix checking slightly more complex in the constructor since this would need a null check.
dcheng, Thanks for valuable suggestions and comments! Ptal. https://codereview.chromium.org/2920223002/diff/40001/base/files/important_fi... File base/files/important_file_writer.cc (right): https://codereview.chromium.org/2920223002/diff/40001/base/files/important_fi... base/files/important_file_writer.cc:58: const char* histogram_suffix, On 2017/06/14 19:56:13, dcheng wrote: > And histogram_suffix would use const std::string& as well, since it starts as a > std::string anyway. Done. https://codereview.chromium.org/2920223002/diff/40001/base/files/important_fi... File base/files/important_file_writer.h (right): https://codereview.chromium.org/2920223002/diff/40001/base/files/important_fi... base/files/important_file_writer.h:58: StringPiece histogram_suffix = StringPiece()); On 2017/06/14 19:56:13, dcheng wrote: > Looking around, it seems like the only time |data| and |histogram_suffix| are > not already std::string objects is in tests. StringPiece construction is pretty > inexpensive, but it's not free. > > Let's just pass these by const std::string& here. Thanks! Replaced |histogram_suffix| type with const std::string&. However can't replace |data| type because of some places having got StringPiece passed (e.g. base/metrics/persistent_histogram_allocator.cc@965, chrome/installer/setup/persistent_histogram_storage.cc@59). https://codereview.chromium.org/2920223002/diff/40001/base/files/important_fi... base/files/important_file_writer.h:67: StringPiece histogram_suffix = StringPiece()); On 2017/06/14 19:56:13, dcheng wrote: > For this: While string piece is nice when the input can be either std::string or > const char*, it seems like const char* would be sufficient here. > > Though I guess it would make suffix checking slightly more complex in the > constructor since this would need a null check. Done.
The CQ bit was checked by [email protected]
The patchset sent to the CQ was uploaded after l-g-t-m from [email protected], [email protected], [email protected] Link to the patchset: https://codereview.chromium.org/2920223002/#ps60001 (title: "Fix histogram suffix to use string reference instead of StringPiece.")
CQ is trying da patch. Follow status at: https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was unchecked by [email protected]
The CQ bit was checked by [email protected]
The CQ bit was unchecked by [email protected]
https://codereview.chromium.org/2920223002/diff/60001/base/files/important_fi... File base/files/important_file_writer.cc (right): https://codereview.chromium.org/2920223002/diff/60001/base/files/important_fi... base/files/important_file_writer.cc:126: const std::string& histogram_suffix) { Since this will change to a StringPiece though, let's just do the string conversion once here (or just pass StringPiece directly to UmaHistogramExactLinearWithSuffix). I would prefer just passing StringPiece. https://codereview.chromium.org/2920223002/diff/60001/base/files/important_fi... File base/files/important_file_writer.h (right): https://codereview.chromium.org/2920223002/diff/60001/base/files/important_fi... base/files/important_file_writer.h:59: const std::string& histogram_suffix = std::string()); OK, I misread the code and thought this was an internal helper. As this is used by code outside ImportantFileWriter, this should be StringPIece =/ Sorry for the churn. =(
dcheng, thanks for additional suggestions! Reverted the code to use StringPiece. Furthermore, added a couple of minor optimizations to UmaHistogramExactLinearWithSuffix to use the precalculated string length in StringPiece and thus to eliminate unnecessary suffix length computation each time UmaHistogramExactLinearWithSuffix is called. https://codereview.chromium.org/2920223002/diff/60001/base/files/important_fi... File base/files/important_file_writer.cc (right): https://codereview.chromium.org/2920223002/diff/60001/base/files/important_fi... base/files/important_file_writer.cc:126: const std::string& histogram_suffix) { On 2017/06/19 20:27:55, dcheng wrote: > Since this will change to a StringPiece though, let's just do the string > conversion once here (or just pass StringPiece directly to > UmaHistogramExactLinearWithSuffix). I would prefer just passing StringPiece. Done. https://codereview.chromium.org/2920223002/diff/60001/base/files/important_fi... File base/files/important_file_writer.h (right): https://codereview.chromium.org/2920223002/diff/60001/base/files/important_fi... base/files/important_file_writer.h:59: const std::string& histogram_suffix = std::string()); On 2017/06/19 20:27:55, dcheng wrote: > OK, I misread the code and thought this was an internal helper. > > As this is used by code outside ImportantFileWriter, this should be StringPIece > =/ > > Sorry for the churn. =( Done.
LGTM with a nit. Thanks! https://codereview.chromium.org/2920223002/diff/80001/base/files/important_fi... File base/files/important_file_writer.cc (right): https://codereview.chromium.org/2920223002/diff/80001/base/files/important_fi... base/files/important_file_writer.cc:66: histogram_full_name.append(1, '.'); I suspect that since basic_string is all in headers, just writing the simple thing will likely optimize well enough. I would suggest writing the simple thing here and just append "." (see https://godbolt.org/g/dGkVnC, which shows that clang does do this optimization)
Fixed the nit, thanks! https://codereview.chromium.org/2920223002/diff/80001/base/files/important_fi... File base/files/important_file_writer.cc (right): https://codereview.chromium.org/2920223002/diff/80001/base/files/important_fi... base/files/important_file_writer.cc:66: histogram_full_name.append(1, '.'); On 2017/06/20 08:25:34, dcheng wrote: > I suspect that since basic_string is all in headers, just writing the simple > thing will likely optimize well enough. I would suggest writing the simple thing > here and just append "." > > (see https://godbolt.org/g/dGkVnC, which shows that clang does do this > optimization) Thanks! Indeed, since strlen is intrinsic, a clever compiler is likely to inline the pointer-only version called with a constant string literal, replacing it with a pointer-and-size version; no need to make the code less readable. Fixed.
The CQ bit was checked by [email protected]
The patchset sent to the CQ was uploaded after l-g-t-m from [email protected], [email protected], [email protected], [email protected] Link to the patchset: https://codereview.chromium.org/2920223002/#ps100001 (title: "Minor fix of std::string::append.")
CQ is trying da patch. Follow status at: https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
CQ is committing da patch. Bot data: {"patchset_id": 100001, "attempt_start_ts": 1497949002423240, "parent_rev": "274c1c34752f6d383c6dec38c785a9be654bf05e", "commit_rev": "4ae8d1757f7b5a0cb85497205a80ed2a572a5165"}
Message was sent while issue was closed.
Description was changed from ========== Add additional histograms with suffixes to ImportantFileWriter. Additional histograms are added to the ImportantFileWriter code to monitor system error codes, and find out exact reasons for failures. Furthermore, histogram suffixes are introduced to discriminate users of the ImportantFileWriter code. As an example, two services (BookmarkStorage and FeedbackReport) are now using the suffixes, which can be further utilized in other services. The original ImportantFile.TempFileFailures histogram will also be dynamically suffixed. [email protected] TEST=New histograms and suffixes will appear. BUG= ========== to ========== Add additional histograms with suffixes to ImportantFileWriter. Additional histograms are added to the ImportantFileWriter code to monitor system error codes, and find out exact reasons for failures. Furthermore, histogram suffixes are introduced to discriminate users of the ImportantFileWriter code. As an example, two services (BookmarkStorage and FeedbackReport) are now using the suffixes, which can be further utilized in other services. The original ImportantFile.TempFileFailures histogram will also be dynamically suffixed. [email protected] TEST=New histograms and suffixes will appear. BUG= Review-Url: https://codereview.chromium.org/2920223002 Cr-Commit-Position: refs/heads/master@{#480783} Committed: https://chromium.googlesource.com/chromium/src/+/4ae8d1757f7b5a0cb85497205a80... ==========
Message was sent while issue was closed.
Committed patchset #6 (id:100001) as https://chromium.googlesource.com/chromium/src/+/4ae8d1757f7b5a0cb85497205a80... |