Skip to content

Commit fc611f5

Browse files
committed
add --spec/-s for special field
1 parent 6ef6ad4 commit fc611f5

File tree

9 files changed

+173
-65
lines changed

9 files changed

+173
-65
lines changed

devel/tsar.h

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -46,53 +46,55 @@
4646

4747

4848
struct mod_info {
49-
char hdr[LEN_128];
50-
int summary_bit; /* bit set indefi summary */
51-
int merge_mode;
52-
int stats_opt;
49+
char hdr[LEN_128];
50+
int summary_bit; /* bit set indefi summary */
51+
int merge_mode;
52+
int stats_opt;
5353
};
5454
struct module
5555
{
56-
char name[LEN_32];
57-
char opt_line[LEN_32];
58-
char record[LEN_1024];
59-
char usage[LEN_256];
60-
61-
struct mod_info *info;
62-
void *lib;
63-
int enable;
64-
65-
/* private data used by framework*/
66-
int n_item;
67-
int n_col;
68-
long n_record;
69-
70-
int pre_flag:4;
71-
int st_flag:4;
72-
73-
U_64 *pre_array;
74-
U_64 *cur_array;
75-
double *st_array;
76-
double *max_array;
77-
double *mean_array;
78-
double *min_array;
79-
80-
/* callback function of module */
81-
void (*data_collect) (struct module *);
82-
void (*set_st_record) (struct module *mod, double *, U_64 *, U_64 *, int );
83-
84-
/* mod manage */
85-
void (*mod_register) (struct module *);
56+
char name[LEN_32];
57+
char opt_line[LEN_32];
58+
char record[LEN_1024];
59+
char usage[LEN_256];
60+
61+
struct mod_info *info;
62+
void *lib;
63+
int enable;
64+
int spec;
65+
66+
/* private data used by framework*/
67+
int n_item;
68+
int n_col;
69+
long n_record;
70+
71+
int pre_flag:4;
72+
int st_flag:4;
73+
74+
U_64 *pre_array;
75+
U_64 *cur_array;
76+
double *st_array;
77+
double *max_array;
78+
double *mean_array;
79+
double *min_array;
80+
81+
/* callback function of module */
82+
void (*data_collect) (struct module *);
83+
void (*set_st_record) (struct module *mod, double *, U_64 *, U_64 *, int );
84+
85+
/* mod manage */
86+
void (*mod_register) (struct module *);
8687
};
8788

8889
void register_mod_fileds(struct module *mod, char *opt, char *usage,
89-
struct mod_info *info, int n_col, void *data_collect, void *set_st_record);
90+
struct mod_info *info, int n_col, void *data_collect, void *set_st_record);
9091
void set_mod_record(struct module *mod, char *record);
9192

9293
enum {
9394
HIDE_BIT,
9495
DETAIL_BIT,
95-
SUMMARY_BIT
96+
SUMMARY_BIT,
97+
SPEC_BIT
9698
};
9799

98100

include/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,5 @@ struct configure
7070
void parse_config_file(const char *file_name);
7171
void get_include_conf();
7272
void get_threshold();
73+
void set_special_field(char *spec_field);
7374
#endif

include/define.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ enum {
117117
enum {
118118
HIDE_BIT,
119119
DETAIL_BIT,
120-
SUMMARY_BIT
120+
SUMMARY_BIT,
121+
SPEC_BIT
121122
};
122123

123124

include/framework.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct module
3636
struct mod_info *info;
3737
void *lib;
3838
int enable;
39+
int spec;
3940

4041
/* private data used by framework*/
4142
int n_item;

src/common.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,16 @@ void get_mod_hdr(char hdr[], struct module *mod)
148148
{
149149
int i, pos = 0;
150150
struct mod_info *info = mod->info;
151-
152151
for (i = 0; i < mod->n_col; i++) {
153-
if (((DATA_SUMMARY == conf.print_mode) && (SUMMARY_BIT == info[i].summary_bit))
152+
if(mod->spec) {
153+
if(SPEC_BIT == info[i].summary_bit){
154+
if (strlen(info[i].hdr) > 6) {
155+
info[i].hdr[6] = '\0';
156+
}
157+
pos += sprintf(hdr + pos, "%s%s", info[i].hdr, PRINT_DATA_SPLIT);
158+
}
159+
}
160+
else if (((DATA_SUMMARY == conf.print_mode) && (SUMMARY_BIT == info[i].summary_bit))
154161
|| ((DATA_DETAIL == conf.print_mode) && (HIDE_BIT != info[i].summary_bit))) {
155162
if (strlen(info[i].hdr) > 6) {
156163
info[i].hdr[6] = '\0';

src/config.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,32 @@ void parse_mod(char *mod_name)
3939
}
4040
}
4141

42+
void special_mod(char *spec_mod)
43+
{
44+
int i = 0, j = 0;
45+
char mod_name[32];
46+
struct module *mod = NULL;
47+
memset(mod_name,0,LEN_32);
48+
sprintf(mod_name,"mod_%s",spec_mod+5);
49+
for ( i = 0; i < statis.total_mod_num; i++ )
50+
{
51+
mod = &mods[i];
52+
if (!strcmp(mod->name,mod_name)) {
53+
/* set special field */
54+
load_modules();
55+
char *token = strtok(NULL, W_SPACE);
56+
struct mod_info *info = mod->info;
57+
for (j=0; j < mod->n_col; j++) {
58+
char *p = info[j].hdr;
59+
while( *p == ' ') p++;
60+
if(strstr(token,p)){
61+
info[j].summary_bit = SPEC_BIT;
62+
mod->spec = 1;
63+
}
64+
}
65+
}
66+
}
67+
}
4268

4369
void parse_int(int *var)
4470
{
@@ -100,6 +126,8 @@ static int parse_line(char *buff)
100126
(void) 0; /* ignore empty lines */
101127
else if (strstr(token, "mod_"))
102128
parse_mod(token);
129+
else if (strstr(token, "spec_"))
130+
special_mod(token);
103131
else if (!strcmp(token, "output_interface"))
104132
parse_string(conf.output_interface);
105133
else if (!strcmp(token, "output_file_path"))
@@ -254,3 +282,22 @@ void get_threshold(){
254282
conf.cmax[conf.mod_num]=atof(tmp[3]);
255283
conf.mod_num++;
256284
}
285+
286+
void set_special_field(char *s)
287+
{
288+
int i = 0, j = 0;
289+
struct module *mod = NULL;
290+
for ( i = 0; i < statis.total_mod_num; i++ )
291+
{
292+
mod = &mods[i];
293+
struct mod_info *info = mod->info;
294+
for (j=0; j < mod->n_col; j++) {
295+
char *p = info[j].hdr;
296+
while( *p == ' ') p++;
297+
if(strstr(s,p)){
298+
info[j].summary_bit = SPEC_BIT;
299+
mod->spec = 1;
300+
}
301+
}
302+
}
303+
}

src/framework.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ void load_modules()
6767
else {
6868
mod_register(mod);
6969
mod->enable = 1;
70+
mod->spec = 0;
7071
do_debug(LOG_INFO, "load_modules: load new module '%s' to mods\n", mod_path);
7172
}
7273
}
73-
}
74+
}
7475
}
7576
}
7677

src/output_print.c

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,34 @@ void print_array_stat(struct module *mod, double *st_array)
139139
struct mod_info *info = mod->info;
140140

141141
for (i=0; i < mod->n_col; i++) {
142-
/* print null */
143-
if (!st_array || !mod->st_flag || st_array[i] < 0) {
144-
/* print record */
145-
if (((DATA_SUMMARY == conf.print_mode) && (SUMMARY_BIT == info[i].summary_bit))
146-
|| ((DATA_DETAIL == conf.print_mode) && (HIDE_BIT != info[i].summary_bit)))
147-
printf("------%s", PRINT_DATA_SPLIT);
148-
} else {
149-
/* print record */
150-
if (((DATA_SUMMARY == conf.print_mode) && (SUMMARY_BIT == info[i].summary_bit))
151-
|| ((DATA_DETAIL == conf.print_mode) && (HIDE_BIT != info[i].summary_bit)))
152-
printf_result(st_array[i]);
142+
if(mod->spec){
143+
/* print null */
144+
if (!st_array || !mod->st_flag || st_array[i] < 0) {
145+
/* print record */
146+
if (((DATA_SUMMARY == conf.print_mode) && (SPEC_BIT == info[i].summary_bit))
147+
|| ((DATA_DETAIL == conf.print_mode) && (SPEC_BIT == info[i].summary_bit)))
148+
printf("------%s", PRINT_DATA_SPLIT);
149+
} else {
150+
/* print record */
151+
if (((DATA_SUMMARY == conf.print_mode) && (SPEC_BIT == info[i].summary_bit))
152+
|| ((DATA_DETAIL == conf.print_mode) && (SPEC_BIT == info[i].summary_bit)))
153+
printf_result(st_array[i]);
154+
}
155+
156+
}
157+
else {
158+
/* print null */
159+
if (!st_array || !mod->st_flag || st_array[i] < 0) {
160+
/* print record */
161+
if (((DATA_SUMMARY == conf.print_mode) && (SUMMARY_BIT == info[i].summary_bit))
162+
|| ((DATA_DETAIL == conf.print_mode) && (HIDE_BIT != info[i].summary_bit)))
163+
printf("------%s", PRINT_DATA_SPLIT);
164+
} else {
165+
/* print record */
166+
if (((DATA_SUMMARY == conf.print_mode) && (SUMMARY_BIT == info[i].summary_bit))
167+
|| ((DATA_DETAIL == conf.print_mode) && (HIDE_BIT != info[i].summary_bit)))
168+
printf_result(st_array[i]);
169+
}
153170
}
154171
}
155172
}
@@ -481,9 +498,17 @@ void print_tail(int tail_type)
481498
struct mod_info *info = mod->info;
482499
for (i=0; i < mod->n_col; i++) {
483500
/* print record */
484-
if (((DATA_SUMMARY == conf.print_mode) && (SUMMARY_BIT == info[i].summary_bit))
485-
|| ((DATA_DETAIL == conf.print_mode) && (HIDE_BIT != info[i].summary_bit))) {
486-
printf_result(m_tail[k]);
501+
if(mod->spec){
502+
if (((DATA_SUMMARY == conf.print_mode) && (SPEC_BIT == info[i].summary_bit))
503+
|| ((DATA_DETAIL == conf.print_mode) && (SPEC_BIT == info[i].summary_bit))) {
504+
printf_result(m_tail[k]);
505+
}
506+
}
507+
else {
508+
if (((DATA_SUMMARY == conf.print_mode) && (SUMMARY_BIT == info[i].summary_bit))
509+
|| ((DATA_DETAIL == conf.print_mode) && (HIDE_BIT != info[i].summary_bit))) {
510+
printf_result(m_tail[k]);
511+
}
487512
}
488513
k++;
489514
}
@@ -819,18 +844,35 @@ void running_check(int check_type){
819844
}
820845
st_array = &mod->st_array[j * mod->n_col];
821846
for (k=0; k < mod->n_col; k++) {
822-
if (!st_array || !mod->st_flag) {
823-
if (((DATA_SUMMARY == conf.print_mode) && (SUMMARY_BIT == info[k].summary_bit))
824-
|| ((DATA_DETAIL == conf.print_mode) && (HIDE_BIT != info[k].summary_bit))){
825-
printf("%s:%s%s=-%s",mod_name,opt,trim(info[k].hdr,LEN_128), " ");
847+
if(mod->spec){
848+
if (!st_array || !mod->st_flag) {
849+
if (((DATA_SUMMARY == conf.print_mode) && (SPEC_BIT == info[k].summary_bit))
850+
|| ((DATA_DETAIL == conf.print_mode) && (SPEC_BIT == info[k].summary_bit))){
851+
printf("%s:%s%s=-%s",mod_name,opt,trim(info[k].hdr,LEN_128), " ");
852+
}
853+
} else {
854+
if (((DATA_SUMMARY == conf.print_mode) && (SPEC_BIT == info[k].summary_bit))
855+
|| ((DATA_DETAIL == conf.print_mode) && (SPEC_BIT == info[k].summary_bit))){
856+
printf("%s:%s%s=",mod_name,opt,trim(info[k].hdr,LEN_128));
857+
//printf_check_result(st_array[k]);
858+
printf("%0.1f ",st_array[k]);
859+
}
826860
}
827-
} else {
828-
if (((DATA_SUMMARY == conf.print_mode) && (SUMMARY_BIT == info[k].summary_bit))
829-
|| ((DATA_DETAIL == conf.print_mode) && (HIDE_BIT != info[k].summary_bit))){
830-
printf("%s:%s%s=",mod_name,opt,trim(info[k].hdr,LEN_128));
831-
//printf_check_result(st_array[k]);
832-
printf("%0.1f ",st_array[k]);
861+
}else{
862+
if (!st_array || !mod->st_flag) {
863+
if (((DATA_SUMMARY == conf.print_mode) && (SUMMARY_BIT == info[k].summary_bit))
864+
|| ((DATA_DETAIL == conf.print_mode) && (HIDE_BIT != info[k].summary_bit))){
865+
printf("%s:%s%s=-%s",mod_name,opt,trim(info[k].hdr,LEN_128), " ");
866+
}
867+
} else {
868+
if (((DATA_SUMMARY == conf.print_mode) && (SUMMARY_BIT == info[k].summary_bit))
869+
|| ((DATA_DETAIL == conf.print_mode) && (HIDE_BIT != info[k].summary_bit))){
870+
printf("%s:%s%s=",mod_name,opt,trim(info[k].hdr,LEN_128));
871+
//printf_check_result(st_array[k]);
872+
printf("%0.1f ",st_array[k]);
873+
}
833874
}
875+
834876
}
835877
}
836878
if(token){

src/tsar.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ void usage()
4545
" --date/-d show the value for the specify day(n or YYYYMMDD)\n"
4646
" --merge/-m merge multiply item to one\n"
4747
" --detail/-D \tdo not conver data to K/M/G\n"
48+
" --spec/-s show spec field data, tsar --cpu -s sys,util\n"
4849
" --help/-h help\n");
4950

5051
fprintf(stderr,
@@ -74,6 +75,7 @@ struct option longopts[] = {
7475
{ "date", required_argument, NULL, 'd' },
7576
{ "merge", no_argument, NULL, 'm' },
7677
{ "detail", no_argument, NULL, 'D' },
78+
{ "spec", required_argument, NULL, 's' },
7779
{ "help", no_argument, NULL, 'h' },
7880
{ 0, 0, 0, 0},
7981
};
@@ -96,7 +98,7 @@ static void main_init(int argc, char **argv)
9698
}
9799
/*end*/
98100
#endif
99-
while ((opt = getopt_long(argc, argv, ":cCi:Llf:n:d:mhD", longopts, NULL)) != -1) {
101+
while ((opt = getopt_long(argc, argv, ":cCi:Llf:n:d:s:mhD", longopts, NULL)) != -1) {
100102
oind++;
101103
switch (opt) {
102104
case 'c':
@@ -117,6 +119,10 @@ static void main_init(int argc, char **argv)
117119
break;
118120
case 'f':
119121
strcpy(conf.output_file_path ,optarg);
122+
break;
123+
case 's':
124+
set_special_field(optarg);
125+
break;
120126
case 'n':
121127
conf.print_ndays = atoi(optarg);
122128
oind++;

0 commit comments

Comments
 (0)