@@ -102,20 +102,24 @@ void bpftune_log_syslog(__attribute__((unused)) void *ctx, int level,
102
102
syslog (level , buf , buflen + 1 );
103
103
}
104
104
105
- /* log to ctx buffer as well as usual log destination */
105
+ /* log to ctx buffer for specific thread, fall back to usual log destination */
106
106
void bpftune_log_buf (void * ctx , int level , const char * fmt , va_list args )
107
107
{
108
108
struct bpftune_log_ctx_buf * c = ctx ;
109
109
va_list nextargs ;
110
+ pthread_t self ;
110
111
111
112
if (!c || level > bpftune_loglevel )
112
113
return ;
113
114
va_copy (nextargs , args );
114
- if (c -> buf_thread == pthread_self () && c -> buf_off <= c -> buf_sz ) {
115
+ self = pthread_self ();
116
+ if (c -> buf_thread == self && c -> buf_off <= c -> buf_sz ) {
115
117
c -> buf_off += vsnprintf (c -> buf + c -> buf_off ,
116
118
c -> buf_sz - c -> buf_off , fmt , args );
119
+ } else {
120
+ if (c -> buf_thread != self && c -> nextlogfn )
121
+ c -> nextlogfn (ctx , level , fmt , nextargs );
117
122
}
118
- c -> nextlogfn (ctx , level , fmt , nextargs );
119
123
va_end (nextargs );
120
124
}
121
125
@@ -2099,15 +2103,21 @@ struct bpftune_req {
2099
2103
static void bpftune_help_handler (const char * req , char * buf , size_t buf_sz );
2100
2104
static void bpftune_tuners_handler (const char * req , char * buf , size_t buf_sz );
2101
2105
static void bpftune_tunables_handler (const char * req , char * buf , size_t buf_sz );
2106
+ static void bpftune_jtunables_handler (const char * req , char * buf , size_t buf_sz );
2102
2107
static void bpftune_summary_handler (const char * req , char * buf , size_t buf_sz );
2108
+ static void bpftune_status_handler (const char * req , char * buf , size_t buf_sz );
2109
+ static void bpftune_jstatus_handler (const char * req , char * buf , size_t buf_sz );
2103
2110
static void bpftune_rollback_handler (const char * req , char * buf , size_t buf_sz );
2104
2111
2105
2112
/* add bpftune server requests with handlers here */
2106
2113
struct bpftune_req bpftune_reqs [] = {
2107
2114
{ "help" , "list supported queries" , bpftune_help_handler },
2108
2115
{ "tuners" , "show state of tuners" , bpftune_tuners_handler },
2109
2116
{ "tunables" , "show list of tunables" , bpftune_tunables_handler },
2117
+ { "jtunables" , "show list of tunables(json)" , bpftune_jtunables_handler },
2110
2118
{ "summary" , "show summary of changes" , bpftune_summary_handler },
2119
+ { "status" , "show status of tunables" , bpftune_status_handler },
2120
+ { "jstatus" , "show status of tunables(json)" ,bpftune_jstatus_handler },
2111
2121
{ "rollback" , "show changes needed to roll back" ,
2112
2122
bpftune_rollback_handler }
2113
2123
};
@@ -2136,22 +2146,76 @@ static void bpftune_tuners_handler(__attribute__((unused)) const char *req,
2136
2146
}
2137
2147
}
2138
2148
2139
- static void bpftune_tunables_handler (__attribute__((unused )) const char * req ,
2140
- char * buf , size_t buf_sz )
2149
+ static void __bpftune_tunables_handler (__attribute__((unused )) const char * req ,
2150
+ char * buf , size_t buf_sz , bool json )
2141
2151
{
2152
+ struct bpftune_log_ctx_buf ctx_buf ;
2142
2153
struct bpftuner * t ;
2143
- int off = 0 ;
2154
+ bool first = true;
2155
+
2156
+ ctx_buf .nextlogfn = bpftune_logfn ;
2157
+ ctx_buf .buf = buf ;
2158
+ ctx_buf .buf_off = 0 ;
2159
+ ctx_buf .buf_sz = buf_sz ;
2160
+ ctx_buf .buf_thread = pthread_self ();
2161
+
2162
+ bpftune_set_log (bpftune_loglevel , bpftune_log_buf , & ctx_buf );
2163
+
2164
+ if (json )
2165
+ bpftune_log (BPFTUNE_LOG_LEVEL , "{\n" );
2144
2166
2145
2167
bpftune_for_each_tuner (t ) {
2146
2168
struct bpftunable * u ;
2147
2169
unsigned int i ;
2148
2170
2171
+ if (json ) {
2172
+ if (!first )
2173
+ bpftune_log (BPFTUNE_LOG_LEVEL , "\t},\n" );
2174
+ first = false;
2175
+ bpftune_log (BPFTUNE_LOG_LEVEL , "\t\"%s\":{\n" ,
2176
+ t -> name );
2177
+ }
2149
2178
for (i = 0 ; i < t -> num_tunables ; i ++ ) {
2150
2179
u = bpftuner_tunable (t , i );
2151
- off += snprintf (buf + off , buf_sz - off , "%20s %50s\n" ,
2152
- t -> name , u -> desc .name );
2180
+ if (json ) {
2181
+ if (i > 0 )
2182
+ bpftune_log (BPFTUNE_LOG_LEVEL , "\t\t},\n" );
2183
+ bpftune_log (BPFTUNE_LOG_LEVEL , "\t\t\"%s\":{\n" ,
2184
+ u -> desc .name );
2185
+ bpftune_log (BPFTUNE_LOG_LEVEL ,
2186
+ "\t\t\t\"type\":\"%s\",\n" ,
2187
+ u -> desc .flags & BPFTUNABLE_STRING ?
2188
+ "string" : "integer" );
2189
+ bpftune_log (BPFTUNE_LOG_LEVEL ,
2190
+ "\t\t\t\"num_values\":%d\n" ,
2191
+ u -> desc .num_values );
2192
+ } else {
2193
+ bpftune_log (BPFTUNE_LOG_LEVEL ,
2194
+ "%16s %50s %8s %2d\n" ,
2195
+ t -> name , u -> desc .name ,
2196
+ u -> desc .flags & BPFTUNABLE_STRING ?
2197
+ "string" : "integer" ,
2198
+ u -> desc .num_values );
2199
+ }
2153
2200
}
2201
+ if (json && t -> num_tunables > 0 )
2202
+ bpftune_log (BPFTUNE_LOG_LEVEL , "\t\t}\n" );
2154
2203
}
2204
+ if (json )
2205
+ bpftune_log (BPFTUNE_LOG_LEVEL , "\t}\n}\n" );
2206
+ bpftune_set_log (bpftune_loglevel , ctx_buf .nextlogfn , NULL );
2207
+ }
2208
+
2209
+ static void bpftune_tunables_handler (__attribute__((unused )) const char * req ,
2210
+ char * buf , size_t buf_sz )
2211
+ {
2212
+ return __bpftune_tunables_handler (req , buf , buf_sz , false);
2213
+ }
2214
+
2215
+ static void bpftune_jtunables_handler (__attribute__((unused )) const char * req ,
2216
+ char * buf , size_t buf_sz )
2217
+ {
2218
+ return __bpftune_tunables_handler (req , buf , buf_sz , true);
2155
2219
}
2156
2220
2157
2221
static void bpftune_summary_handler (__attribute__((unused )) const char * req ,
@@ -2169,7 +2233,6 @@ static void bpftune_summary_handler(__attribute__((unused)) const char *req,
2169
2233
ctx_buf .buf_sz = buf_sz ;
2170
2234
ctx_buf .buf_thread = pthread_self ();
2171
2235
2172
- /* have summary log to buffer + usual log destination */
2173
2236
bpftune_set_log (bpftune_loglevel , bpftune_log_buf , & ctx_buf );
2174
2237
2175
2238
bpftune_for_each_tuner (t ) {
@@ -2187,10 +2250,86 @@ static void bpftune_summary_handler(__attribute__((unused)) const char *req,
2187
2250
}
2188
2251
}
2189
2252
bpftune_set_log (bpftune_loglevel , ctx_buf .nextlogfn , NULL );
2190
- bpftune_log (LOG_DEBUG , "got the following sz %d off %d, orig off %d '%s'\n" ,
2191
- ctx_buf .buf_sz , ctx_buf .buf_off , off , buf );
2192
2253
}
2193
2254
2255
+ static void __bpftune_status_handler (__attribute__((unused )) const char * req ,
2256
+ char * buf , size_t buf_sz , bool json )
2257
+ {
2258
+ struct bpftune_log_ctx_buf ctx_buf ;
2259
+ struct bpftuner * t ;
2260
+ bool first = true;
2261
+ unsigned int i ;
2262
+
2263
+ ctx_buf .nextlogfn = bpftune_logfn ;
2264
+ ctx_buf .buf = buf ;
2265
+ ctx_buf .buf_off = 0 ;
2266
+ ctx_buf .buf_sz = buf_sz ;
2267
+ ctx_buf .buf_thread = pthread_self ();
2268
+
2269
+ buf [0 ] = '\0' ;
2270
+ /* have status log to buffer, fall back to usual destination for other threads */
2271
+ bpftune_set_log (bpftune_loglevel , bpftune_log_buf , & ctx_buf );
2272
+
2273
+ if (json )
2274
+ bpftune_log (BPFTUNE_LOG_LEVEL , "{\n" );
2275
+ bpftune_for_each_tuner (t ) {
2276
+ if (json ) {
2277
+ if (!first )
2278
+ bpftune_log (BPFTUNE_LOG_LEVEL , "\t},\n" );
2279
+ first = false;
2280
+ bpftune_log (BPFTUNE_LOG_LEVEL , "\t\"%s\":{\n" , t -> name );
2281
+ }
2282
+ for (i = 0 ; i < t -> num_tunables ; i ++ ) {
2283
+ char s [PATH_MAX ], vals [PATH_MAX ] = {};
2284
+ struct bpftunable * u ;
2285
+ unsigned int j ;
2286
+
2287
+ u = bpftuner_tunable (t , i );
2288
+ if (u -> desc .type != BPFTUNABLE_SYSCTL )
2289
+ continue ;
2290
+
2291
+ if (u -> desc .flags & BPFTUNABLE_STRING ) {
2292
+ snprintf (vals , sizeof (vals ), "\"%s\"" , u -> current_str );
2293
+ } else {
2294
+ for (j = 0 ; j < u -> desc .num_values ; j ++ ) {
2295
+ snprintf (s , sizeof (s ), "%s%ld" ,
2296
+ j == 0 ? "" : json ? ", " : " " ,
2297
+ u -> current_values [j ]);
2298
+ strcat (vals , s );
2299
+ }
2300
+ }
2301
+ if (json ) {
2302
+ bpftune_log (BPFTUNE_LOG_LEVEL , "\t\t\"%s\":%s %s %s%s\n" ,
2303
+ u -> desc .name ,
2304
+ u -> desc .num_values > 1 ? "[" : "" ,
2305
+ vals ,
2306
+ u -> desc .num_values > 1 ? "]" : "" ,
2307
+ i < t -> num_tunables - 1 ? "," : "" );
2308
+ } else {
2309
+ bpftune_log (BPFTUNE_LOG_LEVEL , "%16s %50s %34s\n" ,
2310
+ t -> name , u -> desc .name , vals );
2311
+ }
2312
+ }
2313
+ }
2314
+ if (json )
2315
+ bpftune_log (BPFTUNE_LOG_LEVEL , "\t}\n}\n" );
2316
+
2317
+ bpftune_set_log (bpftune_loglevel , ctx_buf .nextlogfn , NULL );
2318
+ }
2319
+
2320
+ static void bpftune_status_handler (__attribute__((unused )) const char * req ,
2321
+ char * buf , size_t buf_sz )
2322
+ {
2323
+ return __bpftune_status_handler (req , buf , buf_sz , false);
2324
+ }
2325
+
2326
+ static void bpftune_jstatus_handler (__attribute__((unused )) const char * req ,
2327
+ char * buf , size_t buf_sz )
2328
+ {
2329
+ return __bpftune_status_handler (req , buf , buf_sz , true);
2330
+ }
2331
+
2332
+
2194
2333
static void bpftune_rollback_handler (__attribute__((unused )) const char * req ,
2195
2334
char * buf , size_t buf_sz )
2196
2335
{
@@ -2206,7 +2345,7 @@ static void bpftune_rollback_handler(__attribute__((unused)) const char *req,
2206
2345
ctx_buf .buf_sz = buf_sz ;
2207
2346
ctx_buf .buf_thread = pthread_self ();
2208
2347
2209
- /* have rollback log to buffer + usual log destination */
2348
+ /* have rollback log to buffer, fall back to usual log destination for other threads */
2210
2349
bpftune_set_log (bpftune_loglevel , bpftune_log_buf , & ctx_buf );
2211
2350
2212
2351
bpftune_for_each_tuner (t ) {
0 commit comments