Search in sources :

Example 1 with ClockDuration

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));
}
Also used : FakeRuleKeyFactory(com.facebook.buck.rules.keys.FakeRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) ClockDuration(com.facebook.buck.timing.ClockDuration) BuildRuleDurationTracker(com.facebook.buck.rules.BuildRuleDurationTracker)

Example 2 with ClockDuration

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));
}
Also used : ClockDuration(com.facebook.buck.timing.ClockDuration) Test(org.junit.Test)

Aggregations

ClockDuration (com.facebook.buck.timing.ClockDuration)2 BuildRuleDurationTracker (com.facebook.buck.rules.BuildRuleDurationTracker)1 RuleKey (com.facebook.buck.rules.RuleKey)1 FakeRuleKeyFactory (com.facebook.buck.rules.keys.FakeRuleKeyFactory)1 Test (org.junit.Test)1