summaryrefslogtreecommitdiffstats
path: root/squashfs-tools/info.c
blob: 49f0c72dd1df4f1a720a780176e559f4d6fb9d52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
 * Create a squashfs filesystem.  This is a highly compressed read only
 * filesystem.
 *
 * Copyright (c) 2013, 2014, 2019, 2021, 2022, 2023
 * Phillip Lougher <phillip@squashfs.org.uk>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2,
 * or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * info.c
 */

#include <pthread.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <signal.h>
#include <sys/time.h>
#include <stdio.h>
#include <math.h>
#include <stdarg.h>
#include <errno.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>

#include "squashfs_fs.h"
#include "mksquashfs.h"
#include "mksquashfs_error.h"
#include "progressbar.h"
#include "caches-queues-lists.h"
#include "signals.h"

static int silent = 0;
static struct dir_ent *ent = NULL;

pthread_t info_thread;


void disable_info()
{
	ent = NULL;
}


void update_info(struct dir_ent *dir_ent)
{
	ent = dir_ent;
}


static void print_filename()
{
	struct dir_ent *dir_ent = ent;

	if(dir_ent == NULL)
		return;

	if(dir_ent->our_dir->subpath[0] != '\0')
		INFO("%s/%s\n", dir_ent->our_dir->subpath, dir_ent->name);
	else
		INFO("/%s\n", dir_ent->name);
}


static void dump_state()
{
	disable_progress_bar();

	printf("Queue and Cache status dump\n");
	printf("===========================\n");

	printf("file buffer queue (reader thread -> deflate thread(s))\n");
	dump_queue(to_deflate);

	printf("uncompressed fragment queue (reader thread -> fragment"
						" thread(s))\n");
	dump_queue(to_process_frag);

	printf("processed fragment queue (fragment thread(s) -> main"
						" thread)\n");
	dump_seq_queue(to_main, 1);

	printf("compressed block queue (deflate thread(s) -> main thread)\n");
	dump_seq_queue(to_main, 0);

	printf("uncompressed packed fragment queue (main thread -> fragment"
						" deflate thread(s))\n");
	dump_queue(to_frag);

	if(!reproducible) {
		printf("locked frag queue (compressed frags waiting while multi-block"
							" file is written)\n");
		dump_queue(locked_fragment);

		printf("compressed block queue (main & fragment deflate threads(s) ->"
						" writer thread)\n");
		dump_queue(to_writer);
	} else {
		printf("compressed fragment queue (fragment deflate threads(s) ->"
						"fragment order thread)\n");

		dump_seq_queue(to_order, 0);

		printf("compressed block queue (main & fragment order threads ->"
						" writer thread)\n");
		dump_queue(to_writer);
	}

	printf("read cache (uncompressed blocks read by reader thread)\n");
	dump_cache(reader_buffer);

	printf("block write cache (compressed blocks waiting for the writer"
						" thread)\n");
	dump_cache(bwriter_buffer);
	printf("fragment write cache (compressed fragments waiting for the"
						" writer thread)\n");
	dump_cache(fwriter_buffer);

	printf("fragment cache (frags waiting to be compressed by fragment"
						" deflate thread(s))\n");
	dump_cache(fragment_buffer);

	printf("fragment reserve cache (avoids pipeline stall if frag cache"
						" full in dup check)\n");
	dump_cache(reserve_cache);

	enable_progress_bar();
}


static void *info_thrd(void *arg)
{
	sigset_t sigmask;
	int sig, waiting = 0;

	sigemptyset(&sigmask);
	sigaddset(&sigmask, SIGQUIT);
	sigaddset(&sigmask, SIGHUP);

	while(1) {
		sig = wait_for_signal(&sigmask, &waiting);

		if(sig == SIGQUIT && !waiting) {
			print_filename();

			/* set one second interval period, if ^\ received
			   within then, dump queue and cache status */
			waiting = 1;
		} else
			dump_state();
	}

	return NULL;
}


void init_info()
{
	pthread_create(&info_thread, NULL, info_thrd, NULL);
}