* Return kernel profiling information. */
| 323 | * Return kernel profiling information. |
| 324 | */ |
| 325 | static int |
| 326 | sysctl_kern_prof(SYSCTL_HANDLER_ARGS) |
| 327 | { |
| 328 | int *name = (int *) arg1; |
| 329 | u_int namelen = arg2; |
| 330 | struct gmonparam *gp = &_gmonparam; |
| 331 | int error; |
| 332 | int state; |
| 333 | |
| 334 | /* all sysctl names at this level are terminal */ |
| 335 | if (namelen != 1) |
| 336 | return (ENOTDIR); /* overloaded */ |
| 337 | |
| 338 | switch (name[0]) { |
| 339 | case GPROF_STATE: |
| 340 | state = gp->state; |
| 341 | error = sysctl_handle_int(oidp, &state, 0, req); |
| 342 | if (error) |
| 343 | return (error); |
| 344 | if (!req->newptr) |
| 345 | return (0); |
| 346 | if (state == GMON_PROF_OFF) { |
| 347 | gp->state = state; |
| 348 | PROC_LOCK(&proc0); |
| 349 | stopprofclock(&proc0); |
| 350 | PROC_UNLOCK(&proc0); |
| 351 | stopguprof(gp); |
| 352 | } else if (state == GMON_PROF_ON) { |
| 353 | gp->state = GMON_PROF_OFF; |
| 354 | stopguprof(gp); |
| 355 | gp->profrate = profhz; |
| 356 | PROC_LOCK(&proc0); |
| 357 | startprofclock(&proc0); |
| 358 | PROC_UNLOCK(&proc0); |
| 359 | gp->state = state; |
| 360 | #ifdef GUPROF |
| 361 | } else if (state == GMON_PROF_HIRES) { |
| 362 | gp->state = GMON_PROF_OFF; |
| 363 | PROC_LOCK(&proc0); |
| 364 | stopprofclock(&proc0); |
| 365 | PROC_UNLOCK(&proc0); |
| 366 | startguprof(gp); |
| 367 | gp->state = state; |
| 368 | #endif |
| 369 | } else if (state != gp->state) |
| 370 | return (EINVAL); |
| 371 | return (0); |
| 372 | case GPROF_COUNT: |
| 373 | return (sysctl_handle_opaque(oidp, |
| 374 | gp->kcount, gp->kcountsize, req)); |
| 375 | case GPROF_FROMS: |
| 376 | return (sysctl_handle_opaque(oidp, |
| 377 | gp->froms, gp->fromssize, req)); |
| 378 | case GPROF_TOS: |
| 379 | return (sysctl_handle_opaque(oidp, |
| 380 | gp->tos, gp->tossize, req)); |
| 381 | case GPROF_GMONPARAM: |
| 382 | return (sysctl_handle_opaque(oidp, gp, sizeof *gp, req)); |
nothing calls this directly
no test coverage detected