Skip to content

Commit

Permalink
[Profiling] Fixing CO2 and Cost calcs (elastic#172608)
Browse files Browse the repository at this point in the history
We have found some bugs while testing the new CO2 and Cost calculations.
  • Loading branch information
cauemarcondes authored Dec 7, 2023
1 parent 6be8e5e commit a324547
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,6 @@ export const baseFlamegraph: BaseFlameGraph = {
Size: 35,
SamplingRate: 1,
SelfCPU: 7,
SelfAnnualCO2Tons: 0.0013627551116480942,
TotalAnnualCO2Tons: 0.04769642890768329,
SelfAnnualCostsUSD: 61.30240940376492,
TotalAnnualCostsUSD: 2145.5843291317715,
TotalCPU: 245,
TotalSamples: 7,
TotalSeconds: 4.980000019073486,
Expand Down
10 changes: 0 additions & 10 deletions packages/kbn-profiling-utils/common/flamegraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ export interface BaseFlameGraph {
AnnualCO2TonsInclusive: number[];
AnnualCostsUSDInclusive: number[];
AnnualCostsUSDExclusive: number[];
SelfAnnualCO2Tons: number;
TotalAnnualCO2Tons: number;
SelfAnnualCostsUSD: number;
TotalAnnualCostsUSD: number;
}

/** Elasticsearch flamegraph */
Expand All @@ -77,8 +73,6 @@ export interface ElasticFlameGraph
TotalAnnualCO2KgsItems: number[];
SelfAnnualCostsUSDItems: number[];
TotalAnnualCostsUSDItems: number[];
SelfAnnualCO2Kgs: number;
TotalAnnualCO2Kgs: number;
}

/**
Expand Down Expand Up @@ -119,10 +113,6 @@ export function createFlameGraph(base: BaseFlameGraph): ElasticFlameGraph {
TotalAnnualCO2KgsItems: base.AnnualCO2TonsInclusive.map(convertTonsToKgs),
SelfAnnualCostsUSDItems: base.AnnualCostsUSDExclusive,
TotalAnnualCostsUSDItems: base.AnnualCostsUSDInclusive,
SelfAnnualCO2Kgs: convertTonsToKgs(base.SelfAnnualCO2Tons),
TotalAnnualCO2Kgs: convertTonsToKgs(base.TotalAnnualCO2Tons),
SelfAnnualCostsUSD: base.SelfAnnualCostsUSD,
TotalAnnualCostsUSD: base.TotalAnnualCostsUSD,
};

const rootFrameGroupID = createFrameGroupID(
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-profiling-utils/common/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ export function createTopNFunctions({

const sumSelfCPU = sumBy(framesAndCountsAndIds, 'CountExclusive');
const sumTotalCPU = sumBy(framesAndCountsAndIds, 'CountInclusive');
const totalAnnualCO2Kgs = sumBy(framesAndCountsAndIds, 'totalAnnualCO2kgs');
const totalAnnualCostUSD = sumBy(framesAndCountsAndIds, 'totalAnnualCostUSD');
const totalAnnualCO2Kgs = sumBy(framesAndCountsAndIds, 'selfAnnualCO2kgs');
const totalAnnualCostUSD = sumBy(framesAndCountsAndIds, 'selfAnnualCostUSD');

return {
TotalCount: totalCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,6 @@ export const baseFlamegraph: BaseFlameGraph = {
SamplingRate: 1,
SelfCPU: 7,
TotalCPU: 245,
SelfAnnualCO2Tons: 0.0013627551116480942,
TotalAnnualCO2Tons: 0.04769642890768329,
SelfAnnualCostsUSD: 61.30240940376492,
TotalAnnualCostsUSD: 2145.5843291317715,
TotalSamples: 7,
TotalSeconds: 4.980000019073486,
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ describe('Differential Functions page', () => {
cy.wait('@getTopNFunctions');
[
{ id: 'overallPerformance', value: '0%' },
{ id: 'annualizedCo2', value: '2.5k lbs / 1.13k kg' },
{ id: 'annualizedCost', value: '$10.66k' },
{ id: 'annualizedCo2', value: '74.49 lbs / 33.79 kg' },
{ id: 'annualizedCost', value: '$318.32' },
{ id: 'totalNumberOfSamples', value: '513' },
].forEach((item) => {
cy.get(`[data-test-subj="${item.id}_value"]`).contains(item.value);
Expand All @@ -50,8 +50,8 @@ describe('Differential Functions page', () => {
cy.wait('@getTopNFunctions');
[
{ id: 'overallPerformance', value: '0%' },
{ id: 'annualizedCo2', value: '0 lbs / 0 kg', comparisonValue: '2.5k lbs / 1.13k kg' },
{ id: 'annualizedCost', value: '$0', comparisonValue: '$10.66k' },
{ id: 'annualizedCo2', value: '0 lbs / 0 kg', comparisonValue: '74.49 lbs / 33.79 kg' },
{ id: 'annualizedCost', value: '$0', comparisonValue: '$318.32' },
{ id: 'totalNumberOfSamples', value: '0', comparisonValue: '15,390' },
].forEach((item) => {
cy.get(`[data-test-subj="${item.id}_value"]`).contains(item.value);
Expand All @@ -76,14 +76,14 @@ describe('Differential Functions page', () => {
{ id: 'overallPerformance', value: '65.89%', icon: 'sortUp_success' },
{
id: 'annualizedCo2',
value: '2.5k lbs / 1.13k kg',
comparisonValue: '548.84 lbs / 248.95 kg (78.01%',
value: '74.49 lbs / 33.79 kg',
comparisonValue: '25.41 lbs / 11.53 kg (65.89%)',
icon: 'comparison_sortUp_success',
},
{
id: 'annualizedCost',
value: '$10.66k',
comparisonValue: '$2.35k (78.01%)',
value: '$318.32',
comparisonValue: '$108.59 (65.89%)',
icon: 'comparison_sortUp_success',
},
{
Expand Down Expand Up @@ -116,14 +116,14 @@ describe('Differential Functions page', () => {
{ id: 'overallPerformance', value: '193.14%', icon: 'sortDown_danger' },
{
id: 'annualizedCo2',
value: '548.84 lbs / 248.95 kg',
comparisonValue: '2.5k lbs / 1.13k kg (354.66%)',
value: '25.41 lbs / 11.53 kg',
comparisonValue: '74.49 lbs / 33.79 kg (193.14%)',
icon: 'comparison_sortDown_danger',
},
{
id: 'annualizedCost',
value: '$2.35k',
comparisonValue: '$10.66k (354.66%)',
value: '$108.59',
comparisonValue: '$318.32 (193.14%)',
icon: 'comparison_sortDown_danger',
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ export function DifferentialFlameGraphsView() {
totalCPU: state.data.primaryFlamegraph.TotalCPU,
totalCount: state.data.primaryFlamegraph.TotalSamples,
scaleFactor: isNormalizedByTime ? baselineTime : baseline,
totalAnnualCO2Kgs: state.data.primaryFlamegraph.TotalAnnualCO2Kgs,
totalAnnualCostUSD: state.data.primaryFlamegraph.TotalAnnualCostsUSD,
totalAnnualCO2Kgs: state.data.primaryFlamegraph.TotalAnnualCO2KgsItems[0],
totalAnnualCostUSD: state.data.primaryFlamegraph.TotalAnnualCostsUSDItems[0],
}
: undefined
}
Expand All @@ -144,8 +144,8 @@ export function DifferentialFlameGraphsView() {
totalCPU: state.data.comparisonFlamegraph.TotalCPU,
totalCount: state.data.comparisonFlamegraph.TotalSamples,
scaleFactor: isNormalizedByTime ? comparisonTime : comparison,
totalAnnualCO2Kgs: state.data.comparisonFlamegraph.TotalAnnualCO2Kgs,
totalAnnualCostUSD: state.data.comparisonFlamegraph.TotalAnnualCostsUSD,
totalAnnualCO2Kgs: state.data.comparisonFlamegraph.TotalAnnualCO2KgsItems[0],
totalAnnualCostUSD: state.data.comparisonFlamegraph.TotalAnnualCostsUSDItems[0],
}
: undefined
}
Expand Down

0 comments on commit a324547

Please sign in to comment.