This repository was archived by the owner on Jan 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathsys-refs.cc
More file actions
157 lines (136 loc) · 3.81 KB
/
sys-refs.cc
File metadata and controls
157 lines (136 loc) · 3.81 KB
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
/*
* SPDX-License-Identifier: GPL-2.0
*
* Copyright (c) 2018 Intel Corporation
*
* Authors: Yao Yuan <yuan.yao@intel.com>
* Fengguang Wu <fengguang.wu@intel.com>
*/
#include <stdio.h>
#include <sys/types.h>
#include <getopt.h>
#include <iostream>
#include <string>
#include <vector>
#include <memory>
#include <iostream>
#include <string.h>
#include <signal.h>
#include "lib/debug.h"
#include "Option.h"
#include "ProcMaps.h"
#include "ProcIdlePages.h"
#include "EPTScan.h"
#include "EPTMigrate.h"
#include "GlobalScan.h"
#include "version.h"
#include "OptionParser.h"
using namespace std;
OptionParser option;
GlobalScan gscan;
int debug_level()
{
return option.debug_level;
}
static const struct option opts[] = {
{"interval", required_argument, NULL, 'i'},
{"sleep", required_argument, NULL, 's'},
{"loop", required_argument, NULL, 'l'},
{"output", required_argument, NULL, 'o'},
{"dram", required_argument, NULL, 'd'},
{"migrate", required_argument, NULL, 'm'},
{"verbose", required_argument, NULL, 'v'},
{"config", required_argument, NULL, 'c'},
{"progressive-profile", required_argument, NULL, 'p'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'r'},
{NULL, 0, NULL, 0}
};
static void usage(char *prog)
{
fprintf(stderr,
"%s [option] ...\n"
"Options (order matters, the latter takes effect):\n"
" -h|--help Show this information\n"
" -i|--interval The scan interval in seconds\n"
" -s|--sleep Seconds to sleep between scan rounds\n"
" -l|--loop The number of scan rounds\n"
" -o|--output The output file, defaults to refs-count\n"
" -d|--dram The DRAM percent, wrt. DRAM+PMEM total size\n"
" -m|--migrate Migrate what: 0|none, 1|hot, 2|cold, 3|both\n"
" -p|--progressive-profile The script path and name.\n"
" Group pages by refcount,\n"
" migrate and call script to profile each group.\n"
" -v|--verbose Show debug info\n"
" -r|--version Show version info\n"
" -c|--config config file path name\n",
prog);
exit(0);
}
static void parse_cmdline(int argc, char *argv[])
{
int options_index = 0;
int opt = 0;
const char *optstr = "hvri:s:l:o:d:m:c:p:";
optind = 1;
while ((opt = getopt_long(argc, argv, optstr, opts, &options_index)) != EOF) {
switch (opt) {
case 0:
case 'c':
option.parse_file(optarg);
break;
case 's':
option.sleep_secs = atof(optarg);
break;
case 'i':
option.interval = atof(optarg);
break;
case 'l':
option.nr_loops = atoi(optarg);
break;
case 'o':
option.output_file = optarg;
break;
case 'd':
option.dram_percent = atoi(optarg);
break;
case 'm':
option.migrate_what = Option::parse_migrate_name(optarg);
break;
case 'p':
option.progressive_profile = optarg;
break;
case 'v':
++option.debug_level;
break;
case 'r':
print_version();
exit(0);
case 'h':
case '?':
default:
usage(argv[0]);
}
}
}
void signal_handler(int sign_num)
{
gscan.request_reload_conf();
}
int register_signal_handler()
{
if (SIG_ERR != signal(SIGUSR1, signal_handler))
return 0;
return -1;
}
int main(int argc, char *argv[])
{
setlocale(LC_NUMERIC, "");
parse_cmdline(argc, argv);
if (option.dump_options)
option.dump();
register_signal_handler();
gscan.apply_option();
gscan.main_loop();
return 0;
}