From 063341b5639d9ecf4e75656eac5f2e8484fcddb2 Mon Sep 17 00:00:00 2001 From: Hamish Knight Date: Fri, 4 Apr 2025 13:21:22 +0100 Subject: [PATCH] [xcodegen] Print the time taken to generate --- .../swift-xcodegen/SwiftXcodegen.swift | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/utils/swift-xcodegen/Sources/swift-xcodegen/SwiftXcodegen.swift b/utils/swift-xcodegen/Sources/swift-xcodegen/SwiftXcodegen.swift index 854dc524c721..37d1bb5d0cec 100644 --- a/utils/swift-xcodegen/Sources/swift-xcodegen/SwiftXcodegen.swift +++ b/utils/swift-xcodegen/Sources/swift-xcodegen/SwiftXcodegen.swift @@ -11,7 +11,7 @@ //===----------------------------------------------------------------------===// import ArgumentParser -import Darwin +import Foundation import SwiftXcodeGen @main @@ -399,14 +399,27 @@ struct SwiftXcodegen: AsyncParsableCommand, Sendable { try lldbLLVMWorkspace.write("LLDB+LLVM", into: outputDir) } } - showCaveatsIfNeeded() + } + + func printingTimeTaken(_ fn: () async throws -> T) async rethrows -> T { + let start = Date() + let result = try await fn() + + // Note we don't print the time taken when we fail. + let delta = Date().timeIntervalSince(start) + log.info("Successfully generated in \(Int((delta * 1000).rounded()))ms") + + return result } func run() async { // Set the log level log.logLevel = .init(self.logLevel ?? (self.quiet ? .warning : .info)) do { - try await generate() + try await printingTimeTaken { + try await generate() + } + showCaveatsIfNeeded() } catch { log.error("\(error)") }