Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change --times console reporting to be based on Activity #14470

Merged
merged 27 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d0bc864
Time reporting to a file
T-Gro Dec 7, 2022
c9425bd
initial sketch
T-Gro Dec 8, 2022
9b7b86c
formatting
T-Gro Dec 8, 2022
3a0c03a
Add remarks
T-Gro Dec 8, 2022
2e72cf6
csv row building refactored
T-Gro Dec 8, 2022
cde7a25
support for rootId added
T-Gro Dec 8, 2022
a71d736
Tracking whole file compilation, to make it the root activity for fsc…
T-Gro Dec 8, 2022
506f146
Formatting using Fantomas
T-Gro Dec 8, 2022
b2e51b5
Apply suggestions from code review
T-Gro Dec 8, 2022
d6aea78
Merge branch 'main' into fsc-timing-to-file
T-Gro Dec 8, 2022
a5bc3bd
Changing literal strings to Activity.Tags.***
T-Gro Dec 9, 2022
0080726
Merge branch 'fsc-timing-to-file' of https://github.com/dotnet/fsharp…
T-Gro Dec 9, 2022
376701e
Fantomas applied
T-Gro Dec 9, 2022
b5083db
Redoing time reporting in ilwrite
T-Gro Dec 9, 2022
b22a032
Console table layout for --times
T-Gro Dec 9, 2022
515617a
formatting
T-Gro Dec 9, 2022
b8f8a87
Merge branch 'main' into moveTimesFlagToUseActivityModule
T-Gro Dec 14, 2022
9031e5f
formatting
T-Gro Dec 14, 2022
9c8d938
fix CI
T-Gro Dec 14, 2022
a2e4aab
reformatted
T-Gro Dec 14, 2022
74c86da
Supporting proper finish of statistic measurement, to enable multiple…
T-Gro Dec 27, 2022
12575f1
Merge branch 'main' into moveTimesFlagToUseActivityModule
T-Gro Dec 27, 2022
bb41ec9
Resolving build issue caused by conflict (movement of signing)
T-Gro Dec 27, 2022
b3c5e63
reformat
T-Gro Dec 27, 2022
0dfe61c
Making console table markdown friendly (to be directly copy-pastable)
T-Gro Dec 27, 2022
ce28d06
Update src/Compiler/Checking/CheckExpressions.fs
T-Gro Dec 29, 2022
ac75d60
Merge branch 'main' into moveTimesFlagToUseActivityModule
T-Gro Dec 29, 2022
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
88 changes: 39 additions & 49 deletions src/Compiler/AbstractIL/ilwrite.fs
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,7 @@ type cenv =

emitTailcalls: bool

deterministic: bool

showTimes: bool
deterministic: bool

desiredMetadataVersion: ILVersionInfo

Expand Down Expand Up @@ -3020,22 +3018,22 @@ let GenModule (cenv : cenv) (modul: ILModuleDef) =
let midx = AddUnsharedRow cenv TableNames.Module (GetModuleAsRow cenv modul)
List.iter (GenResourcePass3 cenv) (modul.Resources.AsList())
let tdefs = destTypeDefsWithGlobalFunctionsFirst cenv.ilg modul.TypeDefs
reportTime cenv.showTimes "Module Generation Preparation"
reportTime "Module Generation Preparation"
GenTypeDefsPass1 [] cenv tdefs
reportTime cenv.showTimes "Module Generation Pass 1"
reportTime "Module Generation Pass 1"
GenTypeDefsPass2 0 [] cenv tdefs
reportTime cenv.showTimes "Module Generation Pass 2"
reportTime "Module Generation Pass 2"
(match modul.Manifest with None -> () | Some m -> GenManifestPass3 cenv m)
GenTypeDefsPass3 [] cenv tdefs
reportTime cenv.showTimes "Module Generation Pass 3"
reportTime "Module Generation Pass 3"
GenCustomAttrsPass3Or4 cenv (hca_Module, midx) modul.CustomAttrs
// GenericParam is the only sorted table indexed by Columns in other tables (GenericParamConstraint\CustomAttributes).
// Hence we need to sort it before we emit any entries in GenericParamConstraint\CustomAttributes that are attached to generic params.
// Note this mutates the rows in a table. 'SetRowsOfTable' clears
// the key --> index map since it is no longer valid
cenv.GetTable(TableNames.GenericParam).SetRowsOfSharedTable (SortTableRows TableNames.GenericParam (cenv.GetTable(TableNames.GenericParam).GenericRowsOfTable))
GenTypeDefsPass4 [] cenv tdefs
reportTime cenv.showTimes "Module Generation Pass 4"
reportTime "Module Generation Pass 4"

