Skip to content

Commit fd13a00

Browse files
committed
Revert "记录耗时信息"
This reverts commit 8f14581.
1 parent 679579a commit fd13a00

3 files changed

Lines changed: 3 additions & 66 deletions

File tree

src/MediaConverters/MediaConverters.Lib/Imaging/Optimizations/EnhancedGraphicsMetafileOptimization.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ private static ImageFileOptimizationResult ConvertInLinux(ImageFileOptimizationC
4949

5050
// 在 Linux 上,先尝试使用 Inkscape 进行转换,如失败,再使用 libwmf 进行转换
5151
// 调用 Inkscape 进行转换
52-
var stopwatch = Stopwatch.StartNew();
5352
ImageFileOptimizationResult result = ConvertWithInkscape(context);
54-
stopwatch.Stop();
55-
context.LogMessage($"ConvertWithInkscape Cost {stopwatch.ElapsedMilliseconds}ms");
5653
if (result.OptimizedImageFile is { } svgFile)
5754
{
5855
return ConvertSvgToPngFile(svgFile);
@@ -76,10 +73,7 @@ private static ImageFileOptimizationResult ConvertInLinux(ImageFileOptimizationC
7673

7774
// 使用 libwmf 进行转换
7875

79-
stopwatch.Restart();
8076
result = ConvertWithInkscapeLibWmf(context);
81-
stopwatch.Stop();
82-
context.LogMessage($"ConvertWithInkscapeLibWmf Cost {stopwatch.ElapsedMilliseconds}ms");
8377
if (result.OptimizedImageFile is { } svgLibWmfFile)
8478
{
8579
return ConvertSvgToPngFile(svgLibWmfFile);
@@ -93,13 +87,10 @@ ImageFileOptimizationResult ConvertSvgToPngFile(FileInfo svgImageFile)
9387
{
9488
try
9589
{
96-
stopwatch.Restart();
9790
var convertSvgToPngFile = ImageFileOptimization.ConvertSvgToPngFile(context with
9891
{
9992
ImageFile = svgImageFile
10093
});
101-
stopwatch.Stop();
102-
context.LogMessage($"Convert svg to png file Cost {stopwatch.ElapsedMilliseconds}ms. File='{svgImageFile.FullName}'");
10394
if (convertSvgToPngFile is not null)
10495
{
10596
return new ImageFileOptimizationResult()

src/MediaConverters/MediaConverters.Lib/Imaging/Optimizations/ImageFileOptimization.cs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Diagnostics;
32
using System.IO;
43
using System.Threading;
54
using System.Threading.Tasks;
@@ -30,8 +29,6 @@ public static class ImageFileOptimization
3029
/// <returns></returns>
3130
public static async Task<ImageFileOptimizationResult> OptimizeImageFileAsync(ImageFileOptimizationContext context, bool useAreaSizeLimit = true, bool copyNewFile = true)
3231
{
33-
var stopwatch = Stopwatch.StartNew();
34-
3532
var imageFile = context.ImageFile;
3633
var workingFolder = context.WorkingFolder;
3734
var maxImageWidth = context.MaxImageWidth;
@@ -65,10 +62,6 @@ public static async Task<ImageFileOptimizationResult> OptimizeImageFileAsync(Ima
6562
};
6663
}
6764

68-
stopwatch.Stop();
69-
context.LogMessage($"Copy new file Cost {stopwatch.ElapsedMilliseconds}ms. ImageFile: '{context.ImageFile.FullName}'");
70-
stopwatch.Restart();
71-
7265
if (IsExtension(".svg"))
7366
{
7467
// 如果是 svg 那就直接转换了,因为后续叠加特效等逻辑都不能支持 SVG 格式
@@ -103,9 +96,6 @@ public static async Task<ImageFileOptimizationResult> OptimizeImageFileAsync(Ima
10396
IsExtension(".emf"))
10497
{
10598
var result = EnhancedGraphicsMetafileOptimization.ConvertWmfOrEmfToPngFile(context);
106-
stopwatch.Stop();
107-
context.LogMessage($"ConvertWmfOrEmfToPngFile Cost {stopwatch.ElapsedMilliseconds}ms. ImageFile: '{context.ImageFile.FullName}'");
108-
10999
if (result.OptimizedImageFile is not null)
110100
{
111101
context.LogMessage($"Success ConvertWmfOrEmfToPngFile. Update current image file to '{result.OptimizedImageFile}'");
@@ -120,7 +110,6 @@ public static async Task<ImageFileOptimizationResult> OptimizeImageFileAsync(Ima
120110
}
121111
}
122112

123-
stopwatch.Restart();
124113
context.LogMessage($"Start optimize image with ImageSharp. ImageFile: '{context.ImageFile.FullName}'");
125114

126115
Image<Rgba32> image;
@@ -130,9 +119,6 @@ public static async Task<ImageFileOptimizationResult> OptimizeImageFileAsync(Ima
130119
FileShare.Read);
131120

132121
image = await Image.LoadAsync<Rgba32>(fileStream);
133-
134-
stopwatch.Stop();
135-
context.LogMessage($"Load image with ImageSharp Cost {stopwatch.ElapsedMilliseconds}ms. ImageFile: '{context.ImageFile.FullName}'");
136122
}
137123
catch (ImageFormatException e)
138124
{
@@ -179,25 +165,16 @@ public static async Task<ImageFileOptimizationResult> OptimizeImageFileAsync(Ima
179165
};
180166
}
181167

182-
stopwatch.Restart();
183168
OptimizeImage(image, maxImageWidth, maxImageHeight, useAreaSizeLimit);
184-
stopwatch.Stop();
185-
context.LogMessage(
186-
$"Optimize image with ImageSharp Cost {stopwatch.ElapsedMilliseconds}ms. ImageFile: '{context.ImageFile.FullName}'");
187169

188170
// 重新保存即可
189171
var outputImageFilePath = Path.Join(workingFolder.FullName, $"{Path.GetRandomFileName()}.png");
190-
stopwatch.Restart();
191172
await image.SaveAsPngAsync(outputImageFilePath, new PngEncoder()
192173
{
193174
ColorType = PngColorType.RgbWithAlpha,
194175
BitDepth = PngBitDepth.Bit8,
195176
});
196177

197-
stopwatch.Stop();
198-
context.LogMessage(
199-
$"Save optimized image with ImageSharp Cost {stopwatch.ElapsedMilliseconds}ms. OutputImageFile: '{outputImageFilePath}'");
200-
201178
return new ImageFileOptimizationResult()
202179
{
203180
Image = image,
@@ -336,27 +313,11 @@ public static void LimitImageSize(Image<Rgba32> image, int? maxImageWidth, int?
336313
var imageFile = context.ImageFile;
337314
var workingFolder = context.WorkingFolder;
338315

339-
var stopwatch = Stopwatch.StartNew();
340-
341-
342316
using var skSvg = new SKSvg();
343317
using var skPicture = skSvg.Load(imageFile.FullName);
344-
345-
stopwatch.Stop();
346-
context.LogMessage($"Load sk svg Cost {stopwatch.ElapsedMilliseconds}ms");
347-
348318
var outputFile = Path.Join(workingFolder.FullName,
349319
$"SVG_{Path.GetRandomFileName()}.png");
350-
351-
stopwatch.Restart();
352320
var canSave = skSvg.Save(outputFile, SKColors.Transparent);
353-
stopwatch.Stop();
354-
context.LogMessage($"Save sk svg to png Cost {stopwatch.ElapsedMilliseconds}ms. OutputFile='{outputFile}'");
355-
356-
//var skBitmap = skPicture.ToBitmap(SKColor.Empty, 1,1,SKColorType.Bgra8888,SKAlphaType.Unpremul,null!);
357-
//var pixelSpan = skBitmap.GetPixelSpan();
358-
//Image<Rgba32>.LoadPixelData<Rgba32>(pixelSpan, skBitmap.Width, skBitmap.Height)
359-
360321
if (canSave && File.Exists(outputFile))
361322
{
362323
return new FileInfo(outputFile);

src/MediaConverters/MediaConverters.Tool/Program.cs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,11 @@ static async Task<int> Main(string[] args)
5555

5656
internal static async Task<ErrorCode> RunAsync(Options options)
5757
{
58-
var total = Stopwatch.StartNew();
59-
6058
var stopwatch = Stopwatch.StartNew();
59+
6160
var jsonText = await File.ReadAllTextAsync(options.ConvertConfigurationFile);
62-
stopwatch.Stop();
63-
Console.WriteLine($"ReadJsonFile Cost {stopwatch.ElapsedMilliseconds}ms");
6461

65-
stopwatch.Restart();
6662
var imageConvertContext = ImageConvertContext.FromJsonText(jsonText);
67-
stopwatch.Stop();
68-
Console.WriteLine($"ParseJsonFile Cost {stopwatch.ElapsedMilliseconds}ms");
69-
stopwatch.Restart();
70-
7163

7264
if (imageConvertContext is null)
7365
{
@@ -89,9 +81,6 @@ internal static async Task<ErrorCode> RunAsync(Options options)
8981
ShouldLogToFile = options.ShouldLogToFile ?? false,
9082
};
9183
using var imageFileOptimizationResult = await ImageFileOptimization.OptimizeImageFileAsync(context, useAreaSizeLimit, copyNewFile);
92-
stopwatch.Stop();
93-
Console.WriteLine($"OptimizeImageFileAsync Cost {stopwatch.ElapsedMilliseconds}ms. File='{inputFile.FullName}'");
94-
stopwatch.Restart();
9584

9685
if (!imageFileOptimizationResult.IsSuccess)
9786
{
@@ -142,18 +131,14 @@ internal static async Task<ErrorCode> RunAsync(Options options)
142131
ColorType = PngColorType.RgbWithAlpha,
143132
BitDepth = PngBitDepth.Bit8,
144133
});
145-
146-
stopwatch.Stop();
147-
Console.WriteLine($"Save WorkerProvider Png Cost {stopwatch.ElapsedMilliseconds}ms. File='{inputFile.FullName}'");
148-
stopwatch.Restart();
149134
}
150135
else
151136
{
152137
optimizedImageFile.CopyTo(options.OutputFile, overwrite: true);
153138
}
154139

155-
total.Stop();
156-
context.LogMessage($"Success converted image. Cost {total.ElapsedMilliseconds}ms. OutputFile='{options.OutputFile}'");
140+
stopwatch.Stop();
141+
context.LogMessage($"Success converted image. Cost {stopwatch.ElapsedMilliseconds}ms. OutputFile='{options.OutputFile}'");
157142

158143
return ErrorCode.Success;
159144
}

0 commit comments

Comments
 (0)