| 195 | } |
| 196 | |
| 197 | void ObjectInspector::scanForThreadAffinityIssues() |
| 198 | { |
| 199 | const auto probe = Probe::instance(); |
| 200 | const auto &objects = probe->allQObjects(); |
| 201 | |
| 202 | QMutexLocker lock(Probe::objectLock()); |
| 203 | for (const auto object : objects) { |
| 204 | if (!probe->isValidObject(object)) { |
| 205 | continue; |
| 206 | } |
| 207 | |
| 208 | const auto objectName = Util::displayString(object); |
| 209 | if (object == object->thread()) { |
| 210 | Problem problem; |
| 211 | problem.severity = Problem::Warning; |
| 212 | problem.description = QStringLiteral("The thread %1 has affinity with itself.").arg(objectName); |
| 213 | problem.object = ObjectId(object); |
| 214 | problem.locations.append(probe->objectCreationSourceLocation(object)); |
| 215 | problem.problemId = QStringLiteral("com.kdab.GammaRay.ObjectInspector.ThreadAffinityCheck.Self.%1") |
| 216 | .arg(QString::number(reinterpret_cast<quintptr>(object))); |
| 217 | problem.findingCategory = Problem::Scan; |
| 218 | ProblemCollector::addProblem(problem); |
| 219 | } |
| 220 | |
| 221 | const auto parent = object->parent(); |
| 222 | if (parent == nullptr) { |
| 223 | continue; |
| 224 | } |
| 225 | |
| 226 | const auto parentName = Util::displayString(parent); |
| 227 | if (object->thread() != parent->thread()) { |
| 228 | Problem problem; |
| 229 | problem.severity = Problem::Warning; |
| 230 | problem.description = QStringLiteral("The object %1 doesn't have the same thread affinity as its parent %2.").arg(objectName, parentName); |
| 231 | problem.object = ObjectId(object); |
| 232 | problem.locations.append(probe->objectCreationSourceLocation(object)); |
| 233 | problem.problemId = QStringLiteral("com.kdab.GammaRay.ObjectInspector.ThreadAffinityCheck.%1:%2") |
| 234 | .arg(QString::number(reinterpret_cast<quintptr>(object)), |
| 235 | QString::number(reinterpret_cast<quintptr>(parent))); |
| 236 | problem.findingCategory = Problem::Scan; |
| 237 | ProblemCollector::addProblem(problem); |
| 238 | } |
| 239 | |
| 240 | if (qobject_cast<QThread *>(parent) && object->thread() != object->parent()) { |
| 241 | Problem problem; |
| 242 | problem.severity = Problem::Warning; |
| 243 | problem.description = QStringLiteral("The object %1 has thread %2 as parent, but doesn't have affinity with it.").arg(objectName, parentName); |
| 244 | problem.object = ObjectId(object); |
| 245 | problem.locations.append(probe->objectCreationSourceLocation(object)); |
| 246 | problem.problemId = QStringLiteral("com.kdab.GammaRay.ObjectInspector.ThreadAffinityCheck.Parent.%1") |
| 247 | .arg(QString::number(reinterpret_cast<quintptr>(object)), |
| 248 | QString::number(reinterpret_cast<quintptr>(parent))); |
| 249 | problem.findingCategory = Problem::Scan; |
| 250 | ProblemCollector::addProblem(problem); |
| 251 | } |
| 252 | } |
| 253 | } |
nothing calls this directly
no test coverage detected