/// Arbitrary value
[<Literal>]
Expand All @@ -3053,8 +3051,7 @@ let generateIL (
generatePdb,
ilg: ILGlobals,
emitTailcalls,
deterministic,
showTimes,
deterministic,
referenceAssemblyOnly,
referenceAssemblyAttribOpt: ILAttribute option,
allGivenSources,
Expand Down Expand Up @@ -3095,8 +3092,7 @@ let generateIL (
MetadataTable.Unshared (MetadataTable<UnsharedRow>.New ("row table "+string i, EqualityComparer.Default)))
use cenv =
{ emitTailcalls=emitTailcalls
deterministic = deterministic
showTimes=showTimes
deterministic = deterministic
ilg = ilg
desiredMetadataVersion=desiredMetadataVersion
requiredDataFixups= requiredDataFixups
Expand Down Expand Up @@ -3180,7 +3176,7 @@ let generateIL (
EventTokenMap = (fun t edef ->
let tidx = idxForNextedTypeDef t
getUncodedToken TableNames.Event (cenv.eventDefs.GetTableEntry (EventKey (tidx, edef.Name)))) }
reportTime cenv.showTimes "Finalize Module Generation Results"
reportTime "Finalize Module Generation Results"
// New return the results
let data = cenv.data.AsMemory().ToArray()
let resources = cenv.resources.AsMemory().ToArray()
Expand Down Expand Up @@ -3214,8 +3210,7 @@ let writeILMetadataAndCode (
desiredMetadataVersion,
ilg,
emitTailcalls,
deterministic,
showTimes,
deterministic,
referenceAssemblyOnly,
referenceAssemblyAttribOpt,
allGivenSources,
Expand All @@ -3237,16 +3232,15 @@ let writeILMetadataAndCode (
generatePdb,
ilg,
emitTailcalls,
deterministic,
showTimes,
deterministic,
referenceAssemblyOnly,
referenceAssemblyAttribOpt,
allGivenSources,
modul,
cilStartAddress,
normalizeAssemblyRefs)

reportTime showTimes "Generated Tables and Code"
reportTime "Generated Tables and Code"
let tableSize (tab: TableName) = tables[tab.Index].Count

// Now place the code
Expand Down Expand Up @@ -3318,7 +3312,7 @@ let writeILMetadataAndCode (
(if tableSize TableNames.GenericParamConstraint > 0 then 0x00001000 else 0x00000000) |||
0x00000200

reportTime showTimes "Layout Header of Tables"
reportTime "Layout Header of Tables"

let guidAddress n = (if n = 0 then 0 else (n - 1) * 0x10 + 0x01)

Expand Down Expand Up @@ -3362,7 +3356,7 @@ let writeILMetadataAndCode (
if n >= blobAddressTable.Length then failwith "blob index out of range"
blobAddressTable[n]

reportTime showTimes "Build String/Blob Address Tables"
reportTime "Build String/Blob Address Tables"

let sortedTables =
Array.init 64 (fun i ->
Expand All @@ -3371,7 +3365,7 @@ let writeILMetadataAndCode (
let rows = tab.GenericRowsOfTable
if TableRequiresSorting tabName then SortTableRows tabName rows else rows)

reportTime showTimes "Sort Tables"
reportTime "Sort Tables"

let codedTables =

Expand Down Expand Up @@ -3486,7 +3480,7 @@ let writeILMetadataAndCode (
tablesBuf.EmitInt32 rows.Length


reportTime showTimes "Write Header of tablebuf"
reportTime "Write Header of tablebuf"

// The tables themselves
for rows in sortedTables do
Expand Down Expand Up @@ -3521,7 +3515,7 @@ let writeILMetadataAndCode (

tablesBuf.AsMemory().ToArray()

reportTime showTimes "Write Tables to tablebuf"
reportTime "Write Tables to tablebuf"

let tablesStreamUnpaddedSize = codedTables.Length
// QUERY: extra 4 empty bytes in array.exe - why? Include some extra padding after
Expand All @@ -3538,7 +3532,7 @@ let writeILMetadataAndCode (
let blobsChunk, _next = chunk blobsStreamPaddedSize next
let blobsStreamPadding = blobsChunk.size - blobsStreamUnpaddedSize

reportTime showTimes "Layout Metadata"
reportTime "Layout Metadata"

let metadata, guidStart =
use mdbuf = ByteBuffer.Create(MetadataCapacity, useArrayPool = true)
Expand Down Expand Up @@ -3573,20 +3567,20 @@ let writeILMetadataAndCode (
mdbuf.EmitInt32 blobsChunk.size
mdbuf.EmitIntsAsBytes [| 0x23; 0x42; 0x6c; 0x6f; 0x62; 0x00; 0x00; 0x00; (* #Blob000 *)|]

reportTime showTimes "Write Metadata Header"
reportTime "Write Metadata Header"
// Now the coded tables themselves
mdbuf.EmitBytes codedTables
for i = 1 to tablesStreamPadding do
mdbuf.EmitIntAsByte 0x00
reportTime showTimes "Write Metadata Tables"
reportTime "Write Metadata Tables"

// The string stream
mdbuf.EmitByte 0x00uy
for s in strings do
mdbuf.EmitBytes s
for i = 1 to stringsStreamPadding do
mdbuf.EmitIntAsByte 0x00
reportTime showTimes "Write Metadata Strings"
reportTime "Write Metadata Strings"
// The user string stream
mdbuf.EmitByte 0x00uy
for s in userStrings do
Expand All @@ -3596,7 +3590,7 @@ let writeILMetadataAndCode (
for i = 1 to userStringsStreamPadding do
mdbuf.EmitIntAsByte 0x00

reportTime showTimes "Write Metadata User Strings"
reportTime "Write Metadata User Strings"
// The GUID stream
let guidStart = mdbuf.Position
Array.iter mdbuf.EmitBytes guids
Expand All @@ -3608,7 +3602,7 @@ let writeILMetadataAndCode (
mdbuf.EmitBytes s
for i = 1 to blobsStreamPadding do
mdbuf.EmitIntAsByte 0x00
reportTime showTimes "Write Blob Stream"
reportTime "Write Blob Stream"
// Done - close the buffer and return the result.
mdbuf.AsMemory().ToArray(), guidStart

Expand All @@ -3624,7 +3618,7 @@ let writeILMetadataAndCode (
let token = getUncodedToken TableNames.UserStrings (userStringAddress userStringIndex)
if (Bytes.get code (locInCode-1) <> i_ldstr) then failwith "strings-in-code fixup: not at ldstr instruction!"
applyFixup32 code locInCode token
reportTime showTimes "Fixup Metadata"
reportTime "Fixup Metadata"

entryPointToken, code, codePadding, metadata, data, resources, requiredDataFixups.Value, pdbData, mappings, guidStart

Expand Down Expand Up @@ -3687,8 +3681,7 @@ let writeDirectory os dict =
let writeBytes (os: BinaryWriter) (chunk: byte[]) = os.Write(chunk, 0, chunk.Length)

let writePdb (
dumpDebugInfo,
showTimes,
dumpDebugInfo,
embeddedPDB,
pdbfile,
outfile,
Expand Down Expand Up @@ -3721,7 +3714,7 @@ let writePdb (
s.SignStream fs
with exn ->
failwith ($"Warning: A call to SignFile failed ({exn.Message})")
reportTime showTimes "Signing Image"
reportTime "Signing Image"

// Now we've done the bulk of the binary, do the PDB file and fixup the binary.
match pdbfile with
Expand Down Expand Up @@ -3751,7 +3744,7 @@ let writePdb (
stream.WriteTo fs
getInfoForPortablePdb contentId pdbfile pathMap debugDataChunk debugDeterministicPdbChunk debugChecksumPdbChunk algorithmName checkSum embeddedPDB deterministic
| None -> [| |]
reportTime showTimes "Generate PDB Info"
reportTime "Generate PDB Info"

// Now we have the debug data we can go back and fill in the debug directory in the image
use fs2 = reopenOutput()
Expand All @@ -3776,14 +3769,15 @@ let writePdb (
os2.BaseStream.Seek (int64 (textV2P i.iddChunk.addr), SeekOrigin.Begin) |> ignore
if i.iddChunk.size < i.iddData.Length then failwith "Debug data area is not big enough. Debug info may not be usable"
writeBytes os2 i.iddData
reportTime showTimes "Finalize PDB"
reportTime "Finalize PDB"
signImage ()
os2.Dispose()
with exn ->
failwith ("Error while writing debug directory entry: " + exn.Message)
(try os2.Dispose(); FileSystem.FileDeleteShim outfile with _ -> ())
reraise()


reportTime "Finish"
pdbBytes

type options =
Expand All @@ -3799,8 +3793,7 @@ type options =
checksumAlgorithm: HashAlgorithm
signer: ILStrongNameSigner option
emitTailcalls: bool
deterministic: bool
showTimes: bool
deterministic: bool
dumpDebugInfo: bool
referenceAssemblyOnly: bool
referenceAssemblyAttribOpt: ILAttribute option
Expand All @@ -3811,7 +3804,7 @@ let writeBinaryAux (stream: Stream, options: options, modul, normalizeAssemblyRe
// Store the public key from the signer into the manifest. This means it will be written
// to the binary and also acts as an indicator to leave space for delay sign

reportTime options.showTimes "Write Started"
reportTime "Write Started"
let isDll = modul.IsDLL
let ilg = options.ilg

Expand Down Expand Up @@ -3925,8 +3918,7 @@ let writeBinaryAux (stream: Stream, options: options, modul, normalizeAssemblyRe
desiredMetadataVersion,
ilg,
options.emitTailcalls,
options.deterministic,
options.showTimes,
options.deterministic,
options.referenceAssemblyOnly,
options.referenceAssemblyAttribOpt,
options.allGivenSources,
Expand All @@ -3935,7 +3927,7 @@ let writeBinaryAux (stream: Stream, options: options, modul, normalizeAssemblyRe
normalizeAssemblyRefs
)

reportTime options.showTimes "Generated IL and metadata"
reportTime "Generated IL and metadata"
let _codeChunk, next = chunk code.Length next
let _codePaddingChunk, next = chunk codePadding.Length next

Expand Down Expand Up @@ -3968,7 +3960,7 @@ let writeBinaryAux (stream: Stream, options: options, modul, normalizeAssemblyRe
match options.pdbfile, options.portablePDB with
| Some _, true ->
let pdbInfo =
generatePortablePdb options.embedAllSource options.embedSourceList options.sourceLink options.checksumAlgorithm options.showTimes pdbData options.pathMap
generatePortablePdb options.embedAllSource options.embedSourceList options.sourceLink options.checksumAlgorithm pdbData options.pathMap

if options.embeddedPDB then
let (uncompressedLength, contentId, stream, algorithmName, checkSum) = pdbInfo
Expand Down Expand Up @@ -4094,7 +4086,7 @@ let writeBinaryAux (stream: Stream, options: options, modul, normalizeAssemblyRe
let imageEndSectionPhysLoc = nextPhys
let imageEndAddr = next

reportTime options.showTimes "Layout image"
reportTime "Layout image"

let write p (os: BinaryWriter) chunkName chunk =
match p with
Expand Down Expand Up @@ -4501,7 +4493,7 @@ let writeBinaryAux (stream: Stream, options: options, modul, normalizeAssemblyRe

pdbData, pdbInfoOpt, debugDirectoryChunk, debugDataChunk, debugChecksumPdbChunk, debugEmbeddedPdbChunk, debugDeterministicPdbChunk, textV2P, mappings

reportTime options.showTimes "Writing Image"
reportTime "Writing Image"
pdbData, pdbInfoOpt, debugDirectoryChunk, debugDataChunk, debugChecksumPdbChunk, debugEmbeddedPdbChunk, debugDeterministicPdbChunk, textV2P, mappings

let writeBinaryFiles (options: options, modul, normalizeAssemblyRefs) =
Expand Down Expand Up @@ -4529,8 +4521,7 @@ let writeBinaryFiles (options: options, modul, normalizeAssemblyRefs) =
let reopenOutput () =
FileSystem.OpenFileForWriteShim(options.outfile, FileMode.Open, FileAccess.ReadWrite, FileShare.Read)

writePdb (options.dumpDebugInfo,
options.showTimes,
writePdb (options.dumpDebugInfo,
options.embeddedPDB,
options.pdbfile,
options.outfile,
Expand Down Expand Up @@ -4562,8 +4553,7 @@ let writeBinaryInMemory (options: options, modul, normalizeAssemblyRefs) =
stream

let pdbBytes =
writePdb (options.dumpDebugInfo,
options.showTimes,
writePdb (options.dumpDebugInfo,
options.embeddedPDB,
options.pdbfile,
options.outfile,
Expand Down
1 change: 0 additions & 1 deletion src/Compiler/AbstractIL/ilwrite.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type options =
signer: ILStrongNameSigner option
emitTailcalls: bool
deterministic: bool
showTimes: bool
dumpDebugInfo: bool
referenceAssemblyOnly: bool
referenceAssemblyAttribOpt: ILAttribute option
Expand Down
14 changes: 6 additions & 8 deletions src/Compiler/AbstractIL/ilwritepdb.fs
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ let pdbGetDebugInfo
let getDebugFileName outfile =
(FileSystemUtils.chopExtension outfile) + ".pdb"

let sortMethods showTimes info =
reportTime showTimes (sprintf "PDB: Defined %d documents" info.Documents.Length)
let sortMethods info =
reportTime (sprintf "PDB: Defined %d documents" info.Documents.Length)
Array.sortInPlaceBy (fun x -> x.MethToken) info.Methods
reportTime showTimes (sprintf "PDB: Sorted %d methods" info.Methods.Length)
reportTime (sprintf "PDB: Sorted %d methods" info.Methods.Length)
()

let getRowCounts tableRowCounts =
Expand All @@ -345,7 +345,6 @@ type PortablePdbGenerator
embedSourceList: string list,
sourceLink: string,
checksumAlgorithm,
showTimes,
info: PdbData,
pathMap: PathMap
) =
Expand Down Expand Up @@ -784,7 +783,7 @@ type PortablePdbGenerator
| Some scope -> writeMethodScopes minfo.MethToken scope

member _.Emit() =
sortMethods showTimes info
sortMethods info
metadata.SetCapacity(TableIndex.MethodDebugInformation, info.Methods.Length)

defineModuleImportScope ()
Expand Down Expand Up @@ -823,20 +822,19 @@ type PortablePdbGenerator
let contentId = serializer.Serialize blobBuilder
let portablePdbStream = new MemoryStream()
blobBuilder.WriteContentTo portablePdbStream
reportTime showTimes "PDB: Created"
reportTime "PDB: Created"
(portablePdbStream.Length, contentId, portablePdbStream, algorithmName, contentHash)

let generatePortablePdb
(embedAllSource: bool)
(embedSourceList: string list)
(sourceLink: string)
checksumAlgorithm
showTimes
(info: PdbData)
(pathMap: PathMap)
=
let generator =
PortablePdbGenerator(embedAllSource, embedSourceList, sourceLink, checksumAlgorithm, showTimes, info, pathMap)
PortablePdbGenerator(embedAllSource, embedSourceList, sourceLink, checksumAlgorithm, info, pathMap)

generator.Emit()

Expand Down
Loading