-
Notifications
You must be signed in to change notification settings - Fork 0
/
date_spacefree.cpp
150 lines (127 loc) · 4.34 KB
/
date_spacefree.cpp
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
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/uio.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include "allocation.h"
#include "ibp_ClientLib.h"
#include "ibp_server.h"
#include "network.h"
#include "net_sock.h"
#include "log.h"
#include "dns_cache.h"
#include "fmttypes.h"
void parse_line(char *buffer, time_t *t, uint64_t *a_count, uint64_t *p_count, uint64_t *bytes_used, uint64_t *bytes)
{
char *bstate;
int fin;
*t = 0;
*a_count = *p_count = *bytes_used = *bytes = 0;
sscanf(string_token(buffer, " ", &bstate, &fin), TT, t);
sscanf(string_token(NULL, " ", &bstate, &fin), LU, a_count);
sscanf(string_token(NULL, " ", &bstate, &fin), LU, p_count);
sscanf(string_token(NULL, " ", &bstate, &fin), LU, bytes_used);
sscanf(string_token(NULL, " ", &bstate, &fin), LU, bytes);
// printf("t=" TT " * ac=" LU " * pc=" LU " * bu=" LU " * b=" LU "\n", *t, *a_count, *p_count, *bytes_used, *bytes);
}
//*************************************************************************
//*************************************************************************
int main(int argc, char **argv)
{
int bufsize = 1024*1024;
char buffer[bufsize], *bstate;
int err, print_full, i;
Net_timeout_t dt;
time_t t;
uint64_t size;
char print_time[128];
uint64_t a_count, p_count, count, a_total, p_total, total;
uint64_t bytes_used, bytes, total_bytes_used, total_bytes;
double fb1, fb2, fb3, fb4;
uint64_t base_unit;
double units;
if (argc < 4) {
printf("date_spacefree [-full] host port RID size(mb)\n");
return(0);
}
base_unit = 1024 * 1024;
units = base_unit;
units = 1.0 / units;
print_full = 0;
i = 1;
if (strcmp(argv[i], "-full") == 0) { print_full = 1; i++; }
char *host = argv[i]; i++;
int port = atoi(argv[i]); i++;
char *rid = argv[i]; i++;
sscanf(argv[i], "%lf", &fb1);
size = fb1 * base_unit;
dns_cache_init(10);
NetStream_t *ns = new_netstream();
ns_config_sock(ns, -1, 0);
set_net_timeout(&dt, 5, 0);
err = net_connect(ns, host, port, dt);
if (err != 0) {
printf("get_alloc: Can't connect to host! host=%s port=%d err=%d\n", host, port, err);
return(err);
}
sprintf(buffer, "1 %d %s " LU " 10\n", INTERNAL_DATE_FREE, rid, size);
err = write_netstream(ns, buffer, strlen(buffer), dt);
err = readline_netstream(ns, buffer, bufsize, dt);
if (err > 0) {
err = atoi(string_token(buffer, " ", &bstate, &err));
if (err != IBP_OK) {
printf("Error %d returned!\n", err);
close_netstream(ns);
return(err);
}
}
//** Cycle through the data **
a_total = p_total = 0;
total_bytes_used = total_bytes = 0;
if (print_full) {
printf("Time date Tallocs Talias Ttotal mb_used mb_max Nallocs Nalias Ntotal total_used_mb total_max_mb\n");
} else {
printf("Time date Ttotal mb_max Ntotal total_max_mb\n");
}
printf("------------------------------------------------------------------------------------------------------\n");
err = 0;
while (err != -1) {
buffer[0] = '\0';
err = readline_netstream(ns, buffer, bufsize, dt);
//printf("err=%d buf=%s\n", err, buffer);
if (err > 0) {
if (strcmp("END", buffer) == 0) { //** Finished
err = -1;
} else {
parse_line(buffer, &t, &a_count, &p_count, &bytes_used, &bytes);
ctime_r(&t, print_time); print_time[strlen(print_time)-1] = '\0';
count = a_count + p_count;
a_total = a_total + a_count; p_total = p_total + p_count;
total_bytes_used = total_bytes_used + bytes_used;
total_bytes = total_bytes + bytes;
total = a_total + p_total;
fb1 = bytes_used * units;
fb2 = bytes * units;
fb3 = total_bytes_used * units;
fb4 = total_bytes * units;
if (print_full) {
printf(TT " * %s " LU " * " LU " * " LU " * %lf * %lf * " LU " * " LU " * " LU " * %lf * %lf\n",
t, print_time, a_count, p_count, count, fb1, fb2, a_total, p_total, total, fb3, fb4);
} else {
printf(TT " * %s * " LU " * %lf * " LU " * %lf\n",
t, print_time, count, fb2, total,fb4);
}
}
}
}
close_netstream(ns);
printf("\n");
return(0);
}