Linux Perf
progress.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kernel.h>
3 #include "../cache.h"
4 #include "progress.h"
5 
6 static void null_progress__update(struct ui_progress *p __maybe_unused)
7 {
8 }
9 
11 {
13 };
14 
16 
17 void ui_progress__update(struct ui_progress *p, u64 adv)
18 {
19  u64 last = p->curr;
20 
21  p->curr += adv;
22 
23  if (p->curr >= p->next) {
24  u64 nr = DIV_ROUND_UP(p->curr - last, p->step);
25 
26  p->next += nr * p->step;
27  ui_progress__ops->update(p);
28  }
29 }
30 
31 void __ui_progress__init(struct ui_progress *p, u64 total,
32  const char *title, bool size)
33 {
34  p->curr = 0;
35  p->next = p->step = total / 16 ?: 1;
36  p->total = total;
37  p->title = title;
38  p->size = size;
39 
40  if (ui_progress__ops->init)
41  ui_progress__ops->init(p);
42 }
43 
45 {
46  if (ui_progress__ops->finish)
47  ui_progress__ops->finish();
48 }
u64 curr
Definition: progress.h:11
void ui_progress__update(struct ui_progress *p, u64 adv)
Definition: progress.c:17
void(* finish)(void)
Definition: progress.h:29
size_t size
Definition: evsel.c:60
static void null_progress__update(struct ui_progress *p __maybe_unused)
Definition: progress.c:6
struct ui_progress_ops * ui_progress__ops
Definition: progress.c:15
void __ui_progress__init(struct ui_progress *p, u64 total, const char *title, bool size)
Definition: progress.c:31
static struct ui_progress_ops null_progress__ops
Definition: progress.c:10
const char * title
Definition: progress.h:10
void ui_progress__finish(void)
Definition: progress.c:44
u64 total
Definition: progress.h:11
void(* update)(struct ui_progress *p)
Definition: progress.h:28
u64 step
Definition: progress.h:11
u64 next
Definition: progress.h:11
void(* init)(struct ui_progress *p)
Definition: progress.h:27
bool size
Definition: progress.h:12