| 554 | } |
| 555 | |
| 556 | static final class Profiler { |
| 557 | String profileFile; |
| 558 | ParcelFileDescriptor profileFd; |
| 559 | int samplingInterval; |
| 560 | boolean autoStopProfiler; |
| 561 | boolean profiling; |
| 562 | boolean handlingProfiling; |
| 563 | public void setProfiler(ProfilerInfo profilerInfo) { |
| 564 | ParcelFileDescriptor fd = profilerInfo.profileFd; |
| 565 | if (profiling) { |
| 566 | if (fd != null) { |
| 567 | try { |
| 568 | fd.close(); |
| 569 | } catch (IOException e) { |
| 570 | // Ignore |
| 571 | } |
| 572 | } |
| 573 | return; |
| 574 | } |
| 575 | if (profileFd != null) { |
| 576 | try { |
| 577 | profileFd.close(); |
| 578 | } catch (IOException e) { |
| 579 | // Ignore |
| 580 | } |
| 581 | } |
| 582 | profileFile = profilerInfo.profileFile; |
| 583 | profileFd = fd; |
| 584 | samplingInterval = profilerInfo.samplingInterval; |
| 585 | autoStopProfiler = profilerInfo.autoStopProfiler; |
| 586 | } |
| 587 | public void startProfiling() { |
| 588 | if (profileFd == null || profiling) { |
| 589 | return; |
| 590 | } |
| 591 | try { |
| 592 | int bufferSize = SystemProperties.getInt("debug.traceview-buffer-size-mb", 8); |
| 593 | VMDebug.startMethodTracing(profileFile, profileFd.getFileDescriptor(), |
| 594 | bufferSize * 1024 * 1024, 0, samplingInterval != 0, samplingInterval); |
| 595 | profiling = true; |
| 596 | } catch (RuntimeException e) { |
| 597 | Slog.w(TAG, "Profiling failed on path " + profileFile); |
| 598 | try { |
| 599 | profileFd.close(); |
| 600 | profileFd = null; |
| 601 | } catch (IOException e2) { |
| 602 | Slog.w(TAG, "Failure closing profile fd", e2); |
| 603 | } |
| 604 | } |
| 605 | } |
| 606 | public void stopProfiling() { |
| 607 | if (profiling) { |
| 608 | profiling = false; |
| 609 | Debug.stopMethodTracing(); |
| 610 | if (profileFd != null) { |
| 611 | try { |
| 612 | profileFd.close(); |
| 613 | } catch (IOException e) { |
nothing calls this directly
no outgoing calls
no test coverage detected