[3/8] stats: add a helper to get stats of parent pre-dump

Submitted by Pavel Tikhomirov on Feb. 9, 2018, 4:06 p.m.

Details

Message ID 20180209160645.2164-4-ptikhomirov@virtuozzo.com
State New
Series "don't use wrong pagemap (from other task) on pid reuse"
Headers show

Commit Message

Pavel Tikhomirov Feb. 9, 2018, 4:06 p.m.
will be used in the next patch

https://jira.sw.ru/browse/PSBM-67502

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
---
 criu/include/stats.h |  2 ++
 criu/stats.c         | 31 +++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/include/stats.h b/criu/include/stats.h
index 81775c856..8694d9fb7 100644
--- a/criu/include/stats.h
+++ b/criu/include/stats.h
@@ -23,6 +23,8 @@  extern void timing_start(int t);
 extern void timing_stop(int t);
 extern int timing_uptime(int t);
 
+extern int get_parent_stats(void **se);
+
 enum {
 	CNT_PAGES_SCANNED,
 	CNT_PAGES_SKIPPED_PARENT,
diff --git a/criu/stats.c b/criu/stats.c
index 2944474cd..5c05b1e68 100644
--- a/criu/stats.c
+++ b/criu/stats.c
@@ -213,6 +213,37 @@  void write_stats(int what)
 		display_stats(what, &stats);
 }
 
+__maybe_unused int get_parent_stats(void **se)
+{
+	StatsEntry **stats = (StatsEntry **)se;
+	struct cr_img *img;
+	int dir;
+
+	dir = openat(get_service_fd(IMG_FD_OFF), CR_PARENT_LINK, O_RDONLY);
+	if (dir == -1) {
+		pr_perror("Failed to open parent directory");
+		return -1;
+	}
+
+	img = open_image_at(dir, CR_FD_STATS, O_RSTR, "dump");
+	if (!img) {
+		pr_perror("Failed to open parent dump stats");
+		close(dir);
+		return -1;
+	}
+
+	if (pb_read_one(img, stats, PB_STATS) < 0) {
+		pr_perror("Failed to read parent dump stats");
+		close_image(img);
+		close(dir);
+		return -1;
+	}
+
+	close_image(img);
+	close(dir);
+	return 0;
+}
+
 int init_stats(int what)
 {
 	if (what == DUMP_STATS) {

Comments

Dmitry Safonov Feb. 9, 2018, 4:50 p.m.
2018-02-09 16:06 GMT+00:00 Pavel Tikhomirov <ptikhomirov@virtuozzo.com>:
> will be used in the next patch
>
> https://jira.sw.ru/browse/PSBM-67502
>
> Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
> ---
>  criu/include/stats.h |  2 ++
>  criu/stats.c         | 31 +++++++++++++++++++++++++++++++
>  2 files changed, 33 insertions(+)
>
> diff --git a/criu/include/stats.h b/criu/include/stats.h
> index 81775c856..8694d9fb7 100644
> --- a/criu/include/stats.h
> +++ b/criu/include/stats.h
> @@ -23,6 +23,8 @@ extern void timing_start(int t);
>  extern void timing_stop(int t);
>  extern int timing_uptime(int t);
>
> +extern int get_parent_stats(void **se);

Because dynamic typing and Python are great?
I know, you're trying to decrease nr of includes..
But will that work for you if it's not get_parent_stats(),
but get_parent_uptime() which will return parsed uint64_t?
Then we'll still be able to enjoy C99's static typing..

> +
>  enum {
>         CNT_PAGES_SCANNED,
>         CNT_PAGES_SKIPPED_PARENT,
> diff --git a/criu/stats.c b/criu/stats.c
> index 2944474cd..5c05b1e68 100644
> --- a/criu/stats.c
> +++ b/criu/stats.c
> @@ -213,6 +213,37 @@ void write_stats(int what)
>                 display_stats(what, &stats);
>  }
>
> +__maybe_unused int get_parent_stats(void **se)

Failed to remove __maybe_unused somewhere,
not nice.
Pavel Tikhomirov Feb. 9, 2018, 10:46 p.m.