diff --git a/docs/api/core/core.md b/docs/api/core/core.md index 03239b3f..973a7e2d 100644 --- a/docs/api/core/core.md +++ b/docs/api/core/core.md @@ -4,6 +4,8 @@ **类型**: `module` +**头文件**: `XCEngine/Core/Core.h` + **描述**: XCEngine 的核心基础模块,提供类型别名、智能指针、事件系统等基础功能。 ## 概述 diff --git a/docs/api/core/event/event.md b/docs/api/core/event/event.md index ce4575cc..e46fbcfb 100644 --- a/docs/api/core/event/event.md +++ b/docs/api/core/event/event.md @@ -4,6 +4,8 @@ **类型**: `class` (template) +**头文件**: `XCEngine/Core/Event.h` + **描述**: 事件系统模板类,提供类型安全的多订阅者事件/委托系统。 ## 概述 diff --git a/docs/api/core/filewriter/Close.md b/docs/api/core/filewriter/Close.md index 85350fe9..f5c9f771 100644 --- a/docs/api/core/filewriter/Close.md +++ b/docs/api/core/filewriter/Close.md @@ -10,6 +10,10 @@ void Close(); 关闭当前打开的文件。如果文件未打开,则什么都不做。析构函数会自动调用此方法。 +**返回:** 无 + +**线程安全:** ❌ + **复杂度:** O(1) **示例:** diff --git a/docs/api/core/filewriter/Flush.md b/docs/api/core/filewriter/Flush.md index e1326091..d4a5cc45 100644 --- a/docs/api/core/filewriter/Flush.md +++ b/docs/api/core/filewriter/Flush.md @@ -12,6 +12,8 @@ bool Flush(); **返回:** `bool` - 是否刷新成功 +**线程安全:** ❌ + **复杂度:** O(1) **示例:** diff --git a/docs/api/core/filewriter/IsOpen.md b/docs/api/core/filewriter/IsOpen.md index 63957437..bcff01dc 100644 --- a/docs/api/core/filewriter/IsOpen.md +++ b/docs/api/core/filewriter/IsOpen.md @@ -12,6 +12,8 @@ bool IsOpen() const; **返回:** `bool` - 文件是否已打开 +**线程安全:** ✅ + **复杂度:** O(1) **示例:** diff --git a/docs/api/core/filewriter/Open.md b/docs/api/core/filewriter/Open.md index d572e394..5e35b5dc 100644 --- a/docs/api/core/filewriter/Open.md +++ b/docs/api/core/filewriter/Open.md @@ -16,6 +16,8 @@ bool Open(const char* filePath, bool append = false); **返回:** `bool` - 是否成功打开 +**线程安全:** ❌ + **复杂度:** O(1) **示例:** diff --git a/docs/api/core/filewriter/Write.md b/docs/api/core/filewriter/Write.md index ce47d085..25c33a05 100644 --- a/docs/api/core/filewriter/Write.md +++ b/docs/api/core/filewriter/Write.md @@ -18,6 +18,8 @@ bool Write(const Containers::String& str); **返回:** `bool` - 是否写入成功 +**线程安全:** ❌ + **复杂度:** O(n) 其中 n 为写入的字节数 **示例:** diff --git a/docs/api/core/filewriter/ctor-default.md b/docs/api/core/filewriter/ctor-default.md new file mode 100644 index 00000000..9624cbc1 --- /dev/null +++ b/docs/api/core/filewriter/ctor-default.md @@ -0,0 +1,36 @@ +# FileWriter::FileWriter (默认构造) + +```cpp +FileWriter(); +``` + +默认构造 FileWriter 对象,不打开任何文件。 + +**描述** + +创建 FileWriter 实例,m_file 初始化为 nullptr。可后续通过 Open 方法打开文件。 + +**线程安全:** ❌ + +**复杂度:** O(1) + +**示例:** + +```cpp +#include + +using namespace XCEngine::Core; + +FileWriter writer; +if (!writer.IsOpen()) { + writer.Open("output.txt"); + writer.Write("Hello\n"); + writer.Close(); +} +``` + +## 相关文档 + +- [FileWriter 总览](filewriter.md) - 返回类总览 +- [Open](Open.md) - 打开文件 +- [FileWriter(filePath, append)](ctor-file.md) - 构造并打开文件 diff --git a/docs/api/core/filewriter/ctor-file.md b/docs/api/core/filewriter/ctor-file.md new file mode 100644 index 00000000..4c855e0b --- /dev/null +++ b/docs/api/core/filewriter/ctor-file.md @@ -0,0 +1,45 @@ +# FileWriter::FileWriter (文件路径构造) + +```cpp +FileWriter(const char* filePath, bool append = false); +``` + +构造 FileWriter 对象并打开文件。 + +**描述** + +创建 FileWriter 实例并尝试打开指定路径的文件。如果 append 为 true,则以追加模式打开;否则以覆盖模式打开。 + +**参数:** +- `filePath` - 要打开的文件路径 +- `append` - 是否以追加模式打开,默认 false(覆盖模式) + +**线程安全:** ❌ + +**复杂度:** O(1) + +**示例:** + +```cpp +#include + +using namespace XCEngine::Core; + +// 覆盖模式打开 +FileWriter writer1("output.txt"); +if (writer1.IsOpen()) { + writer1.Write("Content\n"); +} + +// 追加模式打开 +FileWriter writer2("log.txt", true); +if (writer2.IsOpen()) { + writer2.Write("New log entry\n"); +} +``` + +## 相关文档 + +- [FileWriter 总览](filewriter.md) - 返回类总览 +- [Open](Open.md) - 打开文件 +- [FileWriter()](ctor-default.md) - 默认构造 diff --git a/docs/api/core/filewriter/dtor.md b/docs/api/core/filewriter/dtor.md new file mode 100644 index 00000000..136b68ad --- /dev/null +++ b/docs/api/core/filewriter/dtor.md @@ -0,0 +1,33 @@ +# FileWriter::~FileWriter + +```cpp +~FileWriter(); +``` + +析构函数,自动关闭文件。 + +**描述** + +销毁 FileWriter 实例,如果文件处于打开状态则自动调用 Close 关闭文件,释放 FILE* 资源。 + +**线程安全:** ❌ + +**复杂度:** O(1) + +**示例:** + +```cpp +#include + +using namespace XCEngine::Core; + +{ + FileWriter writer("output.txt"); + writer.Write("Content inside scope\n"); +} // 析构时自动关闭文件 +``` + +## 相关文档 + +- [FileWriter 总览](filewriter.md) - 返回类总览 +- [Close](Close.md) - 关闭文件 diff --git a/docs/api/core/filewriter/filewriter.md b/docs/api/core/filewriter/filewriter.md index b1fe6b51..c1539a0b 100644 --- a/docs/api/core/filewriter/filewriter.md +++ b/docs/api/core/filewriter/filewriter.md @@ -4,6 +4,8 @@ **类型**: `class` +**头文件**: `XCEngine/Core/FileWriter.h` + **描述**: 文件写入工具类,提供简单的文件写入操作封装。 ## 概述 @@ -14,9 +16,9 @@ | 方法 | 描述 | |------|------| -| `FileWriter()` | 默认构造(不打开文件) | -| `FileWriter(const char* filePath, bool append = false)` | 构造并打开文件 | -| `~FileWriter()` | 析构函数,自动关闭文件 | +| [`FileWriter()`](ctor-default.md) | 默认构造(不打开文件) | +| [`FileWriter(filePath, append)`](ctor-file.md) | 构造并打开文件 | +| [`~FileWriter()`](dtor.md) | 析构函数,自动关闭文件 | | [`Open`](Open.md) | 打开文件,append=true 时为追加模式 | | [`Close`](Close.md) | 关闭文件 | | [`IsOpen`](IsOpen.md) | 检查文件是否已打开 | diff --git a/docs/api/core/refcounted/AddRef.md b/docs/api/core/refcounted/AddRef.md index 8e1972b1..3f294fbb 100644 --- a/docs/api/core/refcounted/AddRef.md +++ b/docs/api/core/refcounted/AddRef.md @@ -4,34 +4,40 @@ void AddRef(); ``` -增加引用计数。 +原子地增加引用计数。 **描述** 原子地增加引用计数。在复制 `RefCounted` 指针或传递引用时调用此方法。 +**线程安全:** ✅ + **复杂度:** O(1) **示例:** ```cpp #include +#include -class MyObject : public RefCounted { +class MyObject : public XCEngine::Core::RefCounted { public: - void DoSomething() { /* ... */ } + void DoSomething() { } }; -// 创建对象(构造时 refCount = 1) -MyObject* obj = new MyObject(); - -// 手动增加引用 -obj->AddRef(); // refCount = 2 -obj->AddRef(); // refCount = 3 - -// 需要释放额外的引用 -obj->Release(); // refCount = 2 -obj->Release(); // refCount = 1 +int main() { + MyObject* obj = new MyObject(); + printf("After create: %u\n", obj->GetRefCount()); + + obj->AddRef(); + printf("After AddRef: %u\n", obj->GetRefCount()); + + obj->Release(); + printf("After Release: %u\n", obj->GetRefCount()); + + obj->Release(); + return 0; +} ``` ## 相关文档 diff --git a/docs/api/core/refcounted/GetRefCount.md b/docs/api/core/refcounted/GetRefCount.md index 16c69a0d..a86124d8 100644 --- a/docs/api/core/refcounted/GetRefCount.md +++ b/docs/api/core/refcounted/GetRefCount.md @@ -12,28 +12,36 @@ uint32_t GetRefCount() const; **返回:** `uint32_t` - 当前引用计数 +**线程安全:** ✅ + **复杂度:** O(1) **示例:** ```cpp #include +#include -class MyObject : public RefCounted { +class MyObject : public XCEngine::Core::RefCounted { public: void Debug() { printf("RefCount: %u\n", GetRefCount()); } }; -MyObject* obj = new MyObject(); -printf("After create: %u\n", obj->GetRefCount()); // 1 - -obj->AddRef(); -printf("After AddRef: %u\n", obj->GetRefCount()); // 2 - -obj->Release(); -printf("After Release: %u\n", obj->GetRefCount()); // 1 +int main() { + MyObject* obj = new MyObject(); + printf("After create: %u\n", obj->GetRefCount()); + + obj->AddRef(); + printf("After AddRef: %u\n", obj->GetRefCount()); + + obj->Release(); + printf("After Release: %u\n", obj->GetRefCount()); + + obj->Release(); + return 0; +} ``` ## 相关文档 diff --git a/docs/api/core/refcounted/Release.md b/docs/api/core/refcounted/Release.md index a3ac6763..3cd20df8 100644 --- a/docs/api/core/refcounted/Release.md +++ b/docs/api/core/refcounted/Release.md @@ -4,33 +4,40 @@ void Release(); ``` -减少引用计数。 +原子地减少引用计数。 **描述** 原子地减少引用计数。当引用计数归零时,对象会自动 `delete this`。这是实现自动内存管理的关键方法。 -**复杂度:** O(1)(归零时为 O(n),n 为对象大小) +**线程安全:** ✅ + +**复杂度:** O(1) **示例:** ```cpp #include +#include -class MyObject : public RefCounted { +class MyObject : public XCEngine::Core::RefCounted { public: - void DoSomething() { /* ... */ } + void DoSomething() { } }; -// 创建对象(构造时 refCount = 1) -MyObject* obj = new MyObject(); - -// 手动增加引用 -obj->AddRef(); // refCount = 2 - -// 释放引用 -obj->Release(); // refCount = 1 -obj->Release(); // refCount = 0, 对象被自动 delete +int main() { + MyObject* obj = new MyObject(); + printf("After create: %u\n", obj->GetRefCount()); + + obj->AddRef(); + printf("After AddRef: %u\n", obj->GetRefCount()); + + obj->Release(); + printf("After Release: %u\n", obj->GetRefCount()); + + obj->Release(); + return 0; +} ``` ## 相关文档 diff --git a/docs/api/core/refcounted/refcounted.md b/docs/api/core/refcounted/refcounted.md index 947bf283..e31d24f2 100644 --- a/docs/api/core/refcounted/refcounted.md +++ b/docs/api/core/refcounted/refcounted.md @@ -4,6 +4,8 @@ **类型**: `class` +**头文件**: `XCEngine/Core/RefCounted.h` + **描述**: 引用计数基类,提供线程安全的引用计数生命周期管理。 ## 概述 @@ -14,28 +16,39 @@ | 方法 | 描述 | |------|------| -| `RefCounted()` | 构造函数,初始引用计数为 1 | -| `virtual ~RefCounted()` | 虚析构函数 | -| [`AddRef`](AddRef.md) | 增加引用计数 | -| [`Release`](Release.md) | 减少引用计数(归零时自动 delete this) | -| [`GetRefCount`](GetRefCount.md) | 获取当前引用计数 | +| [`RefCounted()`](refcounted.md) | 构造函数,初始引用计数为 1 | +| [`~RefCounted()`](refcounted.md) | 虚析构函数 | +| [`AddRef()`](AddRef.md) | 增加引用计数 | +| [`Release()`](Release.md) | 减少引用计数(归零时自动 delete this) | +| [`GetRefCount()`](GetRefCount.md) | 获取当前引用计数 | ## 使用示例 ```cpp -class MyObject : public RefCounted { +#include +#include + +class MyObject : public XCEngine::Core::RefCounted { public: - MyObject() { /* ... */ } - ~MyObject() { /* ... */ } + MyObject() { } + virtual ~MyObject() { } - void DoSomething() { /* ... */ } + void DoSomething() { } }; -// 使用 -MyObject* obj = new MyObject(); // refCount = 1 -obj->AddRef(); // refCount = 2 -obj->Release(); // refCount = 1 -obj->Release(); // refCount = 0, 自动 delete +int main() { + MyObject* obj = new MyObject(); + printf("After create: %u\n", obj->GetRefCount()); + + obj->AddRef(); + printf("After AddRef: %u\n", obj->GetRefCount()); + + obj->Release(); + printf("After Release: %u\n", obj->GetRefCount()); + + obj->Release(); + return 0; +} ``` ## 相关文档 diff --git a/docs/api/core/smartptr/smartptr.md b/docs/api/core/smartptr/smartptr.md index f87ee2d0..74c0eedb 100644 --- a/docs/api/core/smartptr/smartptr.md +++ b/docs/api/core/smartptr/smartptr.md @@ -4,6 +4,8 @@ **类型**: `header-only` +**头文件**: `XCEngine/Core/SmartPtr.h` + **描述**: 智能指针类型别名和工厂函数,提供 `std::shared_ptr` 和 `std::unique_ptr` 的简化接口。 ## 概述 diff --git a/docs/api/core/types/byte.md b/docs/api/core/types/byte.md index eff9330d..23de7d1f 100644 --- a/docs/api/core/types/byte.md +++ b/docs/api/core/types/byte.md @@ -10,8 +10,6 @@ using byte = uint8_t; `byte` 是 1 字节无符号整数类型,专门用于表示原始字节数据。语义上比 `uint8` 更清晰,适用于二进制数据、内存缓冲区等场景。 -**复杂度:** O(1) - **示例:** ```cpp diff --git a/docs/api/core/types/int16.md b/docs/api/core/types/int16.md index fc666edd..88971f38 100644 --- a/docs/api/core/types/int16.md +++ b/docs/api/core/types/int16.md @@ -10,8 +10,6 @@ using int16 = int16_t; `int16` 是 16 位(2 字节)有符号整数类型,范围为 -32,768 到 32,767。该类型别名确保跨平台一致性。 -**复杂度:** O(1) - **示例:** ```cpp diff --git a/docs/api/core/types/int32.md b/docs/api/core/types/int32.md index 9c4aeb3f..12c3b050 100644 --- a/docs/api/core/types/int32.md +++ b/docs/api/core/types/int32.md @@ -10,8 +10,6 @@ using int32 = int32_t; `int32` 是 32 位(4 字节)有符号整数类型,范围为 -2,147,483,648 到 2,147,483,647。该类型别名确保跨平台一致性,是最常用的整数类型。 -**复杂度:** O(1) - **示例:** ```cpp diff --git a/docs/api/core/types/int64.md b/docs/api/core/types/int64.md index 7d80c404..842bacbf 100644 --- a/docs/api/core/types/int64.md +++ b/docs/api/core/types/int64.md @@ -10,8 +10,6 @@ using int64 = int64_t; `int64` 是 64 位(8 字节)有符号整数类型,范围为 -9,223,372,036,854,775,808 到 9,223,372,036,854,775,807。该类型别名用于需要大范围整数的场景,如时间戳、大文件大小等。 -**复杂度:** O(1) - **示例:** ```cpp diff --git a/docs/api/core/types/int8.md b/docs/api/core/types/int8.md index 348d020b..6a402d33 100644 --- a/docs/api/core/types/int8.md +++ b/docs/api/core/types/int8.md @@ -10,8 +10,6 @@ using int8 = int8_t; `int8` 是 8 位(1 字节)有符号整数类型,范围为 -128 到 127。该类型别名确保跨平台一致性。 -**复杂度:** O(1) - **示例:** ```cpp diff --git a/docs/api/core/types/types.md b/docs/api/core/types/types.md index 645077f8..11b12105 100644 --- a/docs/api/core/types/types.md +++ b/docs/api/core/types/types.md @@ -2,7 +2,7 @@ **命名空间**: `XCEngine::Core` -**类型**: `header` (type aliases) +**类型**: `类型别名定义` **头文件**: `XCEngine/Core/Types.h` @@ -26,9 +26,9 @@ | `uint64` | `uint64_t` | 64位无符号整数 | | `byte` | `uint8_t` | 字节类型 | -## 公共方法 +## 类型定义 -| 方法 | 描述 | +| 类型 | 描述 | |------|------| | [`int8`](int8.md) | 8位有符号整数类型别名 | | [`int16`](int16.md) | 16位有符号整数类型别名 | @@ -59,5 +59,4 @@ void ProcessData(Core::uint32 size, const Core::int8* data); ## 相关文档 -- [Core 模块总览](../core.md) - 返回模块总览 -- [SmartPtr](../smartptr/smartptr.md) - 智能指针 +- [SmartPtr](../smartptr/smartptr.md) - 智能指针(该文档暂缺) diff --git a/docs/api/core/types/uint16.md b/docs/api/core/types/uint16.md index 3b4a42bc..167e657b 100644 --- a/docs/api/core/types/uint16.md +++ b/docs/api/core/types/uint16.md @@ -10,8 +10,6 @@ using uint16 = uint16_t; `uint16` 是 16 位(2 字节)无符号整数类型,范围为 0 到 65,535。常用于 Unicode 字符、端口号等场景。 -**复杂度:** O(1) - **示例:** ```cpp diff --git a/docs/api/core/types/uint32.md b/docs/api/core/types/uint32.md index 4caae087..92355349 100644 --- a/docs/api/core/types/uint32.md +++ b/docs/api/core/types/uint32.md @@ -10,8 +10,6 @@ using uint32 = uint32_t; `uint32` 是 32 位(4 字节)无符号整数类型,范围为 0 到 4,294,967,295。常用于 ID、计数、大小等场景。 -**复杂度:** O(1) - **示例:** ```cpp diff --git a/docs/api/core/types/uint64.md b/docs/api/core/types/uint64.md index ab23116c..185f1817 100644 --- a/docs/api/core/types/uint64.md +++ b/docs/api/core/types/uint64.md @@ -10,8 +10,6 @@ using uint64 = uint64_t; `uint64` 是 64 位(8 字节)无符号整数类型,范围为 0 到 18,446,744,073,709,551,615。用于需要极大整数范围的场景,如大文件大小、精确时间等。 -**复杂度:** O(1) - **示例:** ```cpp diff --git a/docs/api/core/types/uint8.md b/docs/api/core/types/uint8.md index 6b55bc5f..eb0631fd 100644 --- a/docs/api/core/types/uint8.md +++ b/docs/api/core/types/uint8.md @@ -10,8 +10,6 @@ using uint8 = uint8_t; `uint8` 是 8 位(1 字节)无符号整数类型,范围为 0 到 255。常用于字节数据、颜色分量(RGB)等场景。 -**复杂度:** O(1) - **示例:** ```cpp diff --git a/docs/api/debug/consolelogsink/consolelogsink.md b/docs/api/debug/consolelogsink/consolelogsink.md index 8a43dd2d..7459bc34 100644 --- a/docs/api/debug/consolelogsink/consolelogsink.md +++ b/docs/api/debug/consolelogsink/consolelogsink.md @@ -1,21 +1,50 @@ -# ConsoleLogSink::ConsoleLogSink +# ConsoleLogSink + +**命名空间**: `XCEngine::Debug` + +**类型**: `class` + +**头文件**: `XCEngine/Debug/ConsoleLogSink.h` + +**描述**: 控制台日志输出目标,将日志输出到标准输出流。 + +## 概述 + +`ConsoleLogSink` 是日志系统的控制台输出实现。它将日志条目输出到标准输出流(stdout),支持彩色输出和日志级别过滤。该类继承自 `ILogSink` 接口,可通过 `Logger::AddSink` 添加到日志系统。 + +设计用于开发调试场景,默认启用彩色输出便于在终端中区分不同日志级别。 + +## 公共方法 + +| 方法 | 描述 | +|------|------| +| [`ConsoleLogSink()`](constructor.md) | 构造函数 | +| [`~ConsoleLogSink`](destructor.md) | 析构函数 | +| [`Log`](log.md) | 输出日志到控制台 | +| [`Flush`](flush.md) | 刷新输出流 | +| [`SetColorOutput`](setcoloroutput.md) | 设置彩色输出 | +| [`SetMinimumLevel`](setminimumlevel.md) | 设置最小日志级别 | + +## 使用示例 ```cpp -ConsoleLogSink() -``` +#include -默认构造函数。创建一个 `ConsoleLogSink` 实例,默认启用彩色输出,最小日志级别为 `Verbose`。 - -**复杂度:** O(1) - -**示例:** - -```cpp auto sink = std::make_unique(); +sink->SetColorOutput(true); +sink->SetMinimumLevel(XCEngine::Debug::LogLevel::Warning); XCEngine::Debug::Logger::Get().AddSink(std::move(sink)); ``` +## 构造函数详细 + +| 属性 | 值 | +|------|-----| +| 默认 `m_colorOutput` | `true` | +| 默认 `m_minimumLevel` | `LogLevel::Verbose` | + ## 相关文档 -- [ConsoleLogSink 总览](overview.md) - 返回类总览 - [Debug 模块总览](../debug.md) - 返回模块总览 +- [Logger](../logger/logger.md) - 日志记录器 +- [ILogSink](../ilogsink/ilogsink.md) - 日志输出接口 diff --git a/docs/api/debug/consolelogsink/constructor.md b/docs/api/debug/consolelogsink/constructor.md new file mode 100644 index 00000000..8dcd9637 --- /dev/null +++ b/docs/api/debug/consolelogsink/constructor.md @@ -0,0 +1,27 @@ +# ConsoleLogSink::ConsoleLogSink + +```cpp +ConsoleLogSink() +``` + +默认构造函数。创建一个 `ConsoleLogSink` 实例。 + +**线程安全:** ✅ + +**复杂度:** O(1) + +**返回值:** 无 + +**示例:** + +```cpp +using namespace XCEngine::Debug; + +auto sink = std::make_unique(); +Logger::Get().AddSink(std::move(sink)); +``` + +## 相关文档 + +- [ConsoleLogSink 总览](consolelogsink.md) - 返回类总览 +- [Debug 模块总览](../debug.md) - 返回模块总览 diff --git a/docs/api/debug/consolelogsink/~consolelogsink.md b/docs/api/debug/consolelogsink/destructor.md similarity index 53% rename from docs/api/debug/consolelogsink/~consolelogsink.md rename to docs/api/debug/consolelogsink/destructor.md index 802c70e5..1defe091 100644 --- a/docs/api/debug/consolelogsink/~consolelogsink.md +++ b/docs/api/debug/consolelogsink/destructor.md @@ -6,8 +6,20 @@ 析构函数。销毁 `ConsoleLogSink` 实例,释放相关资源。 +**线程安全:** ✅ + **复杂度:** O(1) +**返回值:** 无 + +**示例:** + +```cpp +auto sink = std::make_unique(); +// sink 自动销毁 +``` + ## 相关文档 - [ConsoleLogSink 总览](consolelogsink.md) - 返回类总览 +- [Debug 模块总览](../debug.md) - 返回模块总览 diff --git a/docs/api/debug/consolelogsink/flush.md b/docs/api/debug/consolelogsink/flush.md index bccfde91..aa8ea4fb 100644 --- a/docs/api/debug/consolelogsink/flush.md +++ b/docs/api/debug/consolelogsink/flush.md @@ -6,8 +6,12 @@ void Flush() override 刷新标准输出流(stdout),调用 `fflush(stdout)` 确保所有待输出的日志内容立即显示在控制台上。 +**线程安全:** ❌ + **复杂度:** O(1) +**返回值:** 无 + **示例:** ```cpp diff --git a/docs/api/debug/consolelogsink/log.md b/docs/api/debug/consolelogsink/log.md index 44f6af57..37361cf7 100644 --- a/docs/api/debug/consolelogsink/log.md +++ b/docs/api/debug/consolelogsink/log.md @@ -4,13 +4,30 @@ void Log(const LogEntry& entry) override ``` -将日志输出到控制台。根据 `LogEntry` 的级别和分类格式化输出内容,并根据 `m_colorOutput` 设置决定是否使用 Windows 控制台颜色 API。如果日志级别低于设置的最小级别,则不输出。 +将日志输出到控制台。输出格式为 `[LEVEL] [CATEGORY] message\n`。 + +根据 `m_colorOutput` 设置决定是否使用 Windows 控制台颜色 API(仅 `_WIN32` 平台)。各日志级别颜色映射: + +| 级别 | 颜色 | +|------|------| +| Verbose | 灰色(低亮度) | +| Debug | 青色(蓝+绿) | +| Info | 绿色 | +| Warning | 黄色(红+绿) | +| Error | 红色(高亮度) | +| Fatal | 洋红色(红+蓝+高亮度) | + +如果日志级别低于设置的最小级别,则不输出。 **参数:** -- `entry` - 日志条目 +- `entry` - 日志条目(参见 [LogEntry](../logentry/logentry.md)) + +**线程安全:** ❌ **复杂度:** O(1) +**返回值:** 无 + **示例:** ```cpp diff --git a/docs/api/debug/consolelogsink/overview.md b/docs/api/debug/consolelogsink/overview.md deleted file mode 100644 index f54f8ce1..00000000 --- a/docs/api/debug/consolelogsink/overview.md +++ /dev/null @@ -1,41 +0,0 @@ -# ConsoleLogSink - -**命名空间**: `XCEngine::Debug` - -**类型**: `class` - -**头文件**: `XCEngine/Debug/ConsoleLogSink.h` - -**描述**: 控制台日志输出目标,将日志输出到标准输出流。 - -## 概述 - -`ConsoleLogSink` 是日志系统的控制台输出实现。它将日志条目输出到标准输出流(stdout),支持彩色输出和日志级别过滤。 - -## 公共方法 - -| 方法 | 描述 | -|------|------| -| `ConsoleLogSink()` | [构造函数](consolelogsink.md) | -| `~ConsoleLogSink()` | [析构函数](~consolelogsink.md) | -| `void Log(const LogEntry& entry)` | [输出日志到控制台](log.md) | -| `void Flush()` | [刷新输出流](flush.md) | -| `void SetColorOutput(bool enable)` | [设置彩色输出](setcoloroutput.md) | -| `void SetMinimumLevel(LogLevel level)` | [设置最小日志级别](setminimumlevel.md) | - -## 使用示例 - -```cpp -#include - -auto sink = std::make_unique(); -sink->SetColorOutput(true); -sink->SetMinimumLevel(XCEngine::Debug::LogLevel::Warning); -XCEngine::Debug::Logger::Get().AddSink(std::move(sink)); -``` - -## 相关文档 - -- [Debug 模块总览](../debug.md) - 返回模块总览 -- [Logger](../logger/logger.md) - 日志记录器 -- [ILogSink](../ilogsink/ilogsink.md) - 日志输出接口 diff --git a/docs/api/debug/consolelogsink/setcoloroutput.md b/docs/api/debug/consolelogsink/setcoloroutput.md index 1bea3754..d8866ad6 100644 --- a/docs/api/debug/consolelogsink/setcoloroutput.md +++ b/docs/api/debug/consolelogsink/setcoloroutput.md @@ -4,13 +4,17 @@ void SetColorOutput(bool enable) ``` -启用或禁用控制台彩色输出。启用后,不同日志级别使用 Windows 控制台颜色 API 输出,便于快速区分日志类型。 +启用或禁用控制台彩色输出。启用后,不同日志级别使用 Windows 控制台颜色 API 输出(仅 `_WIN32` 平台有效,其他平台此设置无效果),便于快速区分日志类型。 **参数:** - `enable` - true 启用彩色输出,false 禁用 +**线程安全:** ❌ + **复杂度:** O(1) +**返回值:** 无 + **示例:** ```cpp diff --git a/docs/api/debug/consolelogsink/setminimumlevel.md b/docs/api/debug/consolelogsink/setminimumlevel.md index 8b64fa10..bc3273e3 100644 --- a/docs/api/debug/consolelogsink/setminimumlevel.md +++ b/docs/api/debug/consolelogsink/setminimumlevel.md @@ -4,13 +4,17 @@ void SetMinimumLevel(LogLevel level) ``` -设置该 Sink 的最小输出级别。此设置仅影响当前 Sink,不会影响 Logger 的全局级别过滤。 +设置该 Sink 的最小输出级别。此设置仅影响当前 Sink,不会影响 Logger 的全局级别过滤。默认值为 `LogLevel::Verbose`,即输出所有级别。 **参数:** - `level` - 最小日志级别 +**线程安全:** ❌ + **复杂度:** O(1) +**返回值:** 无 + **示例:** ```cpp diff --git a/docs/api/debug/debug.md b/docs/api/debug/debug.md index 3ade25d0..749e1920 100644 --- a/docs/api/debug/debug.md +++ b/docs/api/debug/debug.md @@ -4,6 +4,8 @@ **类型**: `module` +**头文件**: `XCEngine/Debug/Debug.h` + **描述**: XCEngine 的调试和日志模块,提供日志记录和性能分析功能。 ## 概述 @@ -77,8 +79,8 @@ if (condition) { XE_LOG(LogCategory::General, LogLevel::Error, "Something went wrong"); } -// 使用断言 -XE_ASSERT(ptr != nullptr, "Pointer must not be null"); +// 使用断言(仅记录Fatal日志,不会中断程序) +XC_ASSERT(ptr != nullptr, "Pointer must not be null"); ``` ## 相关文档 diff --git a/docs/api/debug/filelogsink/construct.md b/docs/api/debug/filelogsink/construct.md index db32c9a2..848d1226 100644 --- a/docs/api/debug/filelogsink/construct.md +++ b/docs/api/debug/filelogsink/construct.md @@ -9,6 +9,8 @@ FileLogSink(const Containers::String& filePath) **参数:** - `filePath` - 日志文件路径 +**线程安全:** ✅ 构造函数本身是线程安全的,但多线程同时创建同一文件可能会产生竞争 + **复杂度:** O(1) **示例:** diff --git a/docs/api/debug/filelogsink/filelogsink.md b/docs/api/debug/filelogsink/filelogsink.md index a3379d45..19a372a2 100644 --- a/docs/api/debug/filelogsink/filelogsink.md +++ b/docs/api/debug/filelogsink/filelogsink.md @@ -16,10 +16,10 @@ | 方法 | 描述 | |------|------| -| `FileLogSink(const Containers::String& filePath)` | [构造函数](construct.md) | -| `~FileLogSink()` | [析构函数](~filelogsink.md) | -| `void Log(const LogEntry& entry)` | [输出日志到文件](log.md) | -| `void Flush()` | [刷新缓冲区](flush.md) | +| [`FileLogSink(const Containers::String& filePath)`](construct.md) | 打开指定路径的文件用于日志写入 | +| [`~FileLogSink()`](~filelogsink.md) | 销毁实例并刷新缓冲区 | +| [`Log(const LogEntry& entry)`](log.md) | 将日志条目追加写入文件 | +| [`Flush()`](flush.md) | 刷新文件缓冲区确保数据写入磁盘 | ## 使用示例 diff --git a/docs/api/debug/filelogsink/flush.md b/docs/api/debug/filelogsink/flush.md index 7dd078a4..ceabf3f8 100644 --- a/docs/api/debug/filelogsink/flush.md +++ b/docs/api/debug/filelogsink/flush.md @@ -6,19 +6,22 @@ void Flush() override 刷新文件缓冲区,调用底层 `FileWriter` 的 flush 方法确保所有待写入的日志数据已实际写入磁盘。 +**线程安全:** ✅ 线程安全 + **复杂度:** O(1) **示例:** ```cpp +#include + auto fileSink = std::make_unique("logs/app.log"); -XCEngine::Debug::Logger::Get().AddSink(std::move(fileSink)); -// 关键操作后立即刷新 -XCEngine::Debug::Logger::Get().Info(XCEngine::Debug::LogCategory::General, "Checkpoint saved"); -// 确保写入磁盘 -XCEngine::Debug::Logger::Get().Flush(); +// 关键操作后立即刷新确保写入磁盘 +fileSink->Flush(); ``` +**注意:** `Flush()` 需要直接调用 `FileLogSink` 实例,不能通过 `Logger` 调用。 + ## 相关文档 - [FileLogSink 总览](filelogsink.md) - 返回类总览 diff --git a/docs/api/debug/filelogsink/log.md b/docs/api/debug/filelogsink/log.md index 91563a9e..9e69d470 100644 --- a/docs/api/debug/filelogsink/log.md +++ b/docs/api/debug/filelogsink/log.md @@ -9,6 +9,8 @@ void Log(const LogEntry& entry) override **参数:** - `entry` - 日志条目 +**线程安全:** ❌ 非线程安全,多线程同时调用 Log 可能导致数据竞争 + **复杂度:** O(m),m 为消息长度 **示例:** diff --git a/docs/api/debug/filelogsink/~filelogsink.md b/docs/api/debug/filelogsink/~filelogsink.md index 17d32059..97cce9ec 100644 --- a/docs/api/debug/filelogsink/~filelogsink.md +++ b/docs/api/debug/filelogsink/~filelogsink.md @@ -6,6 +6,10 @@ 析构函数。销毁 `FileLogSink` 实例,调用 `Flush()` 确保所有日志数据写入文件,然后关闭文件句柄。 +**返回:** 无 + +**线程安全:** ✅ 析构函数是线程安全的 + **复杂度:** O(1) ## 相关文档 diff --git a/docs/api/debug/ilogsink/flush.md b/docs/api/debug/ilogsink/flush.md index f088ee9a..df6f9402 100644 --- a/docs/api/debug/ilogsink/flush.md +++ b/docs/api/debug/ilogsink/flush.md @@ -6,6 +6,12 @@ virtual void Flush() = 0 刷新输出缓冲区,确保所有待写入的日志数据已实际写入目标介质。对于文件类 Sink,应调用底层文件系统的 flush;对于网络类 Sink,应发送缓冲区中的数据。 +**返回:** 无 + +**异常:** 无 + +**线程安全:** ✅ 线程安全 + **复杂度:** O(1) **示例:** diff --git a/docs/api/debug/ilogsink/ilogsink.md b/docs/api/debug/ilogsink/ilogsink.md index 839144f5..050d502d 100644 --- a/docs/api/debug/ilogsink/ilogsink.md +++ b/docs/api/debug/ilogsink/ilogsink.md @@ -4,6 +4,8 @@ **类型**: `class` (abstract interface) +**头文件**: `XCEngine/Debug/ILogSink.h` + **描述**: 日志输出槽抽象接口,定义日志输出的标准协议。 ## 概述 @@ -14,8 +16,8 @@ | 方法 | 描述 | |------|------| -| `virtual void Log(const LogEntry& entry) = 0` | [输出单条日志](log.md) | -| `virtual void Flush() = 0` | [刷新缓冲区,确保日志写入](flush.md) | +| [`Log`](log.md) | 输出单条日志 | +| [`Flush`](flush.md) | 刷新缓冲区,确保日志写入 | ## 使用示例 diff --git a/docs/api/debug/ilogsink/log.md b/docs/api/debug/ilogsink/log.md index 52aa91c0..19e49150 100644 --- a/docs/api/debug/ilogsink/log.md +++ b/docs/api/debug/ilogsink/log.md @@ -9,7 +9,11 @@ virtual void Log(const LogEntry& entry) = 0 **参数:** - `entry` - 日志条目,包含级别、分类、消息、时间戳、线程 ID 等完整信息 -**复杂度:** O(1) +**返回:** 无 + +**异常:** 无 + +**线程安全:** ✅ 线程安全 **示例:** diff --git a/docs/api/debug/logcategory/logcategory.md b/docs/api/debug/logcategory/logcategory.md index 9932fa86..aa5472b1 100644 --- a/docs/api/debug/logcategory/logcategory.md +++ b/docs/api/debug/logcategory/logcategory.md @@ -4,6 +4,8 @@ **类型**: `enum class` +**头文件**: `XCEngine/Debug/LogCategory.h` + **描述**: 日志分类枚举,定义日志的来源模块。 ## 概述 @@ -29,7 +31,7 @@ | 函数 | 描述 | |------|------| -| `const char* LogCategoryToString(LogCategory category)` | [将日志分类转换为字符串](logcategorytostring.md) | +| [`LogCategoryToString`](logcategorytostring.md) | 将日志分类转换为字符串 | ## 使用示例 diff --git a/docs/api/debug/logcategory/logcategorytostring.md b/docs/api/debug/logcategory/logcategorytostring.md index 01b9a97c..8568987d 100644 --- a/docs/api/debug/logcategory/logcategorytostring.md +++ b/docs/api/debug/logcategory/logcategorytostring.md @@ -11,6 +11,8 @@ const char* LogCategoryToString(LogCategory category) **返回:** 对应分类的字符串("General", "Rendering", "Physics" 等) +**线程安全:** ✅ + **复杂度:** O(1) **示例:** diff --git a/docs/api/debug/logentry/logentry.md b/docs/api/debug/logentry/logentry.md index ae2e3839..6db2c721 100644 --- a/docs/api/debug/logentry/logentry.md +++ b/docs/api/debug/logentry/logentry.md @@ -4,6 +4,8 @@ **类型**: `struct` +**头文件**: `XCEngine/Debug/LogEntry.h` + **描述**: 日志条目结构体,包含单条日志的所有信息。 ## 概述 diff --git a/docs/api/debug/logger/addsink.md b/docs/api/debug/logger/addsink.md index e04eb90d..7009e8ac 100644 --- a/docs/api/debug/logger/addsink.md +++ b/docs/api/debug/logger/addsink.md @@ -1,27 +1,43 @@ # Logger::AddSink ```cpp -void AddSink(std::unique_ptr sink) +void AddSink(std::unique_ptr sink); ``` -向日志系统添加一个输出目标(Sink)。Logger 持有 Sink 的所有权,传入的 `unique_ptr` 被移动到内部容器中。每次日志记录时,所有已注册的 Sink 的 `Log` 方法都会被调用。 +添加一个日志输出槽(Sink)到 Logger。Sink 负责将日志输出到具体目标(如控制台、文件、网络等)。 **参数:** -- `sink` - 要添加的日志输出目标,使用 `std::unique_ptr` 包装 +- `sink` - 指向 ILogSink 接口的唯一指针 + +**返回:** 无 + +**线程安全:** ✅ **复杂度:** O(1) **示例:** ```cpp -#include +#include "XCEngine/Debug/Logger.h" +#include "XCEngine/Debug/ConsoleLogSink.h" +#include "XCEngine/Debug/FileLogSink.h" -XCEngine::Debug::Logger::Get().Initialize(); -XCEngine::Debug::Logger::Get().AddSink(std::make_unique()); -XCEngine::Debug::Logger::Get().AddSink(std::make_unique("app.log")); +using namespace XCEngine::Debug; + +Logger& logger = Logger::Get(); +logger.Initialize(); + +// 添加控制台输出 +logger.AddSink(std::make_unique()); + +// 添加文件输出 +logger.AddSink(std::make_unique("app.log")); + +logger.Info(LogCategory::General, "Sinks added"); ``` ## 相关文档 -- [Logger 总览](logger.md) - 返回类总览 -- [ILogSink](../ilogsink/ilogsink.md) - 日志输出接口 +- [Logger](logger.md) - 返回类总览 +- [RemoveSink](removesink.md) - 移除日志输出槽 +- [ILogSink](../ilogsink/ilogsink.md) - 日志输出槽接口 diff --git a/docs/api/debug/logger/debug.md b/docs/api/debug/logger/debug.md index cec3a9cd..af934825 100644 --- a/docs/api/debug/logger/debug.md +++ b/docs/api/debug/logger/debug.md @@ -1,10 +1,10 @@ # Logger::Debug ```cpp -void Debug(LogCategory category, const Containers::String& message) +void Debug(LogCategory category, const Containers::String& message); ``` -记录一条 Debug(1 级)日志。Debug 级别用于一般调试信息,比 Verbose 简洁但比 Info 详细。 +记录 Debug 级别日志。用于记录调试目的的信息,比 Verbose 级别稍简略。 **参数:** - `category` - 日志分类 @@ -12,19 +12,21 @@ void Debug(LogCategory category, const Containers::String& message) **返回:** 无 -**复杂度:** O(n),n 为注册的 Sink 数量 +**线程安全:** ✅ **示例:** ```cpp -#include +#include "XCEngine/Debug/Logger.h" -XCEngine::Debug::Logger::Get().Debug( - XCEngine::Debug::LogCategory::Rendering, - "Draw call batch size: 512" -); +using namespace XCEngine::Debug; + +Logger& logger = Logger::Get(); +logger.Debug(LogCategory::Rendering, "Frame rendered in 16ms"); +logger.Debug(LogCategory::Physics, "Collision detected"); ``` ## 相关文档 -- [Logger 总览](logger.md) - 返回类总览 +- [Logger](logger.md) - 返回类总览 +- [LogLevel](../loglevel/loglevel.md) - 日志级别说明 diff --git a/docs/api/debug/logger/error.md b/docs/api/debug/logger/error.md index 3dcdc5ea..ca494a54 100644 --- a/docs/api/debug/logger/error.md +++ b/docs/api/debug/logger/error.md @@ -1,10 +1,10 @@ # Logger::Error ```cpp -void Error(LogCategory category, const Containers::String& message) +void Error(LogCategory category, const Containers::String& message); ``` -记录一条 Error(4 级)日志。Error 级别用于表示程序执行中发生的错误,如文件读取失败、网络连接中断等。程序通常可以继续运行但功能可能受限。 +记录 Error 级别日志。用于记录错误信息,表示发生了错误但程序可以继续运行。 **参数:** - `category` - 日志分类 @@ -12,19 +12,21 @@ void Error(LogCategory category, const Containers::String& message) **返回:** 无 -**复杂度:** O(n),n 为注册的 Sink 数量 +**线程安全:** ✅ **示例:** ```cpp -#include +#include "XCEngine/Debug/Logger.h" -XCEngine::Debug::Logger::Get().Error( - XCEngine::Debug::LogCategory::Network, - "Failed to connect to game server" -); +using namespace XCEngine::Debug; + +Logger& logger = Logger::Get(); +logger.Error(LogCategory::Network, "Failed to connect to server"); +logger.Error(LogCategory::FileSystem, "Cannot open file"); ``` ## 相关文档 -- [Logger 总览](logger.md) - 返回类总览 +- [Logger](logger.md) - 返回类总览 +- [LogLevel](../loglevel/loglevel.md) - 日志级别说明 diff --git a/docs/api/debug/logger/fatal.md b/docs/api/debug/logger/fatal.md index fa2fed01..89730dd2 100644 --- a/docs/api/debug/logger/fatal.md +++ b/docs/api/debug/logger/fatal.md @@ -1,10 +1,10 @@ # Logger::Fatal ```cpp -void Fatal(LogCategory category, const Containers::String& message) +void Fatal(LogCategory category, const Containers::String& message); ``` -记录一条 Fatal(5 级)日志。Fatal 级别用于表示不可恢复的严重错误,通常意味着程序即将终止。此方法可能在记录日志后触发程序中断。 +记录 Fatal 级别日志。用于记录致命错误,表示程序无法继续运行。通常用于 `XE_ASSERT` 宏中。 **参数:** - `category` - 日志分类 @@ -12,19 +12,20 @@ void Fatal(LogCategory category, const Containers::String& message) **返回:** 无 -**复杂度:** O(n),n 为注册的 Sink 数量 +**线程安全:** ✅ **示例:** ```cpp -#include +#include "XCEngine/Debug/Logger.h" -XCEngine::Debug::Logger::Get().Fatal( - XCEngine::Debug::LogCategory::General, - "Out of memory - cannot continue" -); +using namespace XCEngine::Debug; + +Logger& logger = Logger::Get(); +logger.Fatal(LogCategory::General, "Critical system failure"); ``` ## 相关文档 -- [Logger 总览](logger.md) - 返回类总览 +- [Logger](logger.md) - 返回类总览 +- [LogLevel](../loglevel/loglevel.md) - 日志级别说明 diff --git a/docs/api/debug/logger/get.md b/docs/api/debug/logger/get.md index 19b348c0..eb1878ea 100644 --- a/docs/api/debug/logger/get.md +++ b/docs/api/debug/logger/get.md @@ -1,22 +1,24 @@ # Logger::Get ```cpp -static Logger& Get() +static Logger& Get(); ``` -获取 `Logger` 单例实例。Logger 使用局部静态变量实现 Meyers' Singleton,确保线程安全且只初始化一次。 +获取 Logger 单例实例。 -**返回:** `Logger&` - 全局日志记录器实例的引用 - -**复杂度:** O(1) +**线程安全:** ✅ **示例:** ```cpp -XCEngine::Debug::Logger& logger = XCEngine::Debug::Logger::Get(); -logger.Initialize(); +#include "XCEngine/Debug/Logger.h" + +using namespace XCEngine::Debug; + +Logger& logger = Logger::Get(); +logger.Info(LogCategory::General, "Logger initialized"); ``` ## 相关文档 -- [Logger 总览](logger.md) - 返回类总览 +- [Logger](logger.md) - 返回类总览 diff --git a/docs/api/debug/logger/info.md b/docs/api/debug/logger/info.md index 74292e68..eac3875a 100644 --- a/docs/api/debug/logger/info.md +++ b/docs/api/debug/logger/info.md @@ -1,10 +1,10 @@ # Logger::Info ```cpp -void Info(LogCategory category, const Containers::String& message) +void Info(LogCategory category, const Containers::String& message); ``` -记录一条 Info(2 级)日志。Info 级别用于一般性信息,如启动提示、配置加载等用户可见的正常运行消息。 +记录 Info 级别日志。用于记录一般信息性消息,表示程序正常运行状态。 **参数:** - `category` - 日志分类 @@ -12,19 +12,21 @@ void Info(LogCategory category, const Containers::String& message) **返回:** 无 -**复杂度:** O(n),n 为注册的 Sink 数量 +**线程安全:** ✅ **示例:** ```cpp -#include +#include "XCEngine/Debug/Logger.h" -XCEngine::Debug::Logger::Get().Info( - XCEngine::Debug::LogCategory::General, - "Application initialized successfully" -); +using namespace XCEngine::Debug; + +Logger& logger = Logger::Get(); +logger.Info(LogCategory::General, "Application started"); +logger.Info(LogCategory::Network, "Connected to server"); ``` ## 相关文档 -- [Logger 总览](logger.md) - 返回类总览 +- [Logger](logger.md) - 返回类总览 +- [LogLevel](../loglevel/loglevel.md) - 日志级别说明 diff --git a/docs/api/debug/logger/initialize.md b/docs/api/debug/logger/initialize.md index 7841377b..1af139a9 100644 --- a/docs/api/debug/logger/initialize.md +++ b/docs/api/debug/logger/initialize.md @@ -1,28 +1,28 @@ # Logger::Initialize ```cpp -void Initialize() +void Initialize(); ``` -初始化日志系统。在首次使用日志功能前必须调用。初始化内部状态标志,确保日志系统已准备好工作。 +初始化日志系统。在首次使用 Logger 前必须调用此方法进行初始化。初始化过程会设置内部状态并准备日志记录环境。 -**注意:** 默认最小日志级别为 `Verbose`,所有日志分类默认启用,这些是类成员变量的默认值,不需要在此方法中设置。 +**线程安全:** ❌(应在单线程启动阶段调用) **复杂度:** O(1) **示例:** ```cpp -#include +#include "XCEngine/Debug/Logger.h" -int main() { - XCEngine::Debug::Logger::Get().Initialize(); - XCEngine::Debug::Logger::Get().AddSink(std::make_unique()); - XCEngine::Debug::Logger::Get().Info(XCEngine::Debug::LogCategory::General, "Application started"); - return 0; -} +using namespace XCEngine::Debug; + +Logger& logger = Logger::Get(); +logger.Initialize(); +logger.Info(LogCategory::General, "System initialized"); ``` ## 相关文档 -- [Logger 总览](logger.md) - 返回类总览 +- [Logger](logger.md) - 返回类总览 +- [Shutdown](shutdown.md) - 关闭日志系统 diff --git a/docs/api/debug/logger/log.md b/docs/api/debug/logger/log.md index 8a74bae7..6b16c44d 100644 --- a/docs/api/debug/logger/log.md +++ b/docs/api/debug/logger/log.md @@ -3,43 +3,40 @@ ```cpp void Log(LogLevel level, LogCategory category, const Containers::String& message, const char* file = nullptr, - int32_t line = 0, const char* function = nullptr) + int32_t line = 0, const char* function = nullptr); ``` -通用日志记录方法。根据设置的最小日志级别和分类开关决定是否输出,然后将日志分发给所有已注册的 Sink。如果日志级别低于最小级别或分类被禁用,则不输出。 +通用日志记录方法,支持完整的日志信息包括源码位置。 **参数:** -- `level` - 日志级别(Verbose, Debug, Info, Warning, Error, Fatal) -- `category` - 日志分类(General, Rendering, Physics 等) +- `level` - 日志级别(Verbose、Debug、Info、Warning、Error、Fatal) +- `category` - 日志分类(General、Rendering、Physics 等) - `message` - 日志消息内容 -- `file` - 源代码文件路径(可选,默认 nullptr) -- `line` - 源代码行号(可选,默认 0) -- `function` - 函数名称(可选,默认 nullptr) +- `file` - 源码文件名(可选) +- `line` - 源码行号(可选) +- `function` - 函数名(可选) **返回:** 无 -**复杂度:** O(n),n 为注册的 Sink 数量 +**线程安全:** ✅ **示例:** ```cpp -#include +#include "XCEngine/Debug/Logger.h" -XCEngine::Debug::Logger::Get().Log( - XCEngine::Debug::LogLevel::Error, - XCEngine::Debug::LogCategory::FileSystem, - "Failed to open config file", - __FILE__, - __LINE__, - __FUNCTION__ -); +using namespace XCEngine::Debug; -// 推荐使用 XE_LOG 宏自动填充位置信息 -XE_LOG(XCEngine::Debug::LogCategory::General, XCEngine::Debug::LogLevel::Info, "Initialized"); +Logger& logger = Logger::Get(); + +// 完整调用(包含源码位置) +logger.Log(LogLevel::Error, LogCategory::Network, + "Connection timeout", __FILE__, __LINE__, __FUNCTION__); + +// 简化调用 +logger.Log(LogLevel::Info, LogCategory::General, "Simple message"); ``` ## 相关文档 -- [Logger 总览](logger.md) - 返回类总览 -- [LogLevel](../loglevel/loglevel.md) - 日志级别枚举 -- [LogCategory](../logcategory/logcategory.md) - 日志分类枚举 +- [Logger](logger.md) - 返回类总览 diff --git a/docs/api/debug/logger/logger.md b/docs/api/debug/logger/logger.md index 18c3e20d..0b61a4eb 100644 --- a/docs/api/debug/logger/logger.md +++ b/docs/api/debug/logger/logger.md @@ -6,87 +6,67 @@ **头文件**: `XCEngine/Debug/Logger.h` -**描述**: 全局日志记录器单例,提供多级别、多分类的日志输出。 +**描述**: 日志系统,提供分级日志记录功能 ## 概述 -`Logger` 是 XCEngine 的核心日志系统单例。它支持多个日志输出目标(Sink)、日志级别过滤、分类开关,并提供宏方便使用。 +Logger 是 XCEngine 的核心日志系统,采用单例模式设计。它提供多级别(Verbose、Debug、Info、Warning、Error、Fatal)和多分类(General、Rendering、Physics 等)的日志记录功能,支持自定义日志输出槽(Sink)。 -## 单例访问 - -| 方法 | 描述 | -|------|------| -| `static Logger& Get()` | 获取单例实例 | +Logger 支持多个 Sink 组件,每个 Sink 可以将日志输出到不同的目的地(如文件、控制台、远程服务器等)。系统还提供宏定义 `XE_LOG` 和 `XE_ASSERT` 方便快速记录日志。 ## 公共方法 | 方法 | 描述 | |------|------| -| `void Initialize()` | [初始化日志系统](initialize.md) | -| `void Shutdown()` | [关闭日志系统](shutdown.md) | -| `void AddSink(std::unique_ptr sink)` | [添加日志输出目标](addsink.md) | -| `void RemoveSink(ILogSink* sink)` | [移除日志输出目标](removesink.md) | -| `void Log(...)` | [通用日志记录](log.md) | -| `void Verbose(...)` | [Verbose 级别日志](verbose.md) | -| `void Debug(...)` | [Debug 级别日志](debug.md) | -| `void Info(...)` | [Info 级别日志](info.md) | -| `void Warning(...)` | [Warning 级别日志](warning.md) | -| `void Error(...)` | [Error 级别日志](error.md) | -| `void Fatal(...)` | [Fatal 级别日志](fatal.md) | -| `void SetMinimumLevel(...)` | [设置最小日志级别](setminimumlevel.md) | -| `void SetCategoryEnabled(...)` | [开启/关闭指定分类](setcategoryenabled.md) | - -## 宏定义 - -### XE_LOG - -```cpp -#define XE_LOG(category, level, message) \ - XCEngine::Debug::Logger::Get().Log(level, category, message, __FILE__, __LINE__, __FUNCTION__) -``` - -通用日志宏,自动填充文件名、行号和函数名。 - -### XE_ASSERT - -```cpp -#define XE_ASSERT(condition, message) \ - if (!(condition)) { \ - XCEngine::Debug::Logger::Get().Fatal(XCEngine::Debug::LogCategory::General, message); \ - } -``` - -断言宏,条件失败时记录 Fatal 日志。 +| [`Get`](get.md) | 获取 Logger 单例实例 | +| [`Initialize`](initialize.md) | 初始化日志系统 | +| [`Shutdown`](shutdown.md) | 关闭日志系统 | +| [`AddSink`](addsink.md) | 添加日志输出槽 | +| [`RemoveSink`](removesink.md) | 移除日志输出槽 | +| [`Log`](log.md) | 通用日志记录方法 | +| [`Verbose`](verbose.md) | 记录 Verbose 级别日志 | +| [`Debug`](debug.md) | 记录 Debug 级别日志 | +| [`Info`](info.md) | 记录 Info 级别日志 | +| [`Warning`](warning.md) | 记录 Warning 级别日志 | +| [`Error`](error.md) | 记录 Error 级别日志 | +| [`Fatal`](fatal.md) | 记录 Fatal 级别日志 | +| [`SetMinimumLevel`](setminimumlevel.md) | 设置最低日志级别 | +| [`SetCategoryEnabled`](setcategoryenabled.md) | 设置分类日志开关 | ## 使用示例 ```cpp -#include +#include "XCEngine/Debug/Logger.h" +#include "XCEngine/Debug/ConsoleSink.h" + +using namespace XCEngine::Debug; + +// 获取单例 +Logger& logger = Logger::Get(); // 初始化 -Logger::Get().Initialize(); -Logger::Get().AddSink(std::make_unique()); -Logger::Get().AddSink(std::make_unique("app.log")); +logger.Initialize(); -// 设置日志级别 -Logger::Get().SetMinimumLevel(LogLevel::Debug); +// 添加控制台输出Sink +logger.AddSink(std::make_unique()); -// 使用便捷方法 -Logger::Get().Info(LogCategory::Rendering, "Render started"); -Logger::Get().Warning(LogCategory::Memory, "High memory usage"); -Logger::Get().Error(LogCategory::FileSystem, "Failed to load file"); +// 使用便捷方法记录日志 +logger.Info(LogCategory::General, "Application started"); +logger.Warning(LogCategory::Rendering, "Low memory warning"); +logger.Error(LogCategory::Network, "Connection failed"); -// 使用宏(自动带位置信息) -XE_LOG(LogCategory::General, LogLevel::Info, "Application initialized"); +// 使用宏记录日志(自动包含文件、行号、函数信息) +XE_LOG(LogCategory::General, LogLevel::Info, "User logged in"); -// 使用断言 -XE_ASSERT(ptr != nullptr, "Pointer must not be null"); +// 设置最低日志级别 +logger.SetMinimumLevel(LogLevel::Warning); // 只记录 Warning 及以上 + +// 关闭 +logger.Shutdown(); ``` ## 相关文档 -- [Debug 模块总览](../debug.md) - 返回模块总览 -- [ILogSink](../ilogsink/ilogsink.md) - 日志输出接口 -- [ConsoleLogSink](../consolelogsink/consolelogsink.md) - 控制台输出 -- [FileLogSink](../filelogsink/filelogsink.md) - 文件输出 - [LogLevel](../loglevel/loglevel.md) - 日志级别枚举 +- [LogCategory](../logcategory/logcategory.md) - 日志分类枚举 +- [ILogSink](../ilogsink/ilogsink.md) - 日志输出槽接口 diff --git a/docs/api/debug/logger/removesink.md b/docs/api/debug/logger/removesink.md index bc81dabd..1921ee89 100644 --- a/docs/api/debug/logger/removesink.md +++ b/docs/api/debug/logger/removesink.md @@ -1,29 +1,37 @@ # Logger::RemoveSink ```cpp -void RemoveSink(ILogSink* sink) +void RemoveSink(ILogSink* sink); ``` -从日志系统移除指定的输出目标。通过指针查找并移除对应的 Sink,Logger 不再向该目标发送日志。 +从 Logger 移除指定的日志输出槽。 **参数:** -- `sink` - 要移除的日志输出目标指针 +- `sink` - 指向要移除的 ILogSink 接口的指针 + +**返回:** 无 + +**线程安全:** ✅ **复杂度:** O(n),n 为注册的 Sink 数量 **示例:** ```cpp -#include +#include "XCEngine/Debug/Logger.h" +#include "XCEngine/Debug/ConsoleLogSink.h" -auto fileSink = std::make_unique("app.log"); -XCEngine::Debug::FileLogSink* rawPtr = fileSink.get(); -XCEngine::Debug::Logger::Get().AddSink(std::move(fileSink)); -// 稍后移除 -XCEngine::Debug::Logger::Get().RemoveSink(rawPtr); +using namespace XCEngine::Debug; + +Logger& logger = Logger::Get(); +auto consoleSink = std::make_unique(); +logger.AddSink(consoleSink); + +// 移除 Sink(传入原始指针) +logger.RemoveSink(consoleSink.get()); ``` ## 相关文档 -- [Logger 总览](logger.md) - 返回类总览 -- [ILogSink](../ilogsink/ilogsink.md) - 日志输出接口 +- [Logger](logger.md) - 返回类总览 +- [AddSink](addsink.md) - 添加日志输出槽 diff --git a/docs/api/debug/logger/setcategoryenabled.md b/docs/api/debug/logger/setcategoryenabled.md index 9f6b5122..ce9995d0 100644 --- a/docs/api/debug/logger/setcategoryenabled.md +++ b/docs/api/debug/logger/setcategoryenabled.md @@ -1,36 +1,38 @@ # Logger::SetCategoryEnabled ```cpp -void SetCategoryEnabled(LogCategory category, bool enabled) +void SetCategoryEnabled(LogCategory category, bool enabled); ``` -启用或禁用指定分类的日志输出。当分类被禁用时,该分类的所有日志都不会分发给 Sink,但级别过滤仍然适用。 +设置指定日志分类的开关状态。禁用的分类将不会输出任何日志。 **参数:** -- `category` - 要设置的日志分类 -- `enabled` - true 表示启用,false 表示禁用 +- `category` - 日志分类 +- `enabled` - true 启用,false 禁用 -**复杂度:** O(1) +**返回:** 无 + +**线程安全:** ✅ **示例:** ```cpp -#include +#include "XCEngine/Debug/Logger.h" -// 禁用网络模块日志(减少日志噪音) -XCEngine::Debug::Logger::Get().SetCategoryEnabled( - XCEngine::Debug::LogCategory::Network, - false -); +using namespace XCEngine::Debug; -// 稍后重新启用 -XCEngine::Debug::Logger::Get().SetCategoryEnabled( - XCEngine::Debug::LogCategory::Network, - true -); +Logger& logger = Logger::Get(); + +// 禁用物理系统日志 +logger.SetCategoryEnabled(LogCategory::Physics, false); + +// 只启用关键分类 +logger.SetCategoryEnabled(LogCategory::General, true); +logger.SetCategoryEnabled(LogCategory::Error, true); +logger.SetCategoryEnabled(LogCategory::Warning, true); ``` ## 相关文档 -- [Logger 总览](logger.md) - 返回类总览 +- [Logger](logger.md) - 返回类总览 - [LogCategory](../logcategory/logcategory.md) - 日志分类枚举 diff --git a/docs/api/debug/logger/setminimumlevel.md b/docs/api/debug/logger/setminimumlevel.md index 175fe78d..7a47b231 100644 --- a/docs/api/debug/logger/setminimumlevel.md +++ b/docs/api/debug/logger/setminimumlevel.md @@ -1,30 +1,37 @@ # Logger::SetMinimumLevel ```cpp -void SetMinimumLevel(LogLevel level) +void SetMinimumLevel(LogLevel level); ``` -设置日志系统的最小输出级别。所有低于该级别的日志将被过滤,不会分发给任何 Sink。 +设置最低日志级别。只会记录等于或高于此级别的日志,低于该级别的日志将被忽略。 **参数:** -- `level` - 最小日志级别 +- `level` - 最低日志级别 -**复杂度:** O(1) +**返回:** 无 + +**线程安全:** ✅ **示例:** ```cpp -#include +#include "XCEngine/Debug/Logger.h" -// 只输出 Warning 及以上级别的日志 -XCEngine::Debug::Logger::Get().SetMinimumLevel(XCEngine::Debug::LogLevel::Warning); +using namespace XCEngine::Debug; -// Verbose 和 Debug 级别的日志将被过滤 -XCEngine::Debug::Logger::Get().Verbose(XCEngine::Debug::LogCategory::General, "This will not be logged"); -XCEngine::Debug::Logger::Get().Warning(XCEngine::Debug::LogCategory::General, "This will be logged"); +Logger& logger = Logger::Get(); + +// 只记录 Warning 及以上级别 +logger.SetMinimumLevel(LogLevel::Warning); + +logger.Verbose(LogCategory::General, "This won't be logged"); +logger.Debug(LogCategory::General, "This won't be logged"); +logger.Info(LogCategory::General, "This won't be logged"); +logger.Warning(LogCategory::General, "This WILL be logged"); ``` ## 相关文档 -- [Logger 总览](logger.md) - 返回类总览 +- [Logger](logger.md) - 返回类总览 - [LogLevel](../loglevel/loglevel.md) - 日志级别枚举 diff --git a/docs/api/debug/logger/shutdown.md b/docs/api/debug/logger/shutdown.md index 79cc35b4..95ae2c39 100644 --- a/docs/api/debug/logger/shutdown.md +++ b/docs/api/debug/logger/shutdown.md @@ -1,26 +1,28 @@ # Logger::Shutdown ```cpp -void Shutdown() +void Shutdown(); ``` -关闭日志系统。移除所有注册的 Sink,刷新缓冲区并重置内部状态。在程序退出前调用,确保所有日志数据已写入输出目标。 +关闭日志系统并清理资源。调用此方法后会停止所有日志记录操作并释放相关资源。在程序退出前应调用此方法。 + +**线程安全:** ❌(应在单线程退出阶段调用) **复杂度:** O(n),n 为注册的 Sink 数量 **示例:** ```cpp -#include +#include "XCEngine/Debug/Logger.h" -int main() { - XCEngine::Debug::Logger::Get().Initialize(); - // ... 应用逻辑 ... - XCEngine::Debug::Logger::Get().Shutdown(); - return 0; -} +using namespace XCEngine::Debug; + +Logger& logger = Logger::Get(); +logger.Info(LogCategory::General, "Shutting down..."); +logger.Shutdown(); ``` ## 相关文档 -- [Logger 总览](logger.md) - 返回类总览 +- [Logger](logger.md) - 返回类总览 +- [Initialize](initialize.md) - 初始化日志系统 diff --git a/docs/api/debug/logger/verbose.md b/docs/api/debug/logger/verbose.md index 9ef925b0..5a845cc7 100644 --- a/docs/api/debug/logger/verbose.md +++ b/docs/api/debug/logger/verbose.md @@ -1,10 +1,10 @@ # Logger::Verbose ```cpp -void Verbose(LogCategory category, const Containers::String& message) +void Verbose(LogCategory category, const Containers::String& message); ``` -记录一条 Verbose(0 级)日志。Verbose 是最详细的日志级别,用于输出大量调试细节。 +记录 Verbose 级别日志。Verbose 是最详细的日志级别,用于记录调试信息。 **参数:** - `category` - 日志分类 @@ -12,19 +12,21 @@ void Verbose(LogCategory category, const Containers::String& message) **返回:** 无 -**复杂度:** O(n),n 为注册的 Sink 数量 +**线程安全:** ✅ **示例:** ```cpp -#include +#include "XCEngine/Debug/Logger.h" -XCEngine::Debug::Logger::Get().Verbose( - XCEngine::Debug::LogCategory::Memory, - "Memory pool fragmentation: 12.5%" -); +using namespace XCEngine::Debug; + +Logger& logger = Logger::Get(); +logger.Verbose(LogCategory::General, "Variable value: 42"); +logger.Verbose(LogCategory::Memory, "Memory allocation detail"); ``` ## 相关文档 -- [Logger 总览](logger.md) - 返回类总览 +- [Logger](logger.md) - 返回类总览 +- [LogLevel](../loglevel/loglevel.md) - 日志级别说明 diff --git a/docs/api/debug/logger/warning.md b/docs/api/debug/logger/warning.md index f7e7efc2..1bc8d4f2 100644 --- a/docs/api/debug/logger/warning.md +++ b/docs/api/debug/logger/warning.md @@ -1,10 +1,10 @@ # Logger::Warning ```cpp -void Warning(LogCategory category, const Containers::String& message) +void Warning(LogCategory category, const Containers::String& message); ``` -记录一条 Warning(3 级)日志。Warning 级别用于指示潜在问题但程序仍可继续运行的情况,如资源即将耗尽、配置值超出建议范围等。 +记录 Warning 级别日志。用于记录警告信息,表示可能存在问题但程序仍能继续运行。 **参数:** - `category` - 日志分类 @@ -12,19 +12,21 @@ void Warning(LogCategory category, const Containers::String& message) **返回:** 无 -**复杂度:** O(n),n 为注册的 Sink 数量 +**线程安全:** ✅ **示例:** ```cpp -#include +#include "XCEngine/Debug/Logger.h" -XCEngine::Debug::Logger::Get().Warning( - XCEngine::Debug::LogCategory::Memory, - "Memory usage exceeds 80% of available heap" -); +using namespace XCEngine::Debug; + +Logger& logger = Logger::Get(); +logger.Warning(LogCategory::Memory, "High memory usage detected"); +logger.Warning(LogCategory::Rendering, "Low GPU memory"); ``` ## 相关文档 -- [Logger 总览](logger.md) - 返回类总览 +- [Logger](logger.md) - 返回类总览 +- [LogLevel](../loglevel/loglevel.md) - 日志级别说明 diff --git a/docs/api/debug/loglevel/loglevel.md b/docs/api/debug/loglevel/loglevel.md index eda973be..48276be7 100644 --- a/docs/api/debug/loglevel/loglevel.md +++ b/docs/api/debug/loglevel/loglevel.md @@ -4,37 +4,91 @@ **类型**: `enum class` -**描述**: 日志级别枚举,定义日志的严重程度。 +**头文件**: `XCEngine/Debug/LogLevel.h` + +**描述**: 日志级别枚举,用于区分不同重要程度的日志消息 ## 概述 -`LogLevel` 枚举定义了从最详细到最严重的日志级别。`Logger` 根据设置的最小级别过滤日志。 +LogLevel 枚举定义了六个日志级别,从低到高依次为:Verbose、Debug、Info、Warning、Error、Fatal。数值越高表示级别越严重,便于日志系统进行过滤和分类处理。 ## 枚举值 -| 值 | 说明 | 数值 | +| 值 | 数值 | 描述 | |----|------|------| -| `Verbose` | 详细调试信息 | 0 | -| `Debug` | 调试信息 | 1 | -| `Info` | 一般信息 | 2 | -| `Warning` | 警告信息 | 3 | -| `Error` | 错误信息 | 4 | -| `Fatal` | 致命错误 | 5 | +| `Verbose` | 0 | 详细日志,用于调试追踪 | +| `Debug` | 1 | 调试日志,开发时使用 | +| `Info` | 2 | 信息日志,一般信息提示 | +| `Warning` | 3 | 警告日志,潜在问题提示 | +| `Error` | 4 | 错误日志,已发生的错误 | +| `Fatal` | 5 | 致命日志,导致程序无法继续 | -## 辅助函数 +## 公共函数 | 函数 | 描述 | |------|------| -| `const char* LogLevelToString(LogLevel level)` | [将日志级别转换为字符串](logleveltostring.md) | +| [`LogLevelToString`](logleveltostring.md) | 将 LogLevel 转换为字符串表示 | + +### LogLevelToString + +```cpp +const char* LogLevelToString(LogLevel level); +``` + +将日志级别转换为对应的字符串名称。 + +**参数:** +- `level` - 日志级别值 + +**返回:** 对应级别的字符串名称,如 "Verbose"、"Debug"、"Info" 等 + +**示例:** + +```cpp +#include +#include "XCEngine/Debug/LogLevel.h" + +int main() { + using namespace XCEngine::Debug; + + std::cout << LogLevelToString(LogLevel::Verbose) << std::endl; // Output: VERBOSE + std::cout << LogLevelToString(LogLevel::Info) << std::endl; // Output: INFO + std::cout << LogLevelToString(LogLevel::Error) << std::endl; // Output: ERROR + + for (uint8_t i = 0; i <= 5; ++i) { + LogLevel level = static_cast(i); + std::cout << static_cast(level) << ": " << LogLevelToString(level) << std::endl; + } + + return 0; +} +``` ## 使用示例 ```cpp -Logger::Get().SetMinimumLevel(LogLevel::Warning); -// 只有 Warning、Error、Fatal 级别的日志会被输出 +#include "XCEngine/Debug/LogLevel.h" + +using namespace XCEngine::Debug; + +void ProcessLog(LogLevel level, const char* message) { + if (level >= LogLevel::Warning) { + printf("[%s] %s\n", LogLevelToString(level), message); + } +} + +int main() { + ProcessLog(LogLevel::Verbose, "This is verbose"); // Filtered out + ProcessLog(LogLevel::Debug, "This is debug"); // Filtered out + ProcessLog(LogLevel::Info, "This is info"); // Filtered out + ProcessLog(LogLevel::Warning, "This is warning"); // Output: [WARNING] This is warning + ProcessLog(LogLevel::Error, "This is error"); // Output: [ERROR] This is error + ProcessLog(LogLevel::Fatal, "This is fatal"); // Output: [FATAL] This is fatal + + return 0; +} ``` ## 相关文档 -- [Debug 模块总览](../debug.md) - 返回模块总览 -- [Logger](../logger/logger.md) - 日志记录器 +- [Debug 模块总览](../debug.md) - Debug 模块介绍 diff --git a/docs/api/debug/profiler/beginframe.md b/docs/api/debug/profiler/beginframe.md index 109142d0..6572da78 100644 --- a/docs/api/debug/profiler/beginframe.md +++ b/docs/api/debug/profiler/beginframe.md @@ -6,6 +6,10 @@ void BeginFrame() 开始一帧的性能分析。记录当前帧的起始时间戳,用于计算帧级别的性能指标。应在每帧渲染开始时调用。 +**返回:** `void` + +**线程安全:** ✅ 线程安全 + **复杂度:** O(1) **示例:** diff --git a/docs/api/debug/profiler/beginprofile.md b/docs/api/debug/profiler/beginprofile.md index 0203a51b..7dd9a596 100644 --- a/docs/api/debug/profiler/beginprofile.md +++ b/docs/api/debug/profiler/beginprofile.md @@ -9,6 +9,10 @@ void BeginProfile(const char* name) **参数:** - `name` - 分析块的名称,用于在导出结果中标识 +**返回:** `void` + +**线程安全:** ✅ 线程安全 + **复杂度:** O(1) **示例:** diff --git a/docs/api/debug/profiler/endframe.md b/docs/api/debug/profiler/endframe.md index d9e208b8..766c5066 100644 --- a/docs/api/debug/profiler/endframe.md +++ b/docs/api/debug/profiler/endframe.md @@ -4,7 +4,13 @@ void EndFrame() ``` -结束一帧的性能分析。记录当前帧的结束时间,计算帧耗时并可用于帧率统计。应在每帧渲染结束时调用。 +结束一帧的性能分析。清空当前帧采集的所有样本数据,准备记录下一帧的性能数据。应在每帧渲染结束时调用。 + +**注意:** 此方法仅清空样本数据,不会计算或导出帧耗时信息。 + +**返回:** `void` + +**线程安全:** ✅ 线程安全 **复杂度:** O(1) diff --git a/docs/api/debug/profiler/endprofile.md b/docs/api/debug/profiler/endprofile.md index c231a29b..37cdaefd 100644 --- a/docs/api/debug/profiler/endprofile.md +++ b/docs/api/debug/profiler/endprofile.md @@ -6,6 +6,10 @@ void EndProfile() 结束当前性能分析块。从栈顶弹出分析节点并计算持续时间(endTime - startTime),将结果保存到样本列表中。 +**返回:** `void` + +**线程安全:** ✅ 线程安全 + **复杂度:** O(1) **示例:** diff --git a/docs/api/debug/profiler/exportchrometracing.md b/docs/api/debug/profiler/exportchrometracing.md index f0f7829a..dc6843c3 100644 --- a/docs/api/debug/profiler/exportchrometracing.md +++ b/docs/api/debug/profiler/exportchrometracing.md @@ -11,6 +11,10 @@ void ExportChromeTracing(const Containers::String& filePath) **参数:** - `filePath` - 输出文件路径 +**返回:** `void` + +**线程安全:** ✅ 线程安全 + **复杂度:** O(n),n 为记录的样本数量 **示例:** @@ -35,7 +39,7 @@ void RenderFrame() { XCEngine::Debug::Profiler::Get().EndFrame(); } -// 运行一段时间后导出 +// 运行一段时间后导出(需在 Shutdown 前调用) XCEngine::Debug::Profiler::Get().ExportChromeTracing("trace.json"); XCEngine::Debug::Profiler::Get().Shutdown(); ``` diff --git a/docs/api/debug/profiler/get.md b/docs/api/debug/profiler/get.md index 7ee09d69..0a68c70f 100644 --- a/docs/api/debug/profiler/get.md +++ b/docs/api/debug/profiler/get.md @@ -8,6 +8,8 @@ static Profiler& Get() **返回:** `Profiler&` - 全局性能分析器实例的引用 +**线程安全:** ✅ 线程安全(Meyers' Singleton) + **复杂度:** O(1) **示例:** diff --git a/docs/api/debug/profiler/initialize.md b/docs/api/debug/profiler/initialize.md index eb9dcef7..b1cc9925 100644 --- a/docs/api/debug/profiler/initialize.md +++ b/docs/api/debug/profiler/initialize.md @@ -8,6 +8,10 @@ void Initialize() **注意:** 帧计时器等数据结构在首次 BeginFrame 时自动初始化。 +**返回:** `void` + +**线程安全:** ✅ 线程安全 + **复杂度:** O(1) **示例:** diff --git a/docs/api/debug/profiler/markevent.md b/docs/api/debug/profiler/markevent.md index b1c73252..1675e441 100644 --- a/docs/api/debug/profiler/markevent.md +++ b/docs/api/debug/profiler/markevent.md @@ -13,6 +13,10 @@ void MarkEvent(const char* name, uint64_t timestamp, uint32_t threadId) - `timestamp` - 事件发生的时间戳(微秒) - `threadId` - 事件所属的线程 ID +**返回:** `void` + +**线程安全:** ✅ 线程安全 + **复杂度:** O(1) **示例:** diff --git a/docs/api/debug/profiler/profiler.md b/docs/api/debug/profiler/profiler.md index 23d7eafe..1111a20d 100644 --- a/docs/api/debug/profiler/profiler.md +++ b/docs/api/debug/profiler/profiler.md @@ -4,31 +4,28 @@ **类型**: `class` (singleton) +**头文件**: `XCEngine/Debug/Profiler.h` + **描述**: 性能分析器单例,用于测量代码块执行时间并支持 Chrome Tracing 格式导出。 ## 概述 `Profiler` 是 XCEngine 的性能分析工具。它通过栈式记录和采样方式跟踪函数执行时间,支持导出为 Chrome Tracing 格式(可通过 Chrome 的 `chrome://tracing` 查看)。 -## 单例访问 - -| 方法 | 描述 | -|------|------| -| `static Profiler& Get()` | 获取单例实例 | - ## 公共方法 | 方法 | 描述 | |------|------| -| `void Initialize()` | [初始化性能分析器](initialize.md) | -| `void Shutdown()` | [关闭性能分析器](shutdown.md) | -| `void BeginProfile(const char* name)` | [开始一个性能分析块](beginprofile.md) | -| `void EndProfile()` | [结束当前性能分析块](endprofile.md) | -| `void BeginFrame()` | [开始一帧的分析](beginframe.md) | -| `void EndFrame()` | [结束一帧的分析](endframe.md) | -| `void MarkEvent(const char* name, uint64_t timestamp, uint32_t threadId)` | [标记一个事件点](markevent.md) | -| `void SetMarker(const char* name, uint32_t color)` | [设置帧标记](setmarker.md) | -| `void ExportChromeTracing(const Containers::String& filePath)` | [导出为 Chrome Tracing JSON 格式](exportchrometracing.md) | +| [`Get`](get.md) | 获取单例实例 | +| [`Initialize`](initialize.md) | 初始化性能分析器 | +| [`Shutdown`](shutdown.md) | 关闭性能分析器 | +| [`BeginProfile`](beginprofile.md) | 开始一个性能分析块 | +| [`EndProfile`](endprofile.md) | 结束当前性能分析块 | +| [`BeginFrame`](beginframe.md) | 开始一帧的分析 | +| [`EndFrame`](endframe.md) | 结束一帧的分析 | +| [`MarkEvent`](markevent.md) | 标记一个事件点 | +| [`SetMarker`](setmarker.md) | 设置帧标记 | +| [`ExportChromeTracing`](exportchrometracing.md) | 导出为 Chrome Tracing JSON 格式 | ## 宏定义 diff --git a/docs/api/debug/profiler/setmarker.md b/docs/api/debug/profiler/setmarker.md index a9610c8c..4b28a58a 100644 --- a/docs/api/debug/profiler/setmarker.md +++ b/docs/api/debug/profiler/setmarker.md @@ -12,6 +12,10 @@ void SetMarker(const char* name, uint32_t color) - `name` - 标记名称 - `color` - 标记颜色(ABGR 格式) +**返回:** `void` + +**线程安全:** ✅ 线程安全 + **复杂度:** O(1) **示例:** diff --git a/docs/api/debug/profiler/shutdown.md b/docs/api/debug/profiler/shutdown.md index 8d01e540..866115a9 100644 --- a/docs/api/debug/profiler/shutdown.md +++ b/docs/api/debug/profiler/shutdown.md @@ -6,6 +6,10 @@ void Shutdown() 关闭性能分析器。清理内部数据结构,停止所有活动分析块,重置状态。在程序退出前调用。 +**返回:** `void` + +**线程安全:** ✅ 线程安全 + **复杂度:** O(1) **示例:**