1 // Copyright 2019 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_EXTENSIONS_VTUNEDOMAIN_SUPPORT_EXTENSION_H_ 6 #define V8_EXTENSIONS_VTUNEDOMAIN_SUPPORT_EXTENSION_H_ 7 8 #include "include/v8.h" 9 #include "src/third_party/vtune/vtuneapi.h" 10 #include "src/utils/utils.h" 11 12 #define UNKNOWN_PARAMS 1 << 0 13 #define NO_DOMAIN_NAME 1 << 1 14 #define CREATE_DOMAIN_FAILED 1 << 2 15 #define NO_TASK_NAME 1 << 3 16 #define CREATE_TASK_FAILED 1 << 4 17 #define TASK_BEGIN_FAILED 1 << 5 18 #define TASK_END_FAILED 1 << 6 19 20 namespace v8 { 21 namespace internal { 22 23 class VTuneDomainSupportExtension : public v8::Extension { 24 public: 25 explicit VTuneDomainSupportExtension(const char* fun_name = "test") 26 : v8::Extension("v8/vtunedomain", BuildSource(buffer_,sizeof (buffer_),fun_name)27 BuildSource(buffer_, sizeof(buffer_), fun_name)) {} 28 29 v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( 30 v8::Isolate* isolate, v8::Local<v8::String> name) override; 31 32 private: 33 static void Mark(const v8::FunctionCallbackInfo<v8::Value>& args); 34 BuildSource(char * buf,size_t size,const char * fun_name)35 static const char* BuildSource(char* buf, size_t size, const char* fun_name) { 36 SNPrintF(Vector<char>(buf, static_cast<int>(size)), "native function %s();", 37 fun_name); 38 return buf; 39 } 40 41 char buffer_[50]; 42 }; 43 44 } // namespace internal 45 } // namespace v8 46 47 #endif // V8_EXTENSIONS_VTUNEDOMAIN_SUPPORT_EXTENSION_H_ 48