Skip to content

Conversation

@linoal
Copy link
Contributor

@linoal linoal commented Oct 23, 2025

✅ レビュー前確認項目

  • 自動ビルド・テストが通っていること

✅ マージ前確認項目

  • (libcitygmlの変更がある場合)libcitygmlがmasterの最新版になっていること

🚀 実装内容

  • MeshExtractorのログ対応版関数を作ることで、処理時間などをログに出せるようにしました。
  • MeshExtractor各段階の処理時間をログに出すようにしました。

🌐 影響範囲

🛠️ 動作確認

unity sdkのfeat/import_timeブランチで処理時間がログで出ているのを確認できます

⚠️ 懸念点

Summary by CodeRabbit

リリースノート

  • 新機能
    • メッシュ抽出操作にロギング機能を追加しました。抽出プロセスの各ステージにおける診断情報とタイミング情報をキャプチャできるようになりました。
    • C APIおよびC#ラッパーに、ログレベルとコールバック機能を指定できる拡張メソッドを追加しました。

@coderabbitai
Copy link

coderabbitai bot commented Oct 23, 2025

ウォークスルー

メッシュ抽出機能に対してロギング機能を追加します。C++ヘッダーに新たなオーバーロード関数を導入し、C APIラッパーとC#ラッパーを拡張してロギングコールバックをサポートします。実装内ではStopwatch ユーティリティでタイミング計測を行い、主要な処理段階を診断ログに記録します。

変更箇所

コホート / ファイル 変更の要約
C++ヘッダー定義
include/plateau/polygon_mesh/mesh_extractor.h
citygml/citygmllogger.hをインクルード。CityGMLLoggerパラメータを受け取る2つの新規オーバーロード関数(extractextractInExtents)を追加。既存のオーバーロードは変更なし。
C++実装 - メイン機能
src/polygon_mesh/mesh_extractor.cpp
ロギング対応の新規公開メソッド(extractextractInExtents)を追加。Stopwatchユーティリティでタイミング計測を導入。初期化、ループ処理、テクスチャ圧縮など複数段階でタイミングログを記録。内部呼び出しでロガーをスレッドスルー。
C APIラッパー
src/c_wrapper/mesh_extractor_c.cpp
plateau_mesh_extractor_extract_in_extents_with_log関数を追加。ログレベルとコールバック関数を受け取り、PlateauDllLoggerを設定して抽出処理に渡す。APIエラーハンドリングを維持。
C#ラッパー
wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU/PolygonMesh/MeshExtractor.cs
ExtractInExtentsメソッドシグネチャを拡張。オプションのロギングパラメータ(logCallbackslogLevel)を追加。対応するP/Invoke署名plateau_mesh_extractor_extract_in_extents_with_logを新規定義。

シーケンス図

sequenceDiagram
    participant CSharp as C# Client
    participant CWrapper as C Wrapper
    participant CPP as C++ MeshExtractor
    participant Logger as CityGMLLogger
    
    CSharp->>CWrapper: ExtractInExtents(model, options, extents, logCallbacks, logLevel)
    CWrapper->>CWrapper: Create PlateauDllLogger
    CWrapper->>CWrapper: Configure callbacks
    CWrapper->>CPP: extractInExtents(..., logger)
    CPP->>Logger: Initialize Stopwatch
    CPP->>Logger: Log "Initialize" stage
    CPP->>Logger: Log "LOD loop" stage
    CPP->>Logger: Log "Node arrange" stage
    CPP->>Logger: Log "Texture packing" stage
    CPP->>Logger: Log "Map attach" stage
    CPP->>CWrapper: Return Model
    CWrapper->>CSharp: Return APIResult
Loading

見積もりコードレビュー工数

🎯 3 (中程度) | ⏱️ 約20分

