diff options
author | 2021-11-06 18:42:42 -0700 | |
---|---|---|
committer | 2021-11-06 18:42:42 -0700 | |
commit | d7d9df726b865f654a4f821e138027024ba23bea (patch) | |
tree | 80a3df873e41855df5c5f6419cb8a343f9edf7b8 /src | |
parent | a36818276915fa75207cd30a65e25d62c1d63a14 (diff) | |
download | bun-d7d9df726b865f654a4f821e138027024ba23bea.tar.gz bun-d7d9df726b865f654a4f821e138027024ba23bea.tar.zst bun-d7d9df726b865f654a4f821e138027024ba23bea.zip |
[internal] Use a better timer for measuring parsing & resolving timings
Diffstat (limited to 'src')
-rw-r--r-- | src/bundler.zig | 10 | ||||
-rw-r--r-- | src/resolver/resolver.zig | 10 |
2 files changed, 11 insertions, 9 deletions
diff --git a/src/bundler.zig b/src/bundler.zig index 15d190b0c..094251ce9 100644 --- a/src/bundler.zig +++ b/src/bundler.zig @@ -113,12 +113,12 @@ pub const Bundler = struct { output_files: std.ArrayList(options.OutputFile), resolve_results: *ResolveResults, resolve_queue: ResolveQueue, - elapsed: i128 = 0, + elapsed: u64 = 0, needs_runtime: bool = false, router: ?Router = null, linker: Linker, - timer: Timer = Timer{}, + timer: std.time.Timer = undefined, env: *DotEnv.Loader, // must be pointer array because we can't we don't want the source to point to invalid memory if the array size is reallocated @@ -193,6 +193,7 @@ pub const Bundler = struct { .options = bundle_options, .fs = fs, .allocator = allocator, + .timer = std.time.Timer.start() catch @panic("Timer fail"), .resolver = Resolver.init1(allocator, log, fs, bundle_options), .log = log, // .thread_pool = pool, @@ -2547,12 +2548,11 @@ pub const Bundler = struct { const loader = this_parse.loader; if (FeatureFlags.tracing) { - bundler.timer.start(); + bundler.timer.reset(); } defer { if (FeatureFlags.tracing) { - bundler.timer.stop(); - bundler.elapsed += bundler.timer.elapsed; + bundler.elapsed += bundler.timer.read(); } } var result: ParseResult = undefined; diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig index 125987d37..5816ebd6b 100644 --- a/src/resolver/resolver.zig +++ b/src/resolver/resolver.zig @@ -341,12 +341,13 @@ pub const Resolver = struct { allocator: *std.mem.Allocator, node_module_bundle: ?*NodeModuleBundle, extension_order: []const string = undefined, + timer: std.time.Timer = undefined, care_about_bin_folder: bool = false, care_about_scripts: bool = false, debug_logs: ?DebugLogs = null, - elapsed: i128 = 0, // tracing + elapsed: u64 = 0, // tracing onStartWatchingDirectory: ?fn (*HTTPWatcher, dir_path: string, dir_fd: StoredFileDescriptorType) void = null, onStartWatchingDirectoryCtx: ?*HTTPWatcher = null, @@ -414,6 +415,7 @@ pub const Resolver = struct { .mutex = &resolver_Mutex, .caches = CacheSet.init(allocator), .opts = opts, + .timer = std.time.Timer.start() catch @panic("Timer error!"), .fs = _fs, .node_module_bundle = opts.node_modules_bundle, .log = log, @@ -590,13 +592,13 @@ pub const Resolver = struct { pub fn resolve(r: *ThisResolver, source_dir: string, import_path: string, kind: ast.ImportKind) !Result { r.extension_order = if (kind.isFromCSS()) std.mem.span(&options.BundleOptions.Defaults.CSSExtensionOrder) else r.opts.extension_order; - if (FeatureFlags.tracing) { - tracing_start = std.time.nanoTimestamp(); + r.timer.reset(); } + defer { if (FeatureFlags.tracing) { - r.elapsed += std.time.nanoTimestamp() - tracing_start; + r.elapsed += r.timer.read(); } } if (r.log.level == .verbose) { |