Skip to content

Commit 833bd1a

Browse files
Add mcs -merge -dedup -thin support (#256)
1 parent 2b82911 commit 833bd1a

File tree

1 file changed

+19
-51
lines changed

1 file changed

+19
-51
lines changed

src/superpmi/superpmicollect.cs

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ internal class SuperPMICollectionClass
106106
private static string s_baseFailMclFile = null; // Pathname for a temporary .MCL file used for noticing superpmi replay failures against preliminary MCH.
107107
private static string s_finalFailMclFile = null; // Pathname for a temporary .MCL file used for noticing superpmi replay failures against final MCH.
108108
private static string s_baseMchFile = null; // The base .MCH file path
109-
private static string s_nodupMchFile = null; // The nodup .MCH file path
110109
private static string s_finalMchFile = null; // The clean thin unique .MCH file path
111110
private static string s_tocFile = null; // The .TOC file path for the clean thin unique .MCH file
112111
private static string s_errors = ""; // Collect non-fatal file delete errors to display at the end of the collection process.
@@ -146,7 +145,6 @@ private static void ChooseFilePaths(string outputMchPath)
146145
s_baseFailMclFile = Path.Combine(s_tempDir, "basefail.mcl");
147146
s_finalFailMclFile = Path.Combine(s_tempDir, "finalfail.mcl");
148147
s_baseMchFile = Path.Combine(s_tempDir, "base.mch");
149-
s_nodupMchFile = Path.Combine(s_tempDir, "nodup.mch");
150148

151149
if (outputMchPath == null)
152150
{
@@ -341,11 +339,11 @@ private static void CollectMCFiles(string runProgramPath, string runProgramArgum
341339
}
342340

343341
// Merge MC files:
344-
// mcs -merge <s_baseMchFile> <s_tempDir>\*.mc -recursive
342+
// mcs -merge <s_baseMchFile> <s_tempDir>\*.mc -recursive -dedup -thin
345343
private static void MergeMCFiles()
346344
{
347345
string pattern = Path.Combine(s_tempDir, "*.mc");
348-
RunProgram(Global.McsPath, "-merge " + s_baseMchFile + " " + pattern + " -recursive");
346+
RunProgram(Global.McsPath, "-merge " + s_baseMchFile + " " + pattern + " -recursive -dedup -thin");
349347
if (!File.Exists(s_baseMchFile))
350348
{
351349
throw new SpmiException("file missing: " + s_baseMchFile);
@@ -362,54 +360,32 @@ private static void MergeMCFiles()
362360
}
363361
}
364362

365-
// Create a thin unique MCH:
366-
// <mcl> -removeDup -thin <s_baseMchFile> <s_nodupMchFile>
367-
private static void CreateThinUniqueMCH()
368-
{
369-
RunProgram(Global.McsPath, "-removeDup -thin " + s_baseMchFile + " " + s_nodupMchFile);
370-
371-
if (!File.Exists(s_nodupMchFile))
372-
{
373-
throw new SpmiException("file missing: " + s_nodupMchFile);
374-
}
375-
376-
if (!Global.SkipCleanup)
377-
{
378-
// The base file is no longer used; delete it.
379-
if (File.Exists(s_baseMchFile))
380-
{
381-
SafeFileDelete(s_baseMchFile);
382-
s_baseMchFile = null;
383-
}
384-
}
385-
}
386-
387363
// Create clean MCH file:
388-
// <superPmiPath> -p -f <s_baseFailMclFile> <s_nodupMchFile> <jitPath>
364+
// <superPmiPath> -p -f <s_baseFailMclFile> <s_baseMchFile> <jitPath>
389365
// if <s_baseFailMclFile> is non-empty:
390-
// <mcl> -strip <s_baseFailMclFile> <s_nodupMchFile> <s_finalMchFile>
366+
// <mcl> -strip <s_baseFailMclFile> <s_baseMchFile> <s_finalMchFile>
391367
// else:
392-
// move s_nodupMchFile to s_finalMchFile
368+
// move s_baseMchFile to s_finalMchFile
393369
// del <s_baseFailMclFile>
394370
private static void CreateCleanMCHFile()
395371
{
396-
RunProgram(Global.SuperPmiPath, "-p -f " + s_baseFailMclFile + " " + s_nodupMchFile + " " + Global.JitPath);
372+
RunProgram(Global.SuperPmiPath, "-p -f " + s_baseFailMclFile + " " + s_baseMchFile + " " + Global.JitPath);
397373

398374
if (File.Exists(s_baseFailMclFile) && !String.IsNullOrEmpty(File.ReadAllText(s_baseFailMclFile)))
399375
{
400-
RunProgram(Global.McsPath, "-strip " + s_nodupMchFile + " " + s_finalMchFile);
376+
RunProgram(Global.McsPath, "-strip " + s_baseMchFile + " " + s_finalMchFile);
401377
}
402378
else
403379
{
404380
try
405381
{
406-
Console.WriteLine("Moving {0} to {1}", s_nodupMchFile, s_finalMchFile);
407-
File.Move(s_nodupMchFile, s_finalMchFile, overwrite:true);
408-
s_nodupMchFile = null; // This file no longer exists.
382+
Console.WriteLine("Moving {0} to {1}", s_baseMchFile, s_finalMchFile);
383+
File.Move(s_baseMchFile, s_finalMchFile, overwrite:true);
384+
s_baseMchFile = null; // This file no longer exists.
409385
}
410386
catch (Exception ex)
411387
{
412-
string err = string.Format("Error moving file \"{0}\" to \"{1}\": {2}", s_nodupMchFile, s_finalMchFile, ex.Message);
388+
string err = string.Format("Error moving file \"{0}\" to \"{1}\": {2}", s_baseMchFile, s_finalMchFile, ex.Message);
413389
s_errors += err + System.Environment.NewLine;
414390
Console.Error.WriteLine(err);
415391
}
@@ -428,11 +404,11 @@ private static void CreateCleanMCHFile()
428404
s_baseFailMclFile = null;
429405
}
430406

431-
// The nodup file is no longer used.
432-
if ((s_nodupMchFile != null) && File.Exists(s_nodupMchFile))
407+
// The base file is no longer used.
408+
if ((s_baseMchFile != null) && File.Exists(s_baseMchFile))
433409
{
434-
SafeFileDelete(s_nodupMchFile);
435-
s_nodupMchFile = null;
410+
SafeFileDelete(s_baseMchFile);
411+
s_baseMchFile = null;
436412
}
437413
}
438414
}
@@ -476,7 +452,6 @@ private static void VerifyFinalMCH()
476452
// Cleanup. If we get here due to a failure of some kind, we want to do full cleanup. If we get here as part
477453
// of normal shutdown processing, we want to keep the s_finalMchFile and s_tocFile if s_saveFinalMchFile == true.
478454
// del <s_baseMchFile>
479-
// del <s_nodupMchFile>
480455
// del <s_finalMchFile>
481456
// del <s_tocFile>
482457
// rmdir <s_tempDir>
@@ -498,11 +473,6 @@ private static void Cleanup()
498473
SafeFileDelete(s_baseMchFile);
499474
s_baseMchFile = null;
500475
}
501-
if ((s_nodupMchFile != null) && File.Exists(s_nodupMchFile))
502-
{
503-
SafeFileDelete(s_nodupMchFile);
504-
s_nodupMchFile = null;
505-
}
506476

507477
if (!s_saveFinalMchFile)
508478
{
@@ -542,12 +512,11 @@ public static int Collect(string outputMchPath, string runProgramPath, string ru
542512
{
543513
// Do a basic SuperPMI collect and validation:
544514
// 1. Collect MC files by running a set of sample apps.
545-
// 2. Merge the MC files into a single MCH using "mcs -merge *.mc -recursive".
546-
// 3. Create a thin unique MCH by using "mcs -removeDup -thin".
547-
// 4. Create a clean MCH by running superpmi over the MCH, and using "mcs -strip" to filter
515+
// 2. Merge the MC files into a single MCH using "mcs -merge *.mc -recursive -dedup -thin".
516+
// 3. Create a clean MCH by running superpmi over the MCH, and using "mcs -strip" to filter
548517
// out any failures (if any).
549-
// 5. Create a TOC using "mcs -toc".
550-
// 6. Verify the resulting MCH file is error-free when running superpmi against it with the
518+
// 4. Create a TOC using "mcs -toc".
519+
// 5. Verify the resulting MCH file is error-free when running superpmi against it with the
551520
// same JIT used for collection.
552521
//
553522
// MCH files are big. If we don't need them anymore, clean them up right away to avoid
@@ -564,7 +533,6 @@ public static int Collect(string outputMchPath, string runProgramPath, string ru
564533
ChooseFilePaths(outputMchPath);
565534
CollectMCFiles(runProgramPath, runProgramArguments);
566535
MergeMCFiles();
567-
CreateThinUniqueMCH();
568536
CreateCleanMCHFile();
569537
CreateTOC();
570538
VerifyFinalMCH();

0 commit comments

Comments
 (0)