複数レイヤ(C++、Cラッパー、C#)にまたがる一貫性のあるロギング機能追加であり、新規メソッドシグネチャ、タイミング計測ロジック、エラーハンドリングの検証が必要です。変更パターンは反復的でホモジーニアスですが、ロギング統合とタイミング機能については各ファイルで個別の確認が必要です。

関連する可能性のあるPR

  • タイルimport用Grid分割処理 #281: MeshExtractorの実装と公開API(include/plateau/polygon_mesh/mesh_extractor.hsrc/polygon_mesh/mesh_extractor.cpp)に対する修正を行う点で関連。新規メソッドオーバーロードの追加と既存メソッドの拡張を含む。

ウサギからのお祝い詩

🐰 ログの光、段階ごとに輝く✨
抽出の旅、時間を記す
C++からC#まで、一貫の流れ
タイミング計測で、謎も解ける
メッシュの物語、今ここに🎭

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed PRのタイトル「MeshExtractorをログ出力に対応させ、各段階の処理時間をログに出すようにした」は、変更セットの主要な目的を明確に反映しています。ヘッダーファイルとC++実装ファイルでログ対応版の関数を追加し、処理の各段階をタイミング情報と共にログ出力する機能を実装しており、タイトルはこの実装内容と完全に一致しています。タイトルは簡潔で具体的であり、チームメンバーが変更履歴を確認する際に、主要な変更内容を直感的に理解できます。
Description Check ✅ Passed PRの説明は、テンプレートの主要な構成要素をほぼ満たしています。「実装内容」セクションにはMeshExtractorのログ対応版関数追加と各段階の処理時間ログ出力機能が記載され、「動作確認」セクションではUnity SDKでの検証結果が示されています。マージ前確認項目とレビュー前確認項目も含まれています。「影響範囲」と「懸念点」は空欄ですが、テンプレートの指示文から見て、具体的な懸念点や影響がない場合は記載不要であることが示唆されており、これらは非必須項目と考えられます。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/log_time

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
include/plateau/polygon_mesh/mesh_extractor.h (2)

37-37: 新しいオーバーロードに対してドキュメントコメントの追加を推奨します。

logger パラメータの目的と使用方法を説明するドキュメントコメントがありません。既存のオーバーロードと同様に、関数の説明を追加することをお勧めします。


48-48: 新しいオーバーロードに対してドキュメントコメントの追加を推奨します。

logger パラメータの目的と使用方法を説明するドキュメントコメントがありません。特に、nullptr を渡した場合のデフォルト動作について記載すると良いでしょう。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e7950e and 4ddc446.

📒 Files selected for processing (4)
  • include/plateau/polygon_mesh/mesh_extractor.h (3 hunks)
  • src/c_wrapper/mesh_extractor_c.cpp (2 hunks)
  • src/polygon_mesh/mesh_extractor.cpp (6 hunks)
  • wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU/PolygonMesh/MeshExtractor.cs (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
include/plateau/polygon_mesh/mesh_extractor.h (1)
src/polygon_mesh/mesh_extractor.cpp (12)
  • extract (213-218)
  • extract (213-214)
  • extract (220-223)
  • extract (220-221)
  • extract (225-227)
  • extract (225-225)
  • extractInExtents (229-236)
  • extractInExtents (229-231)
  • extractInExtents (238-244)
  • extractInExtents (238-241)
  • extractInExtents (246-248)
  • extractInExtents (246-246)
wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU/PolygonMesh/MeshExtractor.cs (4)
wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU/Native/NativeVectorExtent.cs (11)
  • Extent (21-27)
  • NativeVectorExtent (8-80)
  • NativeVectorExtent (10-12)
  • NativeVectorExtent (14-19)
  • Add (40-45)
  • NativeMethods (54-79)
  • DllImport (56-58)
  • DllImport (60-62)
  • DllImport (64-68)
  • DllImport (70-73)
  • DllImport (75-78)
wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU/Native/DllLogger.cs (3)
  • LogCallbacks (23-62)
  • LogCallbacks (39-44)
  • IntPtr (58-61)
src/c_wrapper/mesh_extractor_c.cpp (4)
  • plateau_mesh_extractor_extract_in_extents_with_log (48-56)
  • APIResult (17-24)
  • APIResult (35-43)
  • APIResult (48-62)
wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU/Interop/DLLUtil.cs (3)
  • DLLUtil (25-363)
  • IntPtr (53-58)
  • IntPtr (146-164)
src/c_wrapper/mesh_extractor_c.cpp (1)
src/polygon_mesh/mesh_extractor.cpp (6)
  • extractInExtents (229-236)
  • extractInExtents (229-231)
  • extractInExtents (238-244)
  • extractInExtents (238-241)
  • extractInExtents (246-248)
  • extractInExtents (246-246)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: upload-dlls (macos-14, arm64)
  • GitHub Check: upload-dlls (macos-14, x86_64)
  • GitHub Check: upload-dlls (ubuntu-24.04, x86_64)
  • GitHub Check: upload-dlls (windows-2022, x86_64)
  • GitHub Check: build-and-test (macos-14, arm64)
  • GitHub Check: build-and-test (ubuntu-24.04, x86_64)
  • GitHub Check: build-and-test (windows-2022, x86_64)
🔇 Additional comments (6)
wrappers/csharp/LibPLATEAU.NET/CSharpPLATEAU/PolygonMesh/MeshExtractor.cs (1)

35-51: 実装は正しいですが、API の一貫性を確認してください。

ExtractInExtents メソッドにはログ機能が追加されていますが、Extract メソッド(21行目)にはログ機能がありません。これは意図的な設計ですか?もし Extract が頻繁に使用される場合は、同様のログ機能を追加することを検討してください。

src/c_wrapper/mesh_extractor_c.cpp (1)

48-65: 実装は正しいですが、API の一貫性について確認してください。

plateau_mesh_extractor_extract_in_extents_with_log 関数は追加されていますが、対応する plateau_mesh_extractor_extract_with_log 関数がありません。C# ラッパーでも同様の非対称性が見られます。これが意図的な設計である場合は問題ありませんが、将来的に extract にもログ機能が必要になる可能性を考慮してください。

src/polygon_mesh/mesh_extractor.cpp (4)

73-82: 適切なロガーの初期化とエラーログ記録です。

nullptr チェックによるデフォルトロガーの作成と、例外を投げる前のエラーログ記録は良い実装です。


88-208: 各処理段階での時間計測が適切に実装されています。

Initialize、LOD loop、Node arrange、Texture packing、Map attach の各段階で時間計測とログ出力が行われており、パフォーマンス分析に有用です。PR の目的である「各段階の処理時間をログに出す」が正しく実装されています。


225-227: ロガー対応のオーバーロードが正しく実装されています。

既存の API との互換性を保ちながら、ロガーパラメータを受け取る新しいオーバーロードが追加されています。


246-248: ロガー対応のオーバーロードが正しく実装されています。

extractInExtents についても、既存の API との互換性を保ちながら、ロガーパラメータを受け取る新しいオーバーロードが追加されています。

Comment on lines +23 to +49
class Stopwatch {
public:
Stopwatch(std::shared_ptr<citygml::CityGMLLogger> logger, const std::string& task_name)
: logger_(std::move(logger)), task_name_(task_name) {
total_start_time_ = std::chrono::steady_clock::now();
stage_start_time_ = total_start_time_;
logger_->log(citygml::CityGMLLogger::LOGLEVEL::LL_INFO, task_name_ + " start.");
}

~Stopwatch() {
const auto total_duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - total_start_time_).count();
logger_->log(citygml::CityGMLLogger::LOGLEVEL::LL_INFO, task_name_ + " finished. Total: " + std::to_string(total_duration) + "ms");
}

void log_stage(const std::string& stage_name) {
const auto end_time = std::chrono::steady_clock::now();
const auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - stage_start_time_).count();
logger_->log(citygml::CityGMLLogger::LOGLEVEL::LL_INFO, " " + stage_name + " : " + std::to_string(duration) + "ms");
stage_start_time_ = end_time;
}

private:
std::shared_ptr<citygml::CityGMLLogger> logger_;
std::string task_name_;
std::chrono::steady_clock::time_point total_start_time_;
std::chrono::steady_clock::time_point stage_start_time_;
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Stopwatch のデストラクタでの例外安全性に注意が必要です。

デストラクタ内で logger_->log() を呼び出していますが、スタックアンワインド中にこのデストラクタが呼ばれた場合、log メソッドが例外を投げると std::terminate() が呼ばれてしまいます。

以下のように noexcept 指定と try-catch で保護することを推奨します:

-    ~Stopwatch() {
+    ~Stopwatch() noexcept {
+        try {
             const auto total_duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - total_start_time_).count();
             logger_->log(citygml::CityGMLLogger::LOGLEVEL::LL_INFO, task_name_ + " finished. Total: " + std::to_string(total_duration) + "ms");
+        } catch (...) {
+            // ログ出力に失敗しても無視する
+        }
     }
🤖 Prompt for AI Agents
In src/polygon_mesh/mesh_extractor.cpp around lines 23 to 49, the Stopwatch
destructor calls logger_->log() which can throw during stack unwinding and cause
std::terminate; make the destructor noexcept and wrap its logging calls in a
try-catch block (catch all exceptions) while optionally checking logger_ for
null before use; do the same protection for any final logging in the destructor,
and consider using non-throwing logging helpers or std::terminate-safe fallback
if logging fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants