Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tsc/internal/execute/build/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (b *OrchestratorResult) reportWithFilesToDelete(o *Orchestrator, reportFile
return
}
b.Statistics.SetTotalTime(o.opts.Sys.SinceStart())
b.Statistics.Report(o.opts.Sys.Writer(), o.opts.Testing)
b.Statistics.Report(o.opts.Sys.Writer(), o.opts.Testing, o.opts.Command.CompilerOptions.ExtendedDiagnostics.IsTrue())
}

type Orchestrator struct {
Expand Down
2 changes: 1 addition & 1 deletion tsc/internal/execute/tsc/emit.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func EmitAndReportStatistics(input EmitInput) (CompileAndEmitResult, *Statistics
runtime.ReadMemStats(&memStats)

statistics = statisticsFromProgram(input, &memStats)
statistics.Report(input.Writer, input.Testing)
statistics.Report(input.Writer, input.Testing, input.Config.CompilerOptions().ExtendedDiagnostics.IsTrue())
}

if result.EmitResult.EmitSkipped && len(result.Diagnostics) > 0 {
Expand Down
8 changes: 7 additions & 1 deletion tsc/internal/execute/tsc/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/microsoft/TypeScript/tsc/internal/compiler"
"github.com/microsoft/TypeScript/tsc/internal/osutil"
)

type tableRow struct {
Expand Down Expand Up @@ -83,7 +84,7 @@ func statisticsFromProgram(input EmitInput, memStats *runtime.MemStats) *Statist
}
}

func (s *Statistics) Report(w io.Writer, testing CommandLineTesting) {
func (s *Statistics) Report(w io.Writer, testing CommandLineTesting, extendedDiagnostics bool) {
if testing != nil {
testing.OnStatisticsStart(w)
defer testing.OnStatisticsEnd(w)
Expand Down Expand Up @@ -126,6 +127,11 @@ func (s *Statistics) Report(w io.Writer, testing CommandLineTesting) {
}
s.addContentMapperStatistics(&table, prefix)
table.add(prefix+"Total time", s.compileTimes.totalTime)
if extendedDiagnostics {
if cpuTime, err := osutil.ProcessCPUTime(); err == nil {
table.add("CPU time", cpuTime)
}
}
table.print(w)
}

Expand Down
12 changes: 12 additions & 0 deletions tsc/internal/osutil/cputime_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !unix && !windows

package osutil

import (
"errors"
"time"
)

func processCPUTime() (time.Duration, error) {
return 0, errors.ErrUnsupported
}
17 changes: 17 additions & 0 deletions tsc/internal/osutil/cputime_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//go:build unix

package osutil

import (
"time"

"golang.org/x/sys/unix"
)

func processCPUTime() (time.Duration, error) {
var usage unix.Rusage
if err := unix.Getrusage(unix.RUSAGE_SELF, &usage); err != nil {
return 0, err
}
return time.Duration(usage.Utime.Nano()) + time.Duration(usage.Stime.Nano()), nil
}
17 changes: 17 additions & 0 deletions tsc/internal/osutil/cputime_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package osutil

import (
"time"

"golang.org/x/sys/windows"
)

func processCPUTime() (time.Duration, error) {
var creation, exit, kernel, user windows.Filetime
if err := windows.GetProcessTimes(windows.CurrentProcess(), &creation, &exit, &kernel, &user); err != nil {
return 0, err
}
kernelTicks := uint64(kernel.HighDateTime)<<32 | uint64(kernel.LowDateTime)
userTicks := uint64(user.HighDateTime)<<32 | uint64(user.LowDateTime)
return time.Duration(kernelTicks+userTicks) * 100 * time.Nanosecond, nil
}
8 changes: 8 additions & 0 deletions tsc/internal/osutil/osutil.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package osutil

import "time"

// Args returns the command-line arguments with platform-specific launcher details removed.
func Args() []string {
return args()
Expand All @@ -9,3 +11,9 @@ func Args() []string {
func Executable() (string, error) {
return executable()
}

// ProcessCPUTime returns cumulative user and system CPU time across all threads
// of the current process, excluding child processes.
func ProcessCPUTime() (time.Duration, error) {
return processCPUTime()
}
Loading