New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 705171 link

Starred by 1 user

Issue metadata

Status: Started
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Bug



Sign in to add a comment

Make UMA histogram enumeration macros handle scoped enums

Project Member Reported by dcheng@chromium.org, Mar 25 2017

Issue description

Right now, this doesn't appear to compile without static casts.
 

Comment 1 by dcheng@chromium.org, Mar 25 2017

Cc: rkaplow@chromium.org isherman@chromium.org

Comment 2 by wychen@chromium.org, Mar 25 2017

In terms of type safety, scoped enum is better than plain enum, but there's one pitfall: the underlying type doesn't get wide automatically.

This would silently fail:

enum class Name {
  A = 1LL<<40
};

Name::A would surprisingly be 0.

On the other hand:

enum {
  LARGE = 1LL<<40
};

LARGE would be wide enough automatically.
Cc: -mpear...@chromium.org
I agree this would be a nice feature if possible.  I get sick of doing histogram reviews and having to see/approve them with static_casts because the implementer decided to use an enum class.

Comment 4 by wychen@chromium.org, Mar 27 2017

When this is fixed, it might also make sense to clean up the static casts no longer needed.

Comment 5 by dcheng@chromium.org, Mar 27 2017

Yes, that's already on my TODO list, and is easily to fix incrementally.
Project Member

Comment 6 by bugdroid1@chromium.org, Mar 30 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/f6f4e494cd797690b41c4359c08bc33d49811759

commit f6f4e494cd797690b41c4359c08bc33d49811759
Author: dcheng <dcheng@chromium.org>
Date: Thu Mar 30 23:55:57 2017

Make UMA_HISTOGRAM_ENUMERATION work with scoped enums.

Internally, the macro does some math on the macro arguments, which
doesn't interact well with scoped enums. To work around this, the
internal macro now explicitly casts the enum values to integral
types.

To ensure some modicum of safety, there are new static asserts to
verify that the enum values are in range of HistogramBase::Sample.
This breaks code that was using UMA_HISTOGRAM_ENUMERATION to record
things that aren't C++ enumerations, so switch those to use
UMA_HISTOGRAM_EXACT_LINEAR as well.

BUG=705171
R=rkaplow,jochen,mrefaat,sky,thestig,xhwang
TBR=mukai

Review-Url: https://codereview.chromium.org/2776853002
Cr-Commit-Position: refs/heads/master@{#460938}

[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/ash/common/shelf/shelf_view.cc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/ash/common/shelf/shelf_view.h
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/base/metrics/histogram_macros.h
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/base/metrics/histogram_macros_internal.h
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/base/metrics/histogram_macros_unittest.cc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/base/metrics/histogram_unittest.nc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/chrome/browser/chromeos/first_run/first_run_controller.cc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/chrome/browser/chromeos/login/screens/user_image_screen.cc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.cc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/chrome/browser/content_settings/web_site_settings_uma_util.cc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/chrome/browser/devtools/devtools_ui_bindings.cc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/chrome/browser/extensions/installed_loader.cc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/chrome/browser/renderer_context_menu/render_view_context_menu.cc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/chrome/browser/safe_browsing/incident_reporting/environment_data_collection_win.cc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/chrome/browser/ui/page_info/page_info.cc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/chrome/browser/ui/webui/options/chromeos/change_picture_options_handler.cc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/chrome/browser/ui/webui/settings/chromeos/change_picture_handler.cc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/components/content_settings/core/browser/host_content_settings_map.cc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/components/history/core/browser/history_backend.cc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/components/user_prefs/tracked/tracked_preference_helper.cc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/content/browser/gpu/gpu_data_manager_impl_private.cc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/content/renderer/media/rtc_peer_connection_handler.cc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/ios/chrome/browser/desktop_promotion/desktop_promotion_sync_observer.cc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/media/blink/resource_multibuffer_data_provider.cc
[modify] https://crrev.com/f6f4e494cd797690b41c4359c08bc33d49811759/ui/events/blink/input_handler_proxy.cc

Sign in to add a comment