LLDB mainline
Go to the documentation of this file.
1//===-- Progress.cpp ------------------------------------------------------===//
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
11#include "lldb/Core/Debugger.h"
14using namespace lldb;
15using namespace lldb_private;
17std::atomic<uint64_t> Progress::g_id(0);
19Progress::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);
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 }
39void Progress::Increment(uint64_t amount, std::string update) {
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;
48 ReportProgress(update);
49 }
52void Progress::ReportProgress(std::string update) {
53 if (!m_complete) {
54 // Make sure we only send one notification that indicates the progress is
55 // complete.
59 }
A class to manage flag bits.
Definition: Debugger.h:78
static void ReportProgress(uint64_t progress_id, std::string title, std::string details, uint64_t completed, uint64_t total, std::optional< lldb::user_id_t > debugger_id)
Report progress events.
Definition: Debugger.cpp:1364
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:112
void Increment(uint64_t amount=1, std::string update={})
Increment the progress and send a notification to the intalled callback.
Definition: Progress.cpp:39
uint64_t m_completed
How much work ([0...m_total]) that has been completed.
Definition: Progress.h:103
static std::atomic< uint64_t > g_id
Definition: Progress.h:96
std::optional< lldb::user_id_t > m_debugger_id
The optional debugger ID to report progress to.
Definition: Progress.h:108
std::string m_title
The title of the progress activity.
Definition: Progress.h:98
Progress(std::string title, uint64_t total=UINT64_MAX, lldb_private::Debugger *debugger=nullptr)
Construct a progress object that will report information.
Definition: Progress.cpp:19
std::mutex m_mutex
Definition: Progress.h:99
Destroy the progress object.
Definition: Progress.cpp:29
void ReportProgress(std::string update={})
Definition: Progress.cpp:52
const uint64_t m_id
A unique integer identifier for progress reporting.
Definition: Progress.h:101
const uint64_t m_total
Total amount of work, UINT64_MAX for non deterministic progress.
Definition: Progress.h:105
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47