Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Core/Progress.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- Progress.cpp ------------------------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "lldb/Core/Progress.h"
10
11
#include "lldb/Core/Debugger.h"
12
#include "lldb/Utility/StreamString.h"
13
14
using namespace lldb;
15
using namespace lldb_private;
16
17
std::atomic<uint64_t> Progress::g_id(0);
18
19
Progress::Progress(std::string title, uint64_t total,
20
                   lldb_private::Debugger *debugger)
21
146k
    : m_title(title), m_id(++g_id), m_completed(0), m_total(total) {
22
146k
  assert(total > 0);
23
146k
  if (debugger)
24
0
    m_debugger_id = debugger->GetID();
25
146k
  std::lock_guard<std::mutex> guard(m_mutex);
26
146k
  ReportProgress();
27
146k
}
28
29
146k
Progress::~Progress() {
30
  // Make sure to always report progress completed when this object is
31
  // destructed so it indicates the progress dialog/activity should go away.
32
146k
  std::lock_guard<std::mutex> guard(m_mutex);
33
146k
  if (!m_completed) {
34
141k
    m_completed = m_total;
35
141k
    ReportProgress();
36
141k
  }
37
146k
}
38
39
54.6k
void Progress::Increment(uint64_t amount) {
40
54.6k
  if (amount > 0) {
41
54.6k
    std::lock_guard<std::mutex> guard(m_mutex);
42
    // Watch out for unsigned overflow and make sure we don't increment too
43
    // much and exceed m_total.
44
54.6k
    if (amount > (m_total - m_completed))
45
0
      m_completed = m_total;
46
54.6k
    else
47
54.6k
      m_completed += amount;
48
54.6k
    ReportProgress();
49
54.6k
  }
50
54.6k
}
51
52
342k
void Progress::ReportProgress() {
53
342k
  if (!m_complete) {
54
    // Make sure we only send one notification that indicates the progress is
55
    // complete.
56
342k
    m_complete = m_completed == m_total;
57
342k
    Debugger::ReportProgress(m_id, m_title, m_completed, m_total,
58
342k
                             m_debugger_id);
59
342k
  }
60
342k
}