Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions ui/packages/shared/profile/src/ProfileFlameChart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ import {TimeUnits, formatDate, formatDuration} from '@parca/utilities';

import ProfileFlameGraph, {validateFlameChartQuery} from '../ProfileFlameGraph';
import {boundsFromProfileSource} from '../ProfileFlameGraph/FlameGraphArrow/utils';
import {MergedProfileSource, ProfileSource, timeFormat} from '../ProfileSource';
import {
MergedProfileSource,
ProfileSource,
isMergedProfileSource,
timeFormat,
} from '../ProfileSource';
import {useProfileFilters} from '../ProfileView/components/ProfileFilters/useProfileFilters';
import type {SamplesData} from '../ProfileView/types/visualization';
import {flamechartDimensionParser} from '../hooks/urlParsers';
Expand Down Expand Up @@ -83,7 +88,7 @@ const createFilteredProfileSource = (
profileSource: ProfileSource,
selectedTimeframe: {labels: LabelSet; bounds: NumberDuo}
): ProfileSource | null => {
if (!(profileSource instanceof MergedProfileSource)) {
if (!isMergedProfileSource(profileSource)) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '@parca/store';
import {divide, getLastItem, valueFormatter} from '@parca/utilities';

import {MergedProfileSource, ProfileSource} from '../../ProfileSource';
import {ProfileSource, isMergedProfileSource} from '../../ProfileSource';
import {BigIntDuo, hexifyAddress} from '../../utils';
import {
FIELD_DEPTH,
Expand Down Expand Up @@ -115,7 +115,7 @@ export const boundsFromProfileSource = (profileSource?: ProfileSource): BigIntDu
return [0n, 1n];
}

if (!(profileSource instanceof MergedProfileSource)) {
if (!isMergedProfileSource(profileSource)) {
return [0n, 1n];
}

Expand Down
26 changes: 26 additions & 0 deletions ui/packages/shared/profile/src/ProfileSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,32 @@ export class MergedProfileSelection implements ProfileSelection {
}
}

// Type tag carried on instances so we can identify them reliably even when the
// class gets duplicated across bundle chunks (prod builds sometimes end up with
// two copies of the same class, making `instanceof` unreliable).
export const PROFILE_SOURCE_TYPE_MERGED = 'merged' as const;
export const PROFILE_SOURCE_TYPE_DIFF = 'diff' as const;

const getProfileSourceType = (source: ProfileSource | null | undefined): string | undefined => {
if (source == null) return undefined;
const tag = (source as {profileSourceType?: unknown}).profileSourceType;
return typeof tag === 'string' ? tag : undefined;
};

export const isMergedProfileSource = (
source: ProfileSource | null | undefined
): source is MergedProfileSource => {
return getProfileSourceType(source) === PROFILE_SOURCE_TYPE_MERGED;
};

export const isProfileDiffSource = (
source: ProfileSource | null | undefined
): source is ProfileDiffSource => {
return getProfileSourceType(source) === PROFILE_SOURCE_TYPE_DIFF;
};

export class ProfileDiffSource implements ProfileSource {
readonly profileSourceType = PROFILE_SOURCE_TYPE_DIFF;
a: ProfileSource;
b: ProfileSource;
profileType: ProfileType;
Expand Down Expand Up @@ -194,6 +219,7 @@ function nanosToTimestamp(nanos: bigint): Timestamp {
}

export class MergedProfileSource implements ProfileSource {
readonly profileSourceType = PROFILE_SOURCE_TYPE_MERGED;
mergeFrom: bigint;
mergeTo: bigint;
query: Query;
Expand Down
8 changes: 2 additions & 6 deletions ui/packages/shared/utilities/src/bigint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ export const scaleLinear = (
console.log('domainRange', domainRange, rangeRange, divide(rangeRange, domainRange));
}

// guard 0n to avoid BigInt(Infinity).
const rate =
domainRange === 0n ? 0n : BigInt(Math.round(divide(rangeRange, domainRange) * MULTIPLE));
// rate * MULTIPLE to retain the decimal places in BigInt format, then divide by MULTIPLE to get the final result
const rate = BigInt(Math.round(divide(rangeRange, domainRange) * MULTIPLE));

const func = (x: bigint): number => {
if (debugLog) {
Expand All @@ -75,9 +74,6 @@ export const scaleLinear = (
};

func.ticks = (count = 5): bigint[] => {
if (count <= 1 || domainRange === 0n) {
return [domainMin];
}
const step = domainRange / BigInt(count - 1);
const ticks: bigint[] = [];
for (let i = 0; i < count; i++) {
Expand Down
Loading