Coverage Report

Created: 2023-09-30 09:22

/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
235k
    : m_title(title), m_id(++g_id), m_completed(0), m_total(total) {
22
235k
  assert(total > 0);
23
235k
  if (debugger)
24
0
    m_debugger_id = debugger->GetID();
25
235k
  std::lock_guard<std::mutex> guard(m_mutex);
26
235k
  ReportProgress();
27
235k
}
28
29
235k
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
235k
  std::lock_guard<std::mutex> guard(m_mutex);
33
235k
  if (!m_completed) {
34
231k
    m_completed = m_total;
35
231k
    ReportProgress();
36
231k
  }
37
235k
}
38
39
43.4k
void Progress::Increment(uint64_t amount, std::string update) {
40
43.4k
  if (
amount > 043.4k
) {
41
43.4k
    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
43.4k
    if (amount > (m_total - m_completed))
45
0
      m_completed = m_total;
46
43.4k
    else
47
43.4k
      m_completed += amount;
48
43.4k
    ReportProgress(update);
49
43.4k
  }
50
43.4k
}
51
52
510k
void Progress::ReportProgress(std::string update) {
53
510k
  if (!m_complete) {
54
    // Make sure we only send one notification that indicates the progress is
55
    // complete.
56
510k
    m_complete = m_completed == m_total;
57
510k
    Debugger::ReportProgress(m_id, m_title, std::move(update), m_completed,
58
510k
                             m_total, m_debugger_id);
59
510k
  }
60
510k
}