LLDB  mainline
Progress.cpp
Go to the documentation of this file.
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"
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  : m_title(title), m_id(++g_id), m_completed(0), m_total(total) {
22  assert(total > 0);
23  if (debugger)
24  m_debugger_id = debugger->GetID();
25  std::lock_guard<std::mutex> guard(m_mutex);
27 }
28 
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  std::lock_guard<std::mutex> guard(m_mutex);
33  if (!m_completed) {
36  }
37 }
38 
39 void Progress::Increment(uint64_t amount) {
40  if (amount > 0) {
41  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  if (amount > (m_total - m_completed))
46  else
47  m_completed += amount;
49  }
50 }
51 
53  if (!m_complete) {
54  // Make sure we only send one notification that indicates the progress is
55  // complete.
59  }
60 }
lldb_private::Progress::m_mutex
std::mutex m_mutex
Definition: Progress.h:96
lldb_private::Progress::m_debugger_id
llvm::Optional< lldb::user_id_t > m_debugger_id
The optional debugger ID to report progress to.
Definition: Progress.h:105
lldb_private::Progress::Increment
void Increment(uint64_t amount=1)
Increment the progress and send a notification to the intalled callback.
Definition: Progress.cpp:39
lldb_private::Progress::m_total
const uint64_t m_total
Total amount of work, UINT64_MAX for non deterministic progress.
Definition: Progress.h:102
Debugger.h
lldb_private::Progress::ReportProgress
void ReportProgress()
Definition: Progress.cpp:52
Progress.h
StreamString.h
lldb_private::Debugger
Definition: Debugger.h:70
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::UserID::GetID
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47
lldb_private::Progress::~Progress
~Progress()
Destroy the progress object.
Definition: Progress.cpp:29
lldb_private::Progress::m_title
std::string m_title
The title of the progress activity.
Definition: Progress.h:95
lldb_private::Progress::m_id
const uint64_t m_id
A unique integer identifier for progress reporting.
Definition: Progress.h:98
lldb_private::Progress::m_complete
bool m_complete
Set to true when progress has been reported where m_completed == m_total to ensure that we don't send...
Definition: Progress.h:109
lldb_private::Debugger::ReportProgress
static void ReportProgress(uint64_t progress_id, const std::string &message, uint64_t completed, uint64_t total, llvm::Optional< lldb::user_id_t > debugger_id)
Report progress events.
Definition: Debugger.cpp:1200
lldb_private::Progress::m_completed
uint64_t m_completed
How much work ([0...m_total]) that has been completed.
Definition: Progress.h:100
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb
Definition: SBAddress.h:15