feat(dock): add app launch event reporting for taskbar icons#1606
Open
Ivy233 wants to merge 1 commit into
Open
feat(dock): add app launch event reporting for taskbar icons#1606Ivy233 wants to merge 1 commit into
Ivy233 wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Ivy233 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
dc49397 to
35405ee
Compare
1. Implement LaunchDurationReporter to report event 1000610003 when taskbar icons appear 2. Report app metadata: name, launch type, version, unique ID, timestamp, and package type 3. Query Application Manager via DBus for instance information 4. Detect package type using ll-cli for linglong apps and dpkg-query for deb packages 5. Implement cache with 30-minute TTL for linglong and deb packages 6. Async D-Bus query execution for better performance Log: Report app launch events when taskbar icons appear for analytics Influence: 1. Verify event 1000610003 triggers when new taskbar icons appear 2. Verify correct version reporting for linglong and deb packages feat(dock): 添加任务栏图标出现时的应用启动事件上报 1. 实现 LaunchDurationReporter 在任务栏图标出现时上报 1000610003 事件 2. 上报应用元数据:名称、启动类型、版本、唯一 ID、时间戳和包类型 3. 通过 DBus 查询应用管理器获取实例信息 4. 使用 ll-cli 检测玲珑应用,使用 dpkg-query 检测 deb 包 5. 实现 30 分钟 TTL 的玲珑和 deb 包缓存 6. D-Bus 查询异步执行,提升性能 Log: 任务栏图标出现时上报应用启动事件用于分析 Influence: 1. 验证新图标出现时触发 1000610003 事件 2. 验证玲珑和 deb 包版本正确上报 PMS: TASK-389405
35405ee to
0b79013
Compare
deepin pr auto review这份代码实现了一个应用启动时长上报器,通过在后台线程查询 D-Bus 获取应用实例信息,结合本地缓存和命令行工具获取包版本,最终通过事件日志上报。整体架构思路清晰,但在线程安全、代码性能和代码健壮性方面存在一些需要重点关注的问题。 以下是详细的代码审查意见: 一、 语法与逻辑
二、 代码性能
三、 代码安全
四、 代码质量与改进建议
改进后的核心代码示例(供参考)针对上述部分问题,以下是修改后的 void LaunchDurationReporter::reportWindowAppeared(const QString &desktopId)
{
if (desktopId.isEmpty()) {
return;
}
// 安全性:基础格式校验,防止命令注入或异常参数
static QRegularExpression validIdRegex(R"(^[a-zA-Z0-9\.\-_]+$)");
if (!validIdRegex.match(desktopId).hasMatch()) {
qCWarning(launchDurationReporter) << "Invalid desktopId format:" << desktopId;
return;
}
QtConcurrent::run(&m_workerPool, [this, desktopId]() {
auto instances = queryInstances(desktopId);
QString uniqueId;
QString launchType = QStringLiteral("unknown");
if (!instances.isEmpty()) {
const auto &latest = instances.constLast();
uniqueId = latest.instanceId;
launchType = latest.launchType;
}
if (uniqueId.isEmpty()) {
return;
}
QString version;
QString pakType;
{
QMutexLocker locker(&m_cacheMutex);
qint64 currentTime = QDateTime::currentSecsSinceEpoch();
// 刷新 linglong 缓存
if ((currentTime - m_linglongCacheTime) > kLinglongCacheTTLSeconds) {
// 注意:这里仍在持锁状态调用 ll-cli 会阻塞其他线程
// 如果对性能要求极高,应先 unlock() 执行 loadAllLinglongVersions(),完成后再 lock() 写入
m_linglongCache = loadAllLinglongVersions();
m_linglongCacheTime = currentTime;
}
if (m_linglongCache.contains(desktopId)) {
version = m_linglongCache.value(desktopId);
pakType = QStringLiteral("linglong");
} else if (m_debCache.contains(desktopId)) {
const auto &entry = m_debCache.value(desktopId);
if ((currentTime - entry.timestamp) <= kDebCacheTTLSeconds) {
version = entry.version;
pakType = entry.pakType;
} else {
// 改进:清理过期条目,防止内存泄漏
m_debCache.remove(desktopId);
}
}
}
if (pakType.isEmpty()) {
QProcess proc;
proc.start(QStringLiteral("dpkg-query"), {QStringLiteral("-W"), QStringLiteral("-f=${Version}"), desktopId});
proc.waitForFinished(1000);
if (proc.exitCode() == 0) {
version = QString::fromUtf8(proc.readAllStandardOutput()).trimmed();
pakType = QStringLiteral("deb");
} else {
qCDebug(launchDurationReporter) << "dpkg-query failed for" << desktopId << "exitCode:" << proc.exitCode();
// 改进:对于查询失败的也缓存,防止频繁拉起进程
pakType = QStringLiteral("unknown");
}
QMutexLocker locker(&m_cacheMutex);
// 将查询结果(包含 unknown)放入缓存
m_debCache.insert(desktopId, {version, pakType, QDateTime::currentSecsSinceEpoch()});
}
QMetaObject::invokeMethod(this, [this, desktopId, uniqueId, launchType, version, pakType]() {
doReport(desktopId, uniqueId, launchType, version, pakType);
}, Qt::QueuedConnection);
});
}
// 析构函数改进
LaunchDurationReporter::~LaunchDurationReporter()
{
m_workerPool.clear(); // 先清空未执行的任务
m_workerPool.waitForDone(3000); // 设置3秒超时,防止卡死
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Log: Report app launch events when taskbar icons appear for analytics
Influence:
feat(dock): 添加任务栏图标出现时的应用启动事件上报
Log: 任务栏图标出现时上报应用启动事件用于分析
Influence:
PMS: TASK-389405