Lines Matching full:instrumentation

17 #include "instrumentation.h"
38 namespace instrumentation { namespace
40 class TestInstrumentationListener final : public instrumentation::InstrumentationListener {
65 [[maybe_unused]] instrumentation::OptionalFrame frame, in MethodExited()
73 [[maybe_unused]] instrumentation::OptionalFrame frame, in MethodExited()
182 // Unique keys used to test Instrumentation::ConfigureStubs.
190 void CheckConfigureStubs(const char* key, Instrumentation::InstrumentationLevel level) { in CheckConfigureStubs()
192 instrumentation::Instrumentation* instr = Runtime::Current()->GetInstrumentation(); in CheckConfigureStubs()
197 ScopedSuspendAll ssa("Instrumentation::ConfigureStubs"); in CheckConfigureStubs()
201 Instrumentation::InstrumentationLevel GetCurrentInstrumentationLevel() { in GetCurrentInstrumentationLevel()
219 instrumentation::Instrumentation* instr = Runtime::Current()->GetInstrumentation(); in TestEvent()
223 ScopedSuspendAll ssa("Add instrumentation listener"); in TestEvent()
247 ScopedSuspendAll ssa("Remove instrumentation listener"); in TestEvent()
268 instrumentation::Instrumentation* instrumentation = runtime->GetInstrumentation(); in DeoptimizeMethod() local
274 instrumentation->Deoptimize(method); in DeoptimizeMethod()
281 instrumentation::Instrumentation* instrumentation = runtime->GetInstrumentation(); in UndeoptimizeMethod() local
287 instrumentation->Undeoptimize(method); in UndeoptimizeMethod()
289 instrumentation->DisableDeoptimization(key, /*try_switch_to_non_debuggable=*/false); in UndeoptimizeMethod()
296 instrumentation::Instrumentation* instrumentation = runtime->GetInstrumentation(); in DeoptimizeEverything() local
302 instrumentation->DeoptimizeEverything(key); in DeoptimizeEverything()
308 instrumentation::Instrumentation* instrumentation = runtime->GetInstrumentation(); in UndeoptimizeEverything() local
314 instrumentation->UndeoptimizeEverything(key); in UndeoptimizeEverything()
316 instrumentation->DisableDeoptimization(key, /*try_switch_to_non_debuggable=*/false); in UndeoptimizeEverything()
323 instrumentation::Instrumentation* instrumentation = runtime->GetInstrumentation(); in EnableMethodTracing() local
330 instrumentation->EnableMethodTracing(key, &listener, needs_interpreter); in EnableMethodTracing()
336 instrumentation::Instrumentation* instrumentation = runtime->GetInstrumentation(); in DisableMethodTracing() local
342 instrumentation->DisableMethodTracing(key); in DisableMethodTracing()
346 static bool HasEventListener(const instrumentation::Instrumentation* instr, uint32_t event_type) in HasEventListener()
349 case instrumentation::Instrumentation::kMethodEntered: in HasEventListener()
351 case instrumentation::Instrumentation::kMethodExited: in HasEventListener()
353 case instrumentation::Instrumentation::kMethodUnwind: in HasEventListener()
355 case instrumentation::Instrumentation::kDexPcMoved: in HasEventListener()
357 case instrumentation::Instrumentation::kFieldRead: in HasEventListener()
359 case instrumentation::Instrumentation::kFieldWritten: in HasEventListener()
361 case instrumentation::Instrumentation::kExceptionThrown: in HasEventListener()
363 case instrumentation::Instrumentation::kExceptionHandled: in HasEventListener()
365 case instrumentation::Instrumentation::kBranch: in HasEventListener()
367 case instrumentation::Instrumentation::kWatchedFramePop: in HasEventListener()
370 LOG(FATAL) << "Unknown instrumentation event " << event_type; in HasEventListener()
375 static void ReportEvent(const instrumentation::Instrumentation* instr, in ReportEvent()
385 case instrumentation::Instrumentation::kMethodEntered: in ReportEvent()
388 case instrumentation::Instrumentation::kMethodExited: { in ReportEvent()
393 case instrumentation::Instrumentation::kMethodUnwind: in ReportEvent()
396 case instrumentation::Instrumentation::kDexPcMoved: in ReportEvent()
399 case instrumentation::Instrumentation::kFieldRead: in ReportEvent()
402 case instrumentation::Instrumentation::kFieldWritten: { in ReportEvent()
407 case instrumentation::Instrumentation::kExceptionThrown: { in ReportEvent()
414 case instrumentation::Instrumentation::kBranch: in ReportEvent()
417 case instrumentation::Instrumentation::kWatchedFramePop: in ReportEvent()
420 case instrumentation::Instrumentation::kExceptionHandled: { in ReportEvent()
428 LOG(FATAL) << "Unknown instrumentation event " << event_type; in ReportEvent()
437 case instrumentation::Instrumentation::kMethodEntered: in DidListenerReceiveEvent()
439 case instrumentation::Instrumentation::kMethodExited: in DidListenerReceiveEvent()
442 case instrumentation::Instrumentation::kMethodUnwind: in DidListenerReceiveEvent()
444 case instrumentation::Instrumentation::kDexPcMoved: in DidListenerReceiveEvent()
446 case instrumentation::Instrumentation::kFieldRead: in DidListenerReceiveEvent()
448 case instrumentation::Instrumentation::kFieldWritten: in DidListenerReceiveEvent()
451 case instrumentation::Instrumentation::kExceptionThrown: in DidListenerReceiveEvent()
453 case instrumentation::Instrumentation::kExceptionHandled: in DidListenerReceiveEvent()
455 case instrumentation::Instrumentation::kBranch: in DidListenerReceiveEvent()
457 case instrumentation::Instrumentation::kWatchedFramePop: in DidListenerReceiveEvent()
460 LOG(FATAL) << "Unknown instrumentation event " << event_type; in DidListenerReceiveEvent()
468 instrumentation::Instrumentation* instr = Runtime::Current()->GetInstrumentation(); in TEST_F()
486 // Test instrumentation listeners for each event.
489 jobject class_loader = LoadDex("Instrumentation"); in TEST_F()
501 TestEvent(instrumentation::Instrumentation::kMethodEntered, in TEST_F()
509 jobject class_loader = LoadDex("Instrumentation"); in TEST_F()
522 TestEvent(instrumentation::Instrumentation::kMethodExited, in TEST_F()
530 jobject class_loader = LoadDex("Instrumentation"); in TEST_F()
541 TestEvent(instrumentation::Instrumentation::kMethodExited, in TEST_F()
548 TestEvent(instrumentation::Instrumentation::kMethodUnwind); in TEST_F()
552 TestEvent(instrumentation::Instrumentation::kDexPcMoved); in TEST_F()
556 TestEvent(instrumentation::Instrumentation::kFieldRead); in TEST_F()
560 TestEvent(instrumentation::Instrumentation::kWatchedFramePop); in TEST_F()
565 jobject class_loader = LoadDex("Instrumentation"); in TEST_F()
575 TestEvent(instrumentation::Instrumentation::kFieldWritten, in TEST_F()
583 jobject class_loader = LoadDex("Instrumentation"); in TEST_F()
593 TestEvent(instrumentation::Instrumentation::kFieldWritten, in TEST_F()
600 TestEvent(instrumentation::Instrumentation::kExceptionHandled); in TEST_F()
604 TestEvent(instrumentation::Instrumentation::kExceptionThrown); in TEST_F()
608 TestEvent(instrumentation::Instrumentation::kBranch); in TEST_F()
613 jobject class_loader = LoadDex("Instrumentation"); in TEST_F()
615 instrumentation::Instrumentation* instr = runtime->GetInstrumentation(); in TEST_F()
646 instrumentation::Instrumentation* instr = runtime->GetInstrumentation(); in TEST_F()
663 jobject class_loader = LoadDex("Instrumentation"); in TEST_F()
665 instrumentation::Instrumentation* instr = runtime->GetInstrumentation(); in TEST_F()
681 // Deoptimizing a method does not change instrumentation level. in TEST_F()
682 EXPECT_EQ(Instrumentation::InstrumentationLevel::kInstrumentNothing, in TEST_F()
690 EXPECT_EQ(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, in TEST_F()
697 EXPECT_EQ(Instrumentation::InstrumentationLevel::kInstrumentNothing, in TEST_F()
704 EXPECT_EQ(Instrumentation::InstrumentationLevel::kInstrumentNothing, in TEST_F()
713 instrumentation::Instrumentation* instr = runtime->GetInstrumentation(); in TEST_F()
718 EXPECT_EQ(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, in TEST_F()
724 EXPECT_EQ(Instrumentation::InstrumentationLevel::kInstrumentNothing, in TEST_F()
732 instrumentation::Instrumentation* instr = runtime->GetInstrumentation(); in TEST_F()
737 EXPECT_EQ(Instrumentation::InstrumentationLevel::kInstrumentWithEntryExitHooks, in TEST_F()
743 EXPECT_EQ(Instrumentation::InstrumentationLevel::kInstrumentNothing, in TEST_F()
751 Instrumentation* const instr = Runtime::Current()->GetInstrumentation(); \
753 ((_level) == Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter); \
771 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
774 CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); in TEST_F()
775 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
779 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
781 // Check we can switch to instrumentation stubs in TEST_F()
783 Instrumentation::InstrumentationLevel::kInstrumentWithEntryExitHooks); in TEST_F()
784 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithEntryExitHooks, 1U); in TEST_F()
786 // Check we can disable instrumentation. in TEST_F()
787 CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); in TEST_F()
788 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
792 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
796 Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter); in TEST_F()
797 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 1U); in TEST_F()
799 // Check we can disable instrumentation. in TEST_F()
800 CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); in TEST_F()
801 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
805 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
807 // Configure stubs with instrumentation stubs. in TEST_F()
809 Instrumentation::InstrumentationLevel::kInstrumentWithEntryExitHooks); in TEST_F()
810 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithEntryExitHooks, 1U); in TEST_F()
814 Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter); in TEST_F()
815 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 1U); in TEST_F()
817 // Check we can disable instrumentation. in TEST_F()
818 CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); in TEST_F()
819 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
823 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
827 Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter); in TEST_F()
828 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 1U); in TEST_F()
830 // Configure stubs with instrumentation stubs. in TEST_F()
832 Instrumentation::InstrumentationLevel::kInstrumentWithEntryExitHooks); in TEST_F()
833 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithEntryExitHooks, 1U); in TEST_F()
835 // Check we can disable instrumentation. in TEST_F()
836 CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); in TEST_F()
837 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
842 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
844 // Configure stubs with instrumentation stubs. in TEST_F()
846 Instrumentation::InstrumentationLevel::kInstrumentWithEntryExitHooks); in TEST_F()
847 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithEntryExitHooks, 1U); in TEST_F()
851 Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter); in TEST_F()
852 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 1U); in TEST_F()
854 // Configure stubs with instrumentation stubs again. in TEST_F()
856 Instrumentation::InstrumentationLevel::kInstrumentWithEntryExitHooks); in TEST_F()
857 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithEntryExitHooks, 1U); in TEST_F()
859 // Check we can disable instrumentation. in TEST_F()
860 CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); in TEST_F()
861 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
865 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
868 CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); in TEST_F()
869 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
871 CheckConfigureStubs(kClientTwoKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); in TEST_F()
872 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
876 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
878 // Configure stubs with instrumentation stubs for 1st client. in TEST_F()
880 Instrumentation::InstrumentationLevel::kInstrumentWithEntryExitHooks); in TEST_F()
881 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithEntryExitHooks, 1U); in TEST_F()
883 // Configure stubs with instrumentation stubs for 2nd client. in TEST_F()
885 Instrumentation::InstrumentationLevel::kInstrumentWithEntryExitHooks); in TEST_F()
886 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithEntryExitHooks, 2U); in TEST_F()
888 // 1st client requests instrumentation deactivation but 2nd client still needs in TEST_F()
889 // instrumentation stubs. in TEST_F()
890 CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); in TEST_F()
891 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithEntryExitHooks, 1U); in TEST_F()
893 // 2nd client requests instrumentation deactivation in TEST_F()
894 CheckConfigureStubs(kClientTwoKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); in TEST_F()
895 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
899 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
903 Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter); in TEST_F()
904 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 1U); in TEST_F()
908 Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter); in TEST_F()
909 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 2U); in TEST_F()
911 // 1st client requests instrumentation deactivation but 2nd client still needs interpreter. in TEST_F()
912 CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); in TEST_F()
913 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 1U); in TEST_F()
915 // 2nd client requests instrumentation deactivation in TEST_F()
916 CheckConfigureStubs(kClientTwoKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); in TEST_F()
917 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
921 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
923 // Configure stubs with instrumentation stubs for 1st client. in TEST_F()
925 Instrumentation::InstrumentationLevel::kInstrumentWithEntryExitHooks); in TEST_F()
926 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithEntryExitHooks, 1U); in TEST_F()
930 Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter); in TEST_F()
931 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 2U); in TEST_F()
933 // 1st client requests instrumentation deactivation but 2nd client still needs interpreter. in TEST_F()
934 CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); in TEST_F()
935 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 1U); in TEST_F()
937 // 2nd client requests instrumentation deactivation in TEST_F()
938 CheckConfigureStubs(kClientTwoKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); in TEST_F()
939 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
943 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
947 Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter); in TEST_F()
948 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 1U); in TEST_F()
950 // Configure stubs with instrumentation stubs for 2nd client. in TEST_F()
952 Instrumentation::InstrumentationLevel::kInstrumentWithEntryExitHooks); in TEST_F()
953 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithInterpreter, 2U); in TEST_F()
955 // 1st client requests instrumentation deactivation but 2nd client still needs in TEST_F()
956 // instrumentation stubs. in TEST_F()
957 CheckConfigureStubs(kClientOneKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); in TEST_F()
958 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentWithEntryExitHooks, 1U); in TEST_F()
960 // 2nd client requests instrumentation deactivation in TEST_F()
961 CheckConfigureStubs(kClientTwoKey, Instrumentation::InstrumentationLevel::kInstrumentNothing); in TEST_F()
962 CHECK_INSTRUMENTATION(Instrumentation::InstrumentationLevel::kInstrumentNothing, 0U); in TEST_F()
965 } // namespace instrumentation