Skip to content
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

Accumulate consumed units #18714

Merged
merged 1 commit into from
Jul 16, 2021
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
4 changes: 4 additions & 0 deletions core/src/cost_update_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,15 @@ mod tests {
// add new program
{
let accumulated_us: u64 = 1000;
let accumulated_units: u64 = 100;
let count: u32 = 10;
expected_cost = accumulated_us / count as u64;

execute_timings.details.per_program_timings.insert(
program_key_1,
ProgramTiming {
accumulated_us,
accumulated_units,
count,
},
);
Expand All @@ -250,6 +252,7 @@ mod tests {
// update program
{
let accumulated_us: u64 = 2000;
let accumulated_units: u64 = 200;
let count: u32 = 10;
// to expect new cost is Average(new_value, existing_value)
expected_cost = ((accumulated_us / count as u64) + expected_cost) / 2;
Expand All @@ -258,6 +261,7 @@ mod tests {
program_key_1,
ProgramTiming {
accumulated_us,
accumulated_units,
count,
},
);
Expand Down
17 changes: 11 additions & 6 deletions runtime/src/message_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl Executors {
#[derive(Default, Debug)]
pub struct ProgramTiming {
pub accumulated_us: u64,
pub accumulated_units: u64,
pub count: u32,
}

Expand Down Expand Up @@ -87,9 +88,10 @@ impl ExecuteDetailsTimings {
self.total_data_size += other.total_data_size;
self.data_size_changed += other.data_size_changed;
for (id, other) in &other.per_program_timings {
let time_count = self.per_program_timings.entry(*id).or_default();
time_count.accumulated_us += other.accumulated_us;
time_count.count += other.count;
let program_timing = self.per_program_timings.entry(*id).or_default();
program_timing.accumulated_us += other.accumulated_us;
program_timing.accumulated_units += other.accumulated_units;
program_timing.count += other.count;
}
}
}
Expand Down Expand Up @@ -1234,6 +1236,7 @@ impl MessageProcessor {
) -> Result<(), TransactionError> {
for (instruction_index, instruction) in message.instructions.iter().enumerate() {
let mut time = Measure::start("execute_instruction");
let pre_remaining_units = compute_meter.borrow().get_remaining();
let instruction_recorder = instruction_recorders
.as_ref()
.map(|recorders| recorders[instruction_index].clone());
Expand All @@ -1257,11 +1260,13 @@ impl MessageProcessor {
)
.map_err(|err| TransactionError::InstructionError(instruction_index as u8, err));
time.stop();
let post_remaining_units = compute_meter.borrow().get_remaining();

let program_id = instruction.program_id(&message.account_keys);
let time_count = timings.per_program_timings.entry(*program_id).or_default();
time_count.accumulated_us += time.as_us();
time_count.count += 1;
let program_timing = timings.per_program_timings.entry(*program_id).or_default();
program_timing.accumulated_us += time.as_us();
program_timing.accumulated_units += pre_remaining_units - post_remaining_units;
program_timing.count += 1;

err?;
}
Expand Down