-
Notifications
You must be signed in to change notification settings - Fork 34
Bug 1716952 - Implement the Memory Distribution Metric #1514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rosahbruno
merged 10 commits into
mozilla:main
from
rosahbruno:1716952-memory-distribution-metric
Oct 6, 2022
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e973fa4
Implement Memory Distribution metric type
rosahbruno 64a8706
Update changelog for #1514
rosahbruno f2ceff3
Add missing configs for memory_distribution metric
rosahbruno d6d4192
Update memory_distribution error type for samples larger than 1TB
rosahbruno 839145f
Update glean/src/core/metrics/time_unit.ts
rosahbruno e4f0c29
Update glean/tests/integration/schema/metrics.yaml
rosahbruno e74a592
Update glean/tests/integration/schema/metrics.yaml
rosahbruno c20ddad
Update glean/src/core/metrics/distributions.ts
rosahbruno df3b039
Rename negativeDuration to negativeSample to be more contextually cor…
rosahbruno 335a5a8
Update function comments to be more contextually correct
rosahbruno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| import type { Histogram } from "../../histogram/histogram"; | ||
| import type { JSONValue } from "../utils"; | ||
|
|
||
| export interface DistributionData { | ||
| // A map containing the bucket index mapped to the accumulated count. | ||
| // | ||
| // This can contain buckets with a count of `0`. | ||
| values: Record<number, number>; | ||
|
|
||
| // The accumulated sum of all the samples in the distribution. | ||
| sum: number; | ||
|
|
||
| // The number of entries in the histogram. | ||
| count: number; | ||
| } | ||
|
|
||
| /** | ||
| * Create a snapshot of the histogram with a time unit. | ||
| * | ||
| * Utility function for testing. | ||
| * | ||
| * @param hist Histogram to get the snapshot of. | ||
| * @returns Snapshot of the current histogram. | ||
| */ | ||
| export function snapshot(hist: Histogram): DistributionData { | ||
| const snapshotValues = hist.snapshotValues(); | ||
|
|
||
| const utilizedValues: Record<number, number> = {}; | ||
| Object.entries(snapshotValues).forEach(([key, value]) => { | ||
| const numericKey = Number(key); | ||
| if (value > 0 && !isNaN(numericKey)) { | ||
| utilizedValues[numericKey] = value; | ||
| } | ||
| }); | ||
|
|
||
| return { | ||
| count: hist.count, | ||
| values: utilizedValues, | ||
| sum: hist.sum, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Takes the previous values and casts as a `number[]` or creates a new empty `number[]`. We store | ||
| * previous values as an array so that we can always reconstruct our histogram. We | ||
| * are unable to store complex objects in Glean as they must be JSON parse-able objects. | ||
| * | ||
| * @param jsonValue Will always be either undefined or a `number[]`. | ||
| * @returns An array of previous values or an empty array if nothing was previously stored. | ||
| */ | ||
| export function extractAccumulatedValuesFromJsonValue(jsonValue?: JSONValue): number[] { | ||
| let values: number[]; | ||
| if (jsonValue) { | ||
| values = jsonValue as number[]; | ||
| } else { | ||
| values = []; | ||
| } | ||
|
|
||
| return values; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| export enum MemoryUnit { | ||
| // 1 byte | ||
| Byte = "byte", | ||
| // 2^10 bytes | ||
| Kilobyte = "kilobyte", | ||
| // 2^20 bytes | ||
| Megabyte = "megabyte", | ||
| // 2^30 bytes | ||
| Gigabyte = "gigabyte", | ||
| } | ||
|
|
||
| /** | ||
| * Converts a value in a given unit to bytes. | ||
| * | ||
| * @param value The value to convert. | ||
| * @param memoryUnit The `MemoryUnit` to convert from. | ||
| * @returns The integer representation of the byte value. | ||
| */ | ||
| export function convertMemoryUnitToBytes(value: number, memoryUnit: MemoryUnit): number { | ||
| switch (memoryUnit) { | ||
| case MemoryUnit.Byte: | ||
| return value; | ||
| case MemoryUnit.Kilobyte: | ||
| return value * (2 ** 10); | ||
| case MemoryUnit.Megabyte: | ||
| return value * (2 ** 20); | ||
| case MemoryUnit.Gigabyte: | ||
| return value * (2 ** 30); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.