Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit 25ca0d9

Browse files
mrkmarronkfarnung
authored andcommitted
chakrashim: fix cpplint warns
Add quick tests around TTD buffer tracking (reduce performance overhead when not running TTD). PR-URL: #205 Reviewed-By: Kunal Pathak <kpathak@microsoft.com> Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
1 parent 203bf79 commit 25ca0d9

File tree

11 files changed

+134
-91
lines changed

11 files changed

+134
-91
lines changed

deps/chakrashim/src/v8arraybuffer.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,21 @@ ArrayBuffer::Contents ArrayBuffer::GetContents() {
107107
}
108108

109109
// ENABLE_TTD
110-
void ArrayBuffer::TTDRawBufferNotifyRegisterForModification(byte* initialModPosition) {
111-
JsTTDRawBufferAsyncModificationRegister(this, initialModPosition);
110+
void ArrayBuffer::TTDRawBufferNotifyRegisterForModification(
111+
byte* initialModPosition) {
112+
JsTTDRawBufferAsyncModificationRegister(this, initialModPosition);
112113
}
113114

114115
void ArrayBuffer::TTDRawBufferAsyncModifyComplete(byte* finalModPosition) {
115-
JsTTDRawBufferAsyncModifyComplete(finalModPosition);
116+
JsTTDRawBufferAsyncModifyComplete(finalModPosition);
116117
}
117118
void ArrayBuffer::TTDRawBufferModifyNotifySync(UINT32 index, UINT32 count) {
118-
JsTTDRawBufferModifySyncIndirect(this, index, count);
119+
JsTTDRawBufferModifySyncIndirect(this, index, count);
119120
}
120121
void ArrayBuffer::TTDRawBufferCopyNotify(Local<ArrayBuffer> dst,
121-
UINT32 dstindex, Local<ArrayBuffer> src,
122+
UINT32 dstindex, Local<ArrayBuffer> src,
122123
UINT32 srcIndex, UINT32 count) {
123-
JsTTDRawBufferCopySyncIndirect(*dst, dstindex, *src, srcIndex, count);
124+
JsTTDRawBufferCopySyncIndirect(*dst, dstindex, *src, srcIndex, count);
124125
}
125126

126127
ArrayBuffer* ArrayBuffer::Cast(Value* obj) {

src/env-inl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ inline v8::Local<v8::Float64Array> Environment::fs_stats_field_array() const {
387387
return v8::Local<v8::Float64Array>::New(isolate_, fs_stats_field_array_);
388388
}
389389

390-
inline void Environment::set_fs_stats_field_array(v8::Local<v8::Float64Array> fields) {
390+
inline void Environment::set_fs_stats_field_array(
391+
v8::Local<v8::Float64Array> fields) {
391392
CHECK_EQ(fs_stats_field_array_.IsEmpty(), true); // Should be set only once.
392393
fs_stats_field_array_ = v8::Global<v8::Float64Array>::New(isolate_, fields);
393394
}

src/env.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ class Environment {
607607

608608
char* http_parser_buffer_;
609609

610-
//We depend on the property in fs.js to manage the lifetime appropriately
610+
// We depend on the property in fs.js to manage the lifetime appropriately
611611
v8::Global<v8::Float64Array> fs_stats_field_array_;
612612

613613
#define V(PropertyName, TypeName) \

src/node.cc

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2325,7 +2325,9 @@ void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
23252325
fields[3] = isolate->AdjustAmountOfExternalAllocatedMemory(0);
23262326

23272327
#if ENABLE_TTD_NODE
2328-
ab->TTDRawBufferModifyNotifySync(array->ByteOffset(), 4 * sizeof(double));
2328+
if (s_doTTRecord || s_doTTReplay) {
2329+
ab->TTDRawBufferModifyNotifySync(array->ByteOffset(), 4 * sizeof(double));
2330+
}
23292331
#endif
23302332
}
23312333

@@ -2364,8 +2366,10 @@ void Hrtime(const FunctionCallbackInfo<Value>& args) {
23642366
fields[1] = (t / NANOS_PER_SEC) & 0xffffffff;
23652367
fields[2] = t % NANOS_PER_SEC;
23662368
#if ENABLE_TTD_NODE
2367-
ab->TTDRawBufferModifyNotifySync(args[0].As<Uint32Array>()->ByteOffset(),
2368-
3 * sizeof(uint32_t));
2369+
if (s_doTTRecord || s_doTTReplay) {
2370+
ab->TTDRawBufferModifyNotifySync(args[0].As<Uint32Array>()->ByteOffset(),
2371+
3 * sizeof(uint32_t));
2372+
}
23692373
#endif
23702374
}
23712375

@@ -2400,7 +2404,9 @@ void CPUUsage(const FunctionCallbackInfo<Value>& args) {
24002404
fields[0] = MICROS_PER_SEC * rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec;
24012405
fields[1] = MICROS_PER_SEC * rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec;
24022406
#if ENABLE_TTD_NODE
2403-
ab->TTDRawBufferModifyNotifySync(array->ByteOffset(), 2 * sizeof(double));
2407+
if (s_doTTRecord || s_doTTReplay) {
2408+
ab->TTDRawBufferModifyNotifySync(array->ByteOffset(), 2 * sizeof(double));
2409+
}
24042410
#endif
24052411
}
24062412

@@ -3654,28 +3660,29 @@ static void PrintHelp() {
36543660
" stderr\n"
36553661
"OPENSSL_CONF load OpenSSL configuration from file\n"
36563662
"\n"
3657-
"Documentation can be found at https://nodejs.org/\n"
36583663
#if ENABLE_TTD_NODE
3659-
"Record/Replay production diagnostics info at http://aka.ms/nodettd\n"
3664+
"Documentation can be found at https://nodejs.org/\n"
3665+
"Record/Replay diagnostics info at http://aka.ms/nodettd\n");
3666+
#else
3667+
"Documentation can be found at https://nodejs.org/\n");
36603668
#endif
3661-
);
36623669
}
36633670

36643671
#if ENABLE_TTD_NODE
3665-
void TTDFlagWarning(const char* msg, const char* arg) {
3666-
fprintf(stderr, "%s", msg);
3667-
if(arg != nullptr) {
3668-
fprintf(stderr, "> %s\n", arg);
3669-
}
3672+
void TTDFlagWarning(const char* arg, const char* newflag) {
3673+
fprintf(stderr, "Flag %s is deprecated use %s\n", arg, newflag);
36703674
fprintf(stderr, "Run with \"-h\" for help with flags.\n");
36713675

36723676
exit(1);
36733677
}
36743678

36753679
void TTDFlagWarning_Cond(bool cond, const char* msg) {
3676-
if(!cond) {
3677-
TTDFlagWarning(msg, nullptr);
3678-
}
3680+
if (!cond) {
3681+
fprintf(stderr, "%s\n", msg);
3682+
fprintf(stderr, "Run with \"-h\" for help with flags.\n");
3683+
3684+
exit(1);
3685+
}
36793686
}
36803687
#endif
36813688

@@ -3793,38 +3800,38 @@ static void ParseArgs(int* argc,
37933800
trace_enabled_categories = categories;
37943801
#if ENABLE_TTD_NODE
37953802
// Parse and extract the TT args
3796-
} else if(strcmp(arg, "--record") == 0) {
3803+
} else if (strcmp(arg, "--record") == 0) {
37973804
s_doTTRecord = true;
3798-
} else if(strstr(arg, "--replay=") == arg) {
3805+
} else if (strstr(arg, "--replay=") == arg) {
37993806
s_doTTReplay = true;
38003807
s_ttoptReplayUri = arg + strlen("--replay=");
38013808
s_ttoptReplayUriLength = strlen(s_ttoptReplayUri);
3802-
} else if(strstr(arg, "--replay-debug=") == arg) {
3809+
} else if (strstr(arg, "--replay-debug=") == arg) {
38033810
s_doTTReplay = true;
38043811
s_doTTDebug = true;
38053812
s_ttoptReplayUri = arg + strlen("--replay-debug=");
38063813
s_ttoptReplayUriLength = strlen(s_ttoptReplayUri);
3807-
} else if(strcmp(arg, "--break-first") == 0) {
3814+
} else if (strcmp(arg, "--break-first") == 0) {
38083815
s_ttdStartupMode = (0x100 | 0x1);
38093816
debug_options.do_wait_for_connect();
3810-
} else if(strstr(arg, "--record-interval=") == arg) {
3817+
} else if (strstr(arg, "--record-interval=") == arg) {
38113818
const char* intervalStr = arg + strlen("--record-interval=");
38123819
s_ttdSnapInterval = (uint32_t)atoi(intervalStr);
3813-
} else if(strstr(arg, "--record-history=") == arg) {
3820+
} else if (strstr(arg, "--record-history=") == arg) {
38143821
const char* historyStr = arg + strlen("--record-history=");
38153822
s_ttdSnapHistoryLength = (uint32_t)atoi(historyStr);
3816-
} else if(strstr(arg, "-TTRecord:") == arg) {
3817-
TTDFlagWarning("-TTRecord:[dir] is deprecated use --record\n", arg);
3818-
} else if(strstr(arg, "-TTReplay:") == arg) {
3819-
TTDFlagWarning("-TTReplay:[dir] is deprecated use --replay=dir\n", arg);
3820-
} else if(strstr(arg, "-TTDebug:") == arg) {
3821-
TTDFlagWarning("-TTDebug:[dir] is deprecated use --replay-debug=dir\n", arg);
3822-
} else if(strstr(arg, "-TTBreakFirst") == arg) {
3823-
TTDFlagWarning("-TTBreakFirst is deprecated use --break-first\n", arg);
3824-
} else if(strstr(arg, "-TTSnapInterval:") == arg) {
3825-
TTDFlagWarning("-TTSnapInterval is deprecated use --record-interval=num\n", arg);
3826-
} else if(strstr(arg, "-TTHistoryLength:") == arg) {
3827-
TTDFlagWarning("-TTHistoryLength is deprecated use --record-history=num\n", arg);
3823+
} else if (strstr(arg, "-TTRecord:") == arg) {
3824+
TTDFlagWarning(arg, "--record");
3825+
} else if (strstr(arg, "-TTReplay:") == arg) {
3826+
TTDFlagWarning(arg, "--replay=dir");
3827+
} else if (strstr(arg, "-TTDebug:") == arg) {
3828+
TTDFlagWarning(arg, "--replay-debug=dir");
3829+
} else if (strstr(arg, "-TTBreakFirst") == arg) {
3830+
TTDFlagWarning(arg, "--break-first");
3831+
} else if (strstr(arg, "-TTSnapInterval:") == arg) {
3832+
TTDFlagWarning(arg, "--record-interval=num");
3833+
} else if (strstr(arg, "-TTHistoryLength:") == arg) {
3834+
TTDFlagWarning(arg, "--record-history=num");
38283835
#endif
38293836
} else if (strcmp(arg, "--track-heap-objects") == 0) {
38303837
track_heap_objects = true;
@@ -4607,7 +4614,7 @@ inline int Start(Isolate* isolate, void* isolate_context,
46074614
#if ENABLE_TTD_NODE
46084615
// Start time travel after environment is loaded
46094616
if (s_doTTRecord) {
4610-
fprintf(stderr, "Recording has been started (after main module loading)...\n");
4617+
fprintf(stderr, "Recording started (after main module loaded)...\n");
46114618
JsTTDStart();
46124619
}
46134620
#endif
@@ -4667,7 +4674,7 @@ inline int Start(uv_loop_t* event_loop,
46674674
#endif
46684675

46694676
#if ENABLE_TTD_NODE
4670-
if(s_doTTRecord) {
4677+
if (s_doTTRecord) {
46714678
fprintf(stderr, "Recording is enabled (but not yet started)...\n");
46724679
}
46734680

@@ -4792,7 +4799,7 @@ inline int Start_TTDReplay(Isolate* isolate, void* isolate_context,
47924799
&s_ttdStartupMode,
47934800
&nextEventTime);
47944801

4795-
//don't continue replay actions if we are not in debug mode
4802+
// don't continue replay actions if we are not in debug mode
47964803
continueReplayActions &= s_doTTDebug;
47974804
}
47984805

@@ -4813,7 +4820,7 @@ inline int Start_TTDReplay(uv_loop_t* event_loop,
48134820
params.code_event_handler = vTune::GetVtuneCodeEventHandler();
48144821
#endif
48154822

4816-
fprintf(stderr, "Starting TT replay/debug using log in %s\n", s_ttoptReplayUri);
4823+
fprintf(stderr, "Starting replay/debug using log in %s\n", s_ttoptReplayUri);
48174824
Isolate* const isolate = Isolate::NewWithTTDSupport(params,
48184825
s_ttoptReplayUriLength,
48194826
s_ttoptReplayUri,
@@ -4929,28 +4936,29 @@ int Start(int argc, char** argv) {
49294936
v8_initialized = true;
49304937

49314938
#if ENABLE_TTD_NODE
4932-
bool chk_debug_enabled = debug_options.debugger_enabled() || debug_options.inspector_enabled();
4939+
bool chk_debug_enabled = debug_options.debugger_enabled()
4940+
|| debug_options.inspector_enabled();
49334941

49344942
TTDFlagWarning_Cond(!s_doTTRecord || !s_doTTReplay,
49354943
"Cannot enable record & replay at same time.\n");
49364944

4937-
if(s_doTTRecord || s_doTTReplay) {
4945+
if (s_doTTRecord || s_doTTReplay) {
49384946
TTDFlagWarning_Cond(eval_string == nullptr,
49394947
"Eval mode not supported in record/replay.\n");
49404948

49414949
TTDFlagWarning_Cond(!force_repl,
49424950
"Repl mode not supported in record/replay.\n");
49434951
}
49444952

4945-
if(s_doTTRecord) {
4953+
if (s_doTTRecord) {
49464954
TTDFlagWarning_Cond(!chk_debug_enabled,
49474955
"Cannot enable debugger with record mode.\n");
49484956

49494957
TTDFlagWarning_Cond(s_ttdStartupMode == 0x1,
49504958
"Cannot set break flags in record mode.\n");
49514959
}
49524960

4953-
if(s_doTTReplay) {
4961+
if (s_doTTReplay) {
49544962
TTDFlagWarning_Cond(!chk_debug_enabled || s_doTTDebug,
49554963
"Must enable --replay-debug if attaching debugger.\n");
49564964

src/node_buffer.cc

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ size_t Length(Local<Value> val) {
227227
}
228228

229229
#if ENABLE_TTD_NODE
230-
void TTDAsyncModRegister(v8::Local<v8::Object> val, unsigned char* initialModPosition) {
230+
void TTDAsyncModRegister(v8::Local<v8::Object> val,
231+
unsigned char* initialModPosition) {
231232
CHECK(val->IsUint8Array());
232233
Local<Uint8Array> ui = val.As<Uint8Array>();
233234
ui->Buffer()->TTDRawBufferNotifyRegisterForModification(initialModPosition);
@@ -596,11 +597,13 @@ void Copy(const FunctionCallbackInfo<Value> &args) {
596597
args.GetReturnValue().Set(to_copy);
597598

598599
#if ENABLE_TTD_NODE
599-
ArrayBuffer::TTDRawBufferCopyNotify(target->Buffer(),
600-
target_offset + target_start,
601-
ts_obj->Buffer(),
602-
ts_obj_offset + source_start,
603-
to_copy);
600+
if (s_doTTRecord || s_doTTReplay) {
601+
ArrayBuffer::TTDRawBufferCopyNotify(target->Buffer(),
602+
target_offset + target_start,
603+
ts_obj->Buffer(),
604+
ts_obj_offset + source_start,
605+
to_copy);
606+
}
604607
#endif
605608
}
606609

@@ -638,7 +641,9 @@ void Fill(const FunctionCallbackInfo<Value>& args) {
638641
// TODO(mrkmarron): We could improve performance since this is a constant
639642
// value. Fill by just logging constant (instead of copying modified range).
640643
//
641-
ts_obj->Buffer()->TTDRawBufferModifyNotifySync(start, fill_length);
644+
if (s_doTTRecord || s_doTTReplay) {
645+
ts_obj->Buffer()->TTDRawBufferModifyNotifySync(start, fill_length);
646+
}
642647
#endif
643648

644649
return;
@@ -754,8 +759,10 @@ void StringWrite(const FunctionCallbackInfo<Value>& args) {
754759
args.GetReturnValue().Set(written);
755760

756761
#if ENABLE_TTD_NODE
757-
args.This().As<Uint8Array>()->Buffer()->TTDRawBufferModifyNotifySync(
758-
ts_obj_offset + offset, written);
762+
if (s_doTTRecord || s_doTTReplay) {
763+
args.This().As<Uint8Array>()->Buffer()->TTDRawBufferModifyNotifySync(
764+
ts_obj_offset + offset, written);
765+
}
759766
#endif
760767
}
761768

@@ -897,8 +904,10 @@ void WriteFloatGeneric(const FunctionCallbackInfo<Value>& args) {
897904
Swizzle(na.bytes, sizeof(na.bytes));
898905
memcpy(ptr, na.bytes, memcpy_num);
899906
#if ENABLE_TTD_NODE
900-
ts_obj->Buffer()->TTDRawBufferModifyNotifySync(ts_obj_offset + offset,
901-
memcpy_num);
907+
if (s_doTTRecord || s_doTTReplay) {
908+
ts_obj->Buffer()->TTDRawBufferModifyNotifySync(ts_obj_offset + offset,
909+
memcpy_num);
910+
}
902911
#endif
903912
}
904913

@@ -1247,8 +1256,10 @@ void Swap16(const FunctionCallbackInfo<Value>& args) {
12471256
args.GetReturnValue().Set(args[0]);
12481257

12491258
#if ENABLE_TTD_NODE
1250-
args[0].As<Uint8Array>()->Buffer()->TTDRawBufferModifyNotifySync(
1251-
ts_obj_offset, ts_obj_length);
1259+
if (s_doTTRecord || s_doTTReplay) {
1260+
args[0].As<Uint8Array>()->Buffer()->TTDRawBufferModifyNotifySync(
1261+
ts_obj_offset, ts_obj_length);
1262+
}
12521263
#endif
12531264
}
12541265

@@ -1261,8 +1272,10 @@ void Swap32(const FunctionCallbackInfo<Value>& args) {
12611272
args.GetReturnValue().Set(args[0]);
12621273

12631274
#if ENABLE_TTD_NODE
1264-
args[0].As<Uint8Array>()->Buffer()->TTDRawBufferModifyNotifySync(
1265-
ts_obj_offset, ts_obj_length);
1275+
if (s_doTTRecord || s_doTTReplay) {
1276+
args[0].As<Uint8Array>()->Buffer()->TTDRawBufferModifyNotifySync(
1277+
ts_obj_offset, ts_obj_length);
1278+
}
12661279
#endif
12671280
}
12681281

@@ -1275,8 +1288,10 @@ void Swap64(const FunctionCallbackInfo<Value>& args) {
12751288
args.GetReturnValue().Set(args[0]);
12761289

12771290
#if ENABLE_TTD_NODE
1278-
args[0].As<Uint8Array>()->Buffer()->TTDRawBufferModifyNotifySync(
1279-
ts_obj_offset, ts_obj_length);
1291+
if (s_doTTRecord || s_doTTReplay) {
1292+
args[0].As<Uint8Array>()->Buffer()->TTDRawBufferModifyNotifySync(
1293+
ts_obj_offset, ts_obj_length);
1294+
}
12801295
#endif
12811296
}
12821297

src/node_buffer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ NODE_EXTERN void TTDSyncDataModNotify(v8::Local<v8::Object> val,
5050
// Notify us that a native buffer access (which we don't currently
5151
// understand/support) happened.
5252
#define TTD_NATIVE_BUFFER_ACCESS_NOTIFY(X) \
53-
JsTTDCheckAndAssertIfTTDRunning( \
54-
"Unsupported raw buffer access -- investigate this!!!\n")
53+
if (s_doTTRecord || s_doTTReplay) { \
54+
JsTTDCheckAndAssertIfTTDRunning( \
55+
"Unsupported raw buffer access -- investigate this!!!\n"); \
56+
}
5557
#else
5658
#define TTD_NATIVE_BUFFER_ACCESS_NOTIFY(X)
5759
#endif

0 commit comments

Comments
 (0)