-
Notifications
You must be signed in to change notification settings - Fork 1
/
v8monoctx.h
81 lines (64 loc) · 2.35 KB
/
v8monoctx.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef v8monoctx_h__
#define v8monoctx_h__
#include <v8.h>
#include <assert.h>
#include <errno.h>
#include <map>
#include <string>
#include <sstream>
#include <vector>
#include <sys/time.h>
#include <sys/stat.h>
#include <string.h>
#undef New
#undef Null
#undef do_open
#undef do_close
// #define PERSISTENT_COPYABLE v8::Persistent<v8::Script, v8::CopyablePersistentTraits<v8::Script> >
#define CMD_ARGS_LEN 250
// Configuration struct
struct monocfg {
/* config */
unsigned int run_low_memory_notification; // call LowMemoryNotification after number of requests
unsigned int run_idle_notification_loop;// call IdleNotification loop after number of requests
bool watch_templates; // if template changed since last compilation - recompile it
char cmd_args[CMD_ARGS_LEN]; // command like arguments for v8 tuning
/* counters */
unsigned int request_num; // requests totally processed
double run_low_memory_notification_time;
double run_idle_notification_loop_time;
double compile_time;
double exec_time;
};
// Heap statistics struct
typedef struct heapst {
size_t heap_size_limit;
size_t used_heap_size;
size_t total_heap_size;
size_t total_heap_size_executable;
size_t total_physical_size;
} HeapSt;
// Profiler and stat functions
void StartProfile(struct timeval *t1);
double StopProfile(struct timeval *t1);
void GetHeapStat(HeapSt * st);
// Convert to simple cstring
const char* ToCString(const v8::String::Utf8Value& value);
// Reads a file into a string
std::string ReadFile(std::string name);
void ReportException(v8::TryCatch* try_catch);
// This function returns a new array with three elements, x, y, and z
void DataFetch(const v8::FunctionCallbackInfo<v8::Value>& args);
// Global console.error function
void ConsoleError(const v8::FunctionCallbackInfo<v8::Value>& args);
std::vector<std::string> GetErrors (void);
bool InitIsolate(monocfg *cfg);
bool CompileFile(monocfg *cfg, std::string fname, v8::Local<v8::Script> *script, v8::TryCatch *try_catch);
bool CompileSource(monocfg *cfg, std::string source_text, v8::Local<v8::Script> *script, v8::TryCatch *try_catch);
bool LoadFile(monocfg *cfg, std::string fname);
bool LoadConfig(monocfg *cfg, std::string fname);
bool ExecuteFile(monocfg *cfg, std::string fname, std::string run, std::string* json, std::string* out);
// V8 gc interfaces
bool IdleNotification(int ms);
void LowMemoryNotification();
#endif