• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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-extension.h"
9 #include "src/base/strings.h"
10 #include "src/base/vector.h"
11 #include "src/third_party/vtune/vtuneapi.h"
12 
13 #define UNKNOWN_PARAMS 1 << 0
14 #define NO_DOMAIN_NAME 1 << 1
15 #define CREATE_DOMAIN_FAILED 1 << 2
16 #define NO_TASK_NAME 1 << 3
17 #define CREATE_TASK_FAILED 1 << 4
18 #define TASK_BEGIN_FAILED 1 << 5
19 #define TASK_END_FAILED 1 << 6
20 
21 namespace v8 {
22 
23 template <typename T>
24 class FunctionCallbackInfo;
25 
26 namespace internal {
27 
28 class VTuneDomainSupportExtension : public v8::Extension {
29  public:
30   explicit VTuneDomainSupportExtension(const char* fun_name = "test")
31       : v8::Extension("v8/vtunedomain",
BuildSource(buffer_,sizeof (buffer_),fun_name)32                       BuildSource(buffer_, sizeof(buffer_), fun_name)) {}
33 
34   v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
35       v8::Isolate* isolate, v8::Local<v8::String> name) override;
36 
37  private:
38   static void Mark(const v8::FunctionCallbackInfo<v8::Value>& args);
39 
BuildSource(char * buf,size_t size,const char * fun_name)40   static const char* BuildSource(char* buf, size_t size, const char* fun_name) {
41     base::SNPrintF(base::Vector<char>(buf, static_cast<int>(size)),
42                    "native function %s();", fun_name);
43     return buf;
44   }
45 
46   char buffer_[50];
47 };
48 
49 }  // namespace internal
50 }  // namespace v8
51 
52 #endif  // V8_EXTENSIONS_VTUNEDOMAIN_SUPPORT_EXTENSION_H_
53