tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

trr_multi_domain_performance.js (3667B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 /* eslint-env node */
      6 /* global require, module */
      7 
      8 const { logTest } = require("./utils/profiling");
      9 
     10 module.exports = logTest(
     11  "multi-domain dns lookup pageload",
     12  async function (context, commands) {
     13    context.log.info(
     14      "Starting multi-domain pageload to measure DNS lookup time"
     15    );
     16 
     17    const testType = `${context.options.browsertime.test_type}`;
     18    context.log.info("testType: " + testType);
     19 
     20    const url =
     21      "https://mozilla-necko.github.io/tests/dns/trr_multi_domain.html";
     22 
     23    await commands.navigate("about:blank");
     24 
     25    // Idle to allow for confirmation
     26    await commands.wait.byTime(5000);
     27 
     28    if (testType === "trr_warm") {
     29      // Ensure the trr connection has been warmed up by making an arbitrary request
     30      await commands.navigate("https://www.w3.org");
     31      await commands.wait.byTime(2000);
     32    }
     33 
     34    // Start measuring
     35    await commands.measure.start();
     36    await commands.navigate(url);
     37 
     38    // Wait for all domains to load (or fail)
     39    await commands.wait.byTime(10000);
     40 
     41    await commands.measure.stop();
     42 
     43    // Get pageload time
     44    let pageload_time = await commands.js.run(`
     45      return (window.performance.timing.loadEventEnd - window.performance.timing.navigationStart);
     46    `);
     47 
     48    // Extract DNS timing data from the page
     49    let dns_data = await commands.js.run(`
     50      const entries = window.performance.getEntriesByType('resource');
     51 
     52      let totalDNS = 0;
     53      let maxDNS = 0;
     54      let minDNS = Infinity;
     55      let dnsCount = 0;
     56 
     57      const dnsTimings = [];
     58 
     59      entries.forEach(entry => {
     60        const dnsTime = entry.domainLookupEnd - entry.domainLookupStart;
     61        if (dnsTime > 0) {
     62          totalDNS += dnsTime;
     63          maxDNS = Math.max(maxDNS, dnsTime);
     64          minDNS = Math.min(minDNS, dnsTime);
     65          dnsCount++;
     66          dnsTimings.push({
     67            url: entry.name,
     68            dns_time: dnsTime
     69          });
     70        }
     71      });
     72 
     73      return {
     74        avg_dns_lookup_time: dnsCount > 0 ? totalDNS / dnsCount : 0,
     75        total_dns_lookup_time: totalDNS,
     76        total_resource_entries: entries.length,
     77        dns_entries_count: dnsCount,
     78        max_dns_lookup_time: maxDNS === 0 ? 0 : maxDNS,
     79        min_dns_lookup_time: minDNS === Infinity ? 0 : minDNS,
     80        dns_timings: dnsTimings
     81      };
     82    `);
     83 
     84    context.log.info("pageload_time: " + pageload_time);
     85    context.log.info(
     86      "total_resource_entries: " + dns_data.total_resource_entries
     87    );
     88    context.log.info("dns_entries_count: " + dns_data.dns_entries_count);
     89    context.log.info("avg_dns_lookup_time: " + dns_data.avg_dns_lookup_time);
     90    context.log.info(
     91      "total_dns_lookup_time: " + dns_data.total_dns_lookup_time
     92    );
     93    context.log.info("max_dns_lookup_time: " + dns_data.max_dns_lookup_time);
     94    context.log.info("min_dns_lookup_time: " + dns_data.min_dns_lookup_time);
     95 
     96    await commands.measure.addObject({
     97      custom_data: {
     98        pageload_time,
     99        total_resource_entries: dns_data.total_resource_entries,
    100        dns_entries_count: dns_data.dns_entries_count,
    101        avg_dns_lookup_time: dns_data.avg_dns_lookup_time,
    102        total_dns_lookup_time: dns_data.total_dns_lookup_time,
    103        max_dns_lookup_time: dns_data.max_dns_lookup_time,
    104        min_dns_lookup_time: dns_data.min_dns_lookup_time,
    105        dns_timings: dns_data.dns_timings,
    106      },
    107    });
    108 
    109    context.log.info("Multi-domain DNS lookup test finished.");
    110    return true;
    111  }
    112 );