this repo has no description
at trunk 88 lines 2.8 kB view raw
1// Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com) 2#include "profiling.h" 3 4#include "bytecode.h" 5#include "frame.h" 6#include "runtime.h" 7#include "thread.h" 8 9namespace py { 10 11void profiling_call(Thread* thread) { 12 thread->disableProfiling(); 13 14 HandleScope scope(thread); 15 16 Object saved_type(&scope, thread->pendingExceptionType()); 17 Object saved_value(&scope, thread->pendingExceptionValue()); 18 Object saved_traceback(&scope, thread->pendingExceptionTraceback()); 19 thread->clearPendingException(); 20 21 word opcodes = thread->opcodeCount(); 22 23 thread->stackPush(thread->runtime()->profilingCall()); 24 thread->stackPush(thread->profilingData()); 25 Frame* frame = thread->currentFrame(); 26 Frame* previous = frame->previousFrame(); 27 thread->stackPush(previous->isSentinel() 28 ? static_cast<RawObject>(NoneType::object()) 29 : previous->function()); 30 thread->stackPush(frame->function()); 31 thread->stackPush(SmallInt::fromWord(opcodes)); 32 if (!frame->isNative()) { 33 frame->addReturnMode(Frame::kProfilerReturn); 34 } 35 RawObject result = Interpreter::call(thread, 4); 36 if (result.isErrorException()) { 37 thread->ignorePendingException(); 38 } 39 40 thread->setPendingExceptionType(*saved_type); 41 thread->setPendingExceptionValue(*saved_value); 42 thread->setPendingExceptionTraceback(*saved_traceback); 43 44 word slack = thread->opcodeCount() - opcodes; 45 thread->countOpcodes(-slack); 46 thread->enableProfiling(); 47} 48 49void profiling_return(Thread* thread) { 50 if (!thread->profilingEnabled()) return; 51 thread->disableProfiling(); 52 53 HandleScope scope(thread); 54 Object saved_type(&scope, thread->pendingExceptionType()); 55 Object saved_value(&scope, thread->pendingExceptionValue()); 56 Object saved_traceback(&scope, thread->pendingExceptionTraceback()); 57 thread->clearPendingException(); 58 59 word opcodes = thread->opcodeCount(); 60 61 Frame* frame = thread->currentFrame(); 62 Object from(&scope, frame->function()); 63 Object to(&scope, NoneType::object()); 64 Frame* previous_frame = frame->previousFrame(); 65 if (!previous_frame->isSentinel()) { 66 to = previous_frame->function(); 67 } 68 69 thread->stackPush(thread->runtime()->profilingReturn()); 70 thread->stackPush(thread->profilingData()); 71 thread->stackPush(*from); 72 thread->stackPush(*to); 73 thread->stackPush(SmallInt::fromWord(opcodes)); 74 RawObject result = Interpreter::call(thread, 4); 75 if (result.isErrorException()) { 76 thread->ignorePendingException(); 77 } 78 79 thread->setPendingExceptionType(*saved_type); 80 thread->setPendingExceptionValue(*saved_value); 81 thread->setPendingExceptionTraceback(*saved_traceback); 82 83 word slack = thread->opcodeCount() - opcodes; 84 thread->countOpcodes(-slack); 85 thread->enableProfiling(); 86} 87 88} // namespace py