| 2495 | } |
| 2496 | |
| 2497 | std::shared_ptr<PresentEvent> PMTraceConsumer::FindOrCreatePresent(EVENT_HEADER const& hdr) |
| 2498 | { |
| 2499 | // First, we check if there is an in-progress present that was last |
| 2500 | // operated on from this same thread. |
| 2501 | auto present = FindPresentByThreadId(hdr.ThreadId); |
| 2502 | if (present != nullptr) { |
| 2503 | return present; |
| 2504 | } |
| 2505 | |
| 2506 | // Next, we look for the oldest present from the same process that may have |
| 2507 | // been deferred by the driver and submitted on a different thread. Such |
| 2508 | // presents should have only seen present start/stop events so should not |
| 2509 | // have a known PresentMode, etc. yet. |
| 2510 | auto presentsByThisProcess = &mOrderedPresentsByProcessId[hdr.ProcessId]; |
| 2511 | for (auto const& pr : *presentsByThisProcess) { |
| 2512 | present = pr.second; |
| 2513 | if (present->DriverThreadId == 0 && |
| 2514 | present->SeenDxgkPresent == false && |
| 2515 | present->SeenWin32KEvents == false && |
| 2516 | present->PresentMode == PresentMode::Unknown) { |
| 2517 | VerboseTraceBeforeModifyingPresent(present.get()); |
| 2518 | present->DriverThreadId = hdr.ThreadId; |
| 2519 | |
| 2520 | // Set this present as the one the driver thread is working on. We |
| 2521 | // leave it assigned to the one the application thread is working |
| 2522 | // on as well, in case we haven't yet seen application events such |
| 2523 | // as Present::Stop. |
| 2524 | SetThreadPresent(hdr.ThreadId, present); |
| 2525 | |
| 2526 | return present; |
| 2527 | } |
| 2528 | } |
| 2529 | |
| 2530 | // If we couldn't find an in-progress present on the same thread/process, |
| 2531 | // then we create a new one and start tracking it from here (unless the |
| 2532 | // user is filtering this process out). |
| 2533 | // |
| 2534 | // This can happen if there was a lost event, or if the present didn't |
| 2535 | // originate from a runtime whose events we're tracking (i.e., DXGI or |
| 2536 | // D3D9) in which case a DxgKrnl event will be the first present-related |
| 2537 | // event we ever see. |
| 2538 | if (IsProcessTrackedForFiltering(hdr.ProcessId)) { |
| 2539 | present = std::make_shared<PresentEvent>(); |
| 2540 | |
| 2541 | VerboseTraceBeforeModifyingPresent(present.get()); |
| 2542 | present->PresentStartTime = *(uint64_t*) &hdr.TimeStamp; |
| 2543 | present->ProcessId = hdr.ProcessId; |
| 2544 | present->ThreadId = hdr.ThreadId; |
| 2545 | |
| 2546 | ApplyPresentFrameType(present); |
| 2547 | |
| 2548 | TrackPresent(present, presentsByThisProcess); |
| 2549 | |
| 2550 | return present; |
| 2551 | } |
| 2552 | |
| 2553 | return nullptr; |
| 2554 | } |
nothing calls this directly
no outgoing calls
no test coverage detected