use of com.facebook.buck.timing.ClockDuration in project buck by facebook.
the class BuildThreadStateRendererTest method createRuleBeginningEventOptional.
private static Optional<? extends BuildRuleEvent.BeginningBuildRuleEvent> createRuleBeginningEventOptional(long threadId, long timeMs, long durationMs, BuildRule rule) {
BuildRuleDurationTracker durationTracker = new BuildRuleDurationTracker();
durationTracker.setDuration(rule, new ClockDuration(durationMs, 0, 0));
RuleKey ruleKey = new RuleKey(HashCode.fromString("aa"));
return Optional.of(TestEventConfigurator.configureTestEventAtTime(BuildRuleEvent.resumed(rule, durationTracker, new FakeRuleKeyFactory(ImmutableMap.of(rule.getBuildTarget(), ruleKey))), timeMs, TimeUnit.MILLISECONDS, threadId));
}
use of com.facebook.buck.timing.ClockDuration in project buck by facebook.
the class BuildRuleDurationTrackerTest method test.
@Test
public void test() {
BuildRuleDurationTracker tracker = new BuildRuleDurationTracker();
BuildRule rule1 = FakeBuildRule.newEmptyInstance("//fake:rule1");
BuildRule rule2 = FakeBuildRule.newEmptyInstance("//fake:rule2");
/**
* 10 15 20 22 23 26 30 31 33 35 37
* . . . . . . . . . . .
* |-rule1-| . . . . . . . . .
* |---rule1---| . . . . .
* |-------rule1-------| . .
* |---rule1---| . .
* . |------rule1------|
* . .
* |--------rule2-------|
*
* Note that the total wall time for rule1 is 5 + 17 = 22. We count overlaps only once.
* Thread time on the other hand is always added, regardless of overlapping.
*
* Durations for rule1 and rule2 are completely independent of each other.
*/
assertEquals(new ClockDuration(0, 0, 0), tracker.doBeginning(rule1, 10, 10000));
assertEquals(new ClockDuration(5, 5000, 900), tracker.doEnding(rule1, 15, 15000, 900));
assertEquals(new ClockDuration(5, 5000, 900), tracker.doBeginning(rule1, 20, 20000));
assertEquals(new ClockDuration(7, 7000, 900), tracker.doBeginning(rule1, 22, 22000));
assertEquals(new ClockDuration(8, 8000, 900), tracker.doBeginning(rule1, 23, 23000));
assertEquals(new ClockDuration(0, 0, 0), tracker.doBeginning(rule2, 23, 23000));
assertEquals(new ClockDuration(11, 11000, 1200), tracker.doEnding(rule1, 26, 26000, 300));
assertEquals(new ClockDuration(15, 15000, 1200), tracker.doBeginning(rule1, 30, 30000));
assertEquals(new ClockDuration(16, 16000, 1300), tracker.doEnding(rule1, 31, 31000, 100));
assertEquals(new ClockDuration(18, 18000, 1500), tracker.doEnding(rule1, 33, 33000, 200));
assertEquals(new ClockDuration(12, 12000, 42), tracker.doEnding(rule2, 35, 35000, 42));
assertEquals(new ClockDuration(22, 22000, 1900), tracker.doEnding(rule1, 37, 37000, 400));
}
Aggregations