Skip to content

Commit 0ab0c48

Browse files
committed
chore: 起動時ログ強化 (#1951)
1 parent 20e79dd commit 0ab0c48

6 files changed

Lines changed: 75 additions & 7 deletions

File tree

NeeView/App.xaml.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ private async void Application_Startup(object sender, StartupEventArgs e)
9595

9696
try
9797
{
98+
#if !DEBUG
99+
Trace.Listeners.Clear();
100+
#endif
101+
98102
// [開発用] ログ出力設定
99103
if (!string.IsNullOrEmpty(Environment.LogFile))
100104
{
@@ -138,18 +142,21 @@ private async void Application_Startup(object sender, StartupEventArgs e)
138142
bootLock.Dispose();
139143
}
140144

141-
Trace.WriteLine($"App.Initialized: {Stopwatch.ElapsedMilliseconds}ms");
145+
Debug.WriteLine($"App.Initialized: {Stopwatch.ElapsedMilliseconds}ms");
142146

143147
// ToolTipService default properties
144148
ToolTipService.BetweenShowDelayProperty.OverrideMetadata(typeof(DependencyObject), new FrameworkPropertyMetadata(0));
145149

146150
this.ShutdownMode = ShutdownMode.OnMainWindowClose;
147151

148152
// メインウィンドウ起動
153+
Trace.WriteLine("Create MainWindow");
149154
var mainWindow = new MainWindow();
150155
WindowParameters.Initialize(mainWindow);
151156

152157
NVInterop.NVFpReset();
158+
159+
Trace.WriteLine("Show MainWindow");
153160
mainWindow.Show();
154161

155162
MessageDialog.IsShowInTaskBar = false;
@@ -181,24 +188,29 @@ private async Task InitializeAsync(StartupEventArgs e)
181188
this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
182189

183190
// コマンドライン引数処理
191+
Trace.WriteLine("Parse commandline options");
184192
_option = ParseCommandLineOption(e.Args);
185193

186194
// 待機プロセス指定があれば、そのプロセスの終了を待つ
187195
if (_option.WaitProcess is not null && int.TryParse(_option.WaitProcess, out var pid))
188196
{
197+
Trace.WriteLine($"Wait other process exit ({pid})");
189198
await WaitForProcessExitAsync(pid);
190199
}
191200

192201
// AnimatedImage ライブラリ初期化
202+
Trace.WriteLine("Initialize AnimatedImage");
193203
AnimatedImageChecker.InitializeLibrary();
194204

195205
// APPXデータフォルダ移動 (ver.38)
206+
Trace.WriteLine("Correct LocalAppDataFolder (v38.0)");
196207
Environment.CorrectLocalAppDataFolder();
197208

198209
// カレントディレクトリを実行ファイルの場所に変更。ファイルロック回避のため
199210
System.IO.Directory.SetCurrentDirectory(Environment.AssemblyFolder);
200211

201212
// 多重起動サービス起動
213+
Trace.WriteLine("Run multi boot service");
202214
_multiBootService = new MultiBootService();
203215
await _multiBootService.UpdateServerProcess();
204216

@@ -208,13 +220,16 @@ private async Task InitializeAsync(StartupEventArgs e)
208220
DebugStamp("UserSettingLoading...");
209221

210222
// load UserSetting bytes
223+
Trace.WriteLine("Load UserSetting bytes");
211224
UserSetting? setting = null;
212225
var settingResource = new UserSettingResource(_option.SettingFilename);
213226

214227
// create boot setting
228+
Trace.WriteLine("Create boot setting");
215229
var boot = settingResource.LoadBootSetting();
216230
if (boot is null)
217231
{
232+
Trace.WriteLine("Create full setting");
218233
setting = CreateUserSetting(settingResource);
219234
Debug.Assert(setting.Config is not null);
220235
boot = BootSetting.Create(setting.Config);
@@ -223,23 +238,32 @@ private async Task InitializeAsync(StartupEventArgs e)
223238
// If multiple launches are not possible, send parameters to the main app to terminate.
224239
if (!CanStart(boot.IsMultiBootEnabled))
225240
{
241+
Trace.WriteLine("Call main app...");
226242
await _multiBootService.RemoteRestartAsync(e.Args);
227243
throw new OperationCanceledException("Already started.");
228244
}
229245

230246
// run remote command server
247+
Trace.WriteLine("Run remote command server");
231248
AppRemoteCommandServer.Current.Start();
232249

233250
// show splash screen
251+
Trace.WriteLine("Show splash screen");
234252
ShowSplashScreen(boot);
235253

236254
// initialize before UserSetting
255+
Trace.WriteLine("Initialize Text Resource");
237256
var language = _option.Language ?? boot.Language;
238257
InitializeTextResource(language);
258+
259+
Trace.WriteLine("Initialize HtmlNode");
239260
InitializeHtmlNode();
261+
262+
Trace.WriteLine("Initialize CommandTable");
240263
InitializeCommandTable();
241264

242265
// ensure UserSetting
266+
Trace.WriteLine("Ensure UserSetting");
243267
setting ??= CreateUserSetting(settingResource);
244268
SaveData.Current.SetUserSettingFileStamp(setting.FileStamp);
245269
UserSettingTools.Restore(setting, UserSettingLoadOption.ReplaceConfig);
@@ -260,8 +284,13 @@ private async Task InitializeAsync(StartupEventArgs e)
260284
}
261285

262286
// initialize after UserSetting
287+
Trace.WriteLine("Initialize temporary");
263288
InitializeTemporary(Config.Current);
289+
290+
Trace.WriteLine("Initialize ImeKey");
264291
InitializeImeKey(Config.Current);
292+
293+
Trace.WriteLine("Initialize theme");
265294
InitializeTheme();
266295

267296
AppState.Current.Initialize();

NeeView/BookHistory/BookHistoryCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public void Remove(IEnumerable<string> places)
224224
// 無効な履歴削除
225225
public async Task<int> RemoveUnlinkedAsync(CancellationToken token)
226226
{
227-
LocalDebug.WriteLine($"RemoveUnlinked...");
227+
Trace.WriteLine($"BookHistory.RemoveUnlinked...");
228228

229229
var unlinked = new List<BookHistory>();
230230
foreach (var item in this.ToList())
@@ -241,7 +241,7 @@ public async Task<int> RemoveUnlinkedAsync(CancellationToken token)
241241
HistoryChanged?.Invoke(this, new BookMementoCollectionChangedArgs(BookMementoCollectionChangedType.Remove, null, unlinked));
242242
}
243243

244-
LocalDebug.WriteLine($"RemoveUnlinked done.");
244+
Trace.WriteLine($"BookHistory.RemoveUnlinked done.");
245245
return unlinked.Count;
246246
}
247247

NeeView/MainWindow/MainWindow.xaml.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,24 @@ public MainWindow()
6767
DragDropHelper.AttachDragOverTerminator(this);
6868

6969
// Window状態初期化
70+
Trace.WriteLine("Initialize WindowShapeSnap");
7071
InitializeWindowShapeSnap();
7172

7273
// win proc
7374
_windowProcedure = new WindowProcedure(this);
7475

76+
Trace.WriteLine("Initialize WindowStateManager");
7577
_windowStateManager = new WindowStateManager(this);
7678
_windowController = new MainWindowController(this, _windowStateManager);
7779

80+
Trace.WriteLine("Initialize ContextMenuWatcher");
7881
ContextMenuWatcher.Initialize();
7982

83+
Trace.WriteLine("Initialize MouseHorizontalWheelService");
8084
MouseHorizontalWheelService.SubscribeHorizontalWheelEvent(this);
8185

8286
// 固定画像初期化
87+
Trace.WriteLine("Initialize StaticImages");
8388
ThumbnailResource.InitializeStaticImages();
8489
_ = FileIconCollection.Current.InitializeAsync();
8590

@@ -90,6 +95,7 @@ public MainWindow()
9095
//ContentDropManager.Current.SetDragDropEvent(MainView);
9196

9297
// ViewComponent
98+
Trace.WriteLine("Initialize MainViewComponent");
9399
MainViewComponent.Initialize();
94100
_viewComponent = MainViewComponent.Current;
95101

@@ -123,6 +129,7 @@ public MainWindow()
123129
RoutedCommandTable.Current.AddMouseInput(new MouseInput(mouseContext));
124130

125131
// サイドパネル初期化
132+
Trace.WriteLine("Initialize CustomLayoutPanelManager");
126133
CustomLayoutPanelManager.Initialize();
127134

128135
// 各コントロールとモデルを関連付け
@@ -172,12 +179,11 @@ public MainWindow()
172179
}
173180
});
174181

175-
176-
177182
_windowController.SubscribePropertyChanged(nameof(MainWindowController.AutoHideMode),
178183
(s, e) => AutoHideModeChanged());
179184

180185
// initialize routed commands
186+
Trace.WriteLine("Initialize RoutedCommandTable");
181187
RoutedCommandTable.Current.UpdateInputGestures();
182188

183189
// watch menu bar visibility
@@ -194,6 +200,7 @@ public MainWindow()
194200
this.PreviewStylusDown += MainWindow_PreviewStylusDown;
195201

196202
// mouse activate
203+
Trace.WriteLine("Mouse activate");
197204
_mouseActivate = new MouseActivate(this);
198205

199206
// key event for window
@@ -209,9 +216,11 @@ public MainWindow()
209216
CompositionTarget.Rendering += OnRendering;
210217

211218
// message layer space
219+
Trace.WriteLine("Initialize MessageLayerSpace");
212220
InitializeMessageLayerSpace();
213221

214222
// page caption
223+
Trace.WriteLine("Initialize PageCaption");
215224
InitializePageCaption();
216225

217226
// side panel quick hide
@@ -224,6 +233,7 @@ public MainWindow()
224233
Debug_Initialize();
225234

226235
Debug.WriteLine($"App.MainWindow.Initialize.Done: {App.Current.Stopwatch.ElapsedMilliseconds}ms");
236+
Trace.WriteLine("App.MainWindow.Initialize Done");
227237
}
228238

229239

@@ -452,6 +462,7 @@ protected override void OnSourceInitialized(EventArgs e)
452462

453463
if (App.Current.Resources["Window.Background"] is SolidColorBrush brush)
454464
{
465+
Trace.WriteLine("Win32 Background Brushes");
455466
// Win32 の背景ブラシを設定して起動時のちらつきを軽減するテスト
456467
var hwnd = new WindowInteropHelper(this).Handle;
457468
uint color = (uint)(brush.Color.B << 16 | brush.Color.G << 8 | brush.Color.R);
@@ -461,13 +472,16 @@ protected override void OnSourceInitialized(EventArgs e)
461472
}
462473

463474
// Chrome の情報を最新にする
475+
Trace.WriteLine("Refresh window state");
464476
_windowController.Refresh();
465477

466478
// ウィンドウ座標の復元
467479
// NOTE: PInvoke.SetWindowPlacement() を呼ぶとLoadedイベントが発生する。WindowPlacementの処理順番に注意
480+
Trace.WriteLine("Initialize window place");
468481
InitializeWindowPlace();
469482

470483
Debug.WriteLine($"App.MainWindow.SourceInitialized.Done: {App.Current.Stopwatch.ElapsedMilliseconds}ms");
484+
Trace.WriteLine("App.MainWindow.SourceInitialized Done");
471485
}
472486

473487
private void MainWindow_SourceInitialized(object sender, EventArgs e)
@@ -483,16 +497,20 @@ private void MainWindow_Loaded(object sender, RoutedEventArgs e)
483497

484498
_dpiProvider.SetDipScale(VisualTreeHelper.GetDpi(this));
485499

500+
Trace.WriteLine("Initialize PendingItemManager");
486501
PendingItemManager.Initialize(this);
487502

503+
Trace.WriteLine("Update MainViewManager");
488504
MainViewManager.Current.Update(false);
489505

490506
// レイアウト更新
491507
DirtyWindowLayout();
492508

493509
// WinProc登録
510+
Trace.WriteLine("Initialize SystemDeviceWatcher");
494511
SystemDeviceWatcher.Current.Initialize(this);
495512

513+
Trace.WriteLine("ViewModel.Loaded");
496514
_vm.Loaded();
497515

498516
if (InputGestureDisplayString.ErrorMessages.Count > 0)
@@ -508,14 +526,16 @@ private void MainWindow_Loaded(object sender, RoutedEventArgs e)
508526
this.Activate();
509527
}
510528

511-
Trace.WriteLine($"App.MainWindow.Loaded.Done: {App.Current.Stopwatch.ElapsedMilliseconds}ms");
529+
Debug.WriteLine($"App.MainWindow.Loaded.Done: {App.Current.Stopwatch.ElapsedMilliseconds}ms");
530+
Trace.WriteLine("App.MainWindow.Loaded Done");
512531
}
513532

514533
// ウィンドウコンテンツ表示開始
515534
private async void MainWindow_ContentRendered(object sender, EventArgs e)
516535
{
517536
Debug.WriteLine($"App.MainWindow.ContentRendered: {App.Current.Stopwatch.ElapsedMilliseconds}ms");
518537

538+
Trace.WriteLine("ViewModel.ContentRenderedAsync");
519539
await _vm.ContentRenderedAsync();
520540

521541
// focus
@@ -525,6 +545,7 @@ private async void MainWindow_ContentRendered(object sender, EventArgs e)
525545
}
526546

527547
Debug.WriteLine($"App.MainWindow.ContentRendered.Done: {App.Current.Stopwatch.ElapsedMilliseconds}ms");
548+
Trace.WriteLine("App.MainWindow.ContentRendered Done");
528549

529550
// 初回起動ダイアログ
530551
if (!Config.Current.System.IsLoadedSettings)
@@ -1036,6 +1057,7 @@ public RenameManager GetRenameManager()
10361057
[Conditional("DEBUG")]
10371058
private static void Debug_Initialize()
10381059
{
1060+
Trace.WriteLine("Initialize Debug");
10391061
DebugGesture.Initialize(App.Current.MainWindow);
10401062
}
10411063

NeeView/Picture/PictureFileExtensionTools.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private static Dictionary<string, string> CreateSystemExtensions(bool useWic)
4141
var sw = Stopwatch.StartNew();
4242
var wicMap = WicDecoders.ListUp();
4343
sw.Stop();
44-
Trace.WriteLine($"CreateSystemExtensions({useWic}): {sw.ElapsedMilliseconds}ms");
44+
Debug.WriteLine($"CreateSystemExtensions({useWic}): {sw.ElapsedMilliseconds}ms");
4545

4646
foreach (var pair in map)
4747
{

NeeView/Styles/FileIconCollection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public override int GetHashCode()
6464
public async Task InitializeAsync()
6565
{
6666
await AppDispatcher.BeginInvoke(() => CreateDefaultFolderIcon());
67+
Trace.WriteLine("Initialize StaticImages done.");
6768
}
6869

6970

0 commit comments

Comments
 (0)