From 0409b8aa646ea5192cd91976a89f71024129344c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 20 Jun 2024 06:01:55 +0200 Subject: Adding upstream version 127.0.1. Signed-off-by: Daniel Baumann --- toolkit/components/glean/ipc/FOGIPC.cpp | 65 +++++++++++++++++++++++++++- toolkit/components/processtools/metrics.yaml | 16 +++++++ toolkit/moz.configure | 2 +- 3 files changed, 81 insertions(+), 2 deletions(-) (limited to 'toolkit') diff --git a/toolkit/components/glean/ipc/FOGIPC.cpp b/toolkit/components/glean/ipc/FOGIPC.cpp index e44cf3e863..4ce009e4fa 100644 --- a/toolkit/components/glean/ipc/FOGIPC.cpp +++ b/toolkit/components/glean/ipc/FOGIPC.cpp @@ -37,6 +37,10 @@ #include "nsTArray.h" #include "nsThreadUtils.h" +#if defined(__APPLE__) && defined(__aarch64__) +# define HAS_PROCESS_ENERGY +#endif + using mozilla::dom::ContentParent; using mozilla::gfx::GPUChild; using mozilla::gfx::GPUProcessManager; @@ -76,6 +80,29 @@ struct ProcessingTimeMarker { } }; +#ifdef HAS_PROCESS_ENERGY +struct ProcessEnergyMarker { + static constexpr Span MarkerTypeName() { + return MakeStringSpan("ProcessEnergy"); + } + static void StreamJSONMarkerData(baseprofiler::SpliceableJSONWriter& aWriter, + int64_t aUWh, + const ProfilerString8View& aType) { + aWriter.IntProperty("energy", aUWh); + aWriter.StringProperty("label", aType); + } + static MarkerSchema MarkerTypeDisplay() { + using MS = MarkerSchema; + MS schema{MS::Location::MarkerChart, MS::Location::MarkerTable}; + schema.AddKeyLabelFormat("energy", "Energy (µWh)", MS::Format::Integer); + schema.SetTooltipLabel("{marker.name} - {marker.data.label}"); + schema.SetTableLabel( + "{marker.name} - {marker.data.label}: {marker.data.energy}µWh"); + return schema; + } +}; +#endif + } // namespace geckoprofiler::markers namespace mozilla::glean { @@ -248,8 +275,26 @@ void GetTrackerType(nsAutoCString& aTrackerType) { } } +#ifdef HAS_PROCESS_ENERGY +static int64_t GetTaskEnergy() { + task_power_info_v2_data_t task_power_info; + mach_msg_type_number_t count = TASK_POWER_INFO_V2_COUNT; + kern_return_t kr = task_info(mach_task_self(), TASK_POWER_INFO_V2, + (task_info_t)&task_power_info, &count); + if (kr != KERN_SUCCESS) { + return 0; + } + + // task_energy is in nanojoules. We want microwatt-hours. + return task_power_info.task_energy / 3.6 / 1e6; +} +#endif + void RecordPowerMetrics() { static uint64_t previousCpuTime = 0, previousGpuTime = 0; +#ifdef HAS_PROCESS_ENERGY + static int64_t previousProcessEnergy = 0; +#endif uint64_t cpuTime, newCpuTime = 0; if (NS_SUCCEEDED(GetCpuTimeSinceProcessStartInMs(&cpuTime)) && @@ -265,7 +310,16 @@ void RecordPowerMetrics() { newGpuTime = gpuTime - previousGpuTime; } - if (!newCpuTime && !newGpuTime) { +#ifdef HAS_PROCESS_ENERGY + int64_t processEnergy = GetTaskEnergy(); + int64_t newProcessEnergy = processEnergy - previousProcessEnergy; +#endif + + if (!newCpuTime && !newGpuTime +#ifdef HAS_PROCESS_ENERGY + && newProcessEnergy <= 0 +#endif + ) { // Nothing to record. return; } @@ -358,6 +412,15 @@ void RecordPowerMetrics() { previousGpuTime += newGpuTime; } +#ifdef HAS_PROCESS_ENERGY + if (newProcessEnergy) { + power::energy_per_process_type.Get(type).Add(newProcessEnergy); + PROFILER_MARKER("Process Energy", OTHER, {}, ProcessEnergyMarker, + newProcessEnergy, type); + previousProcessEnergy += newProcessEnergy; + } +#endif + profiler_record_wakeup_count(type); } diff --git a/toolkit/components/processtools/metrics.yaml b/toolkit/components/processtools/metrics.yaml index 6efbd22fa5..1d6e6bf133 100644 --- a/toolkit/components/processtools/metrics.yaml +++ b/toolkit/components/processtools/metrics.yaml @@ -112,6 +112,22 @@ power: expires: never telemetry_mirror: POWER_GPU_TIME_BOGUS_VALUES + energy_per_process_type: + type: labeled_counter + description: > + How much energy (in µWh) has been used, broken down by process type. + Only available on Apple Silicon. + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1898057 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1898057 + data_sensitivity: + - technical + notification_emails: + - florian@mozilla.com + expires: never + labels: *per_process_type_labels + wakeups_per_process_type: type: labeled_counter description: > diff --git a/toolkit/moz.configure b/toolkit/moz.configure index 6ad16dc1b7..7282b80d81 100644 --- a/toolkit/moz.configure +++ b/toolkit/moz.configure @@ -3353,7 +3353,7 @@ with only_when(compile_environment): set_config("MOZ_TREE_PIXMAN", True, when=in_tree_pixman) set_define("MOZ_TREE_PIXMAN", True, when=in_tree_pixman) - pkg_check_modules("MOZ_PIXMAN", "pixman-1 >= 0.36.0", when="--enable-system-pixman") + pkg_check_modules("MOZ_PIXMAN", "pixman-1 >= 0.40.0", when="--enable-system-pixman") # Set MOZ_PIXMAN_CFLAGS to an explicit empty value when --enable-system-pixman is *not* used, # for layout/style/extra-bindgen-flags set_config("MOZ_PIXMAN_CFLAGS", [], when=in_tree_pixman) -- cgit v1.2.3