Skip to content

Commit a595b79

Browse files
author
Mike Kaufman
committed
Refactoring Chakra's Telemetry code, including
- simplified abstractions related to telemetry reporting (e.g., deleting concept of "telemetry provider" & "ESBuiltInsDatabase" - cleaned up code so there was a single obvious place where script telemetry being tracked/reported - cleaned up reporting code to use the publically documented telemetry reporting macros - simplified macros used to code gen supporting telemetry fields. should be easier to understand now. - deleted any code I didn't understand. :)
1 parent 5c9b7ed commit a595b79

24 files changed

+79
-85
lines changed

lib/Backend/Chakra.Backend.vcxproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,6 @@
527527
<Project>{0db5ecbc-9385-4a65-be2c-4ef7c65cb719}</Project>
528528
</ProjectReference>
529529
</ItemGroup>
530-
<ItemGroup>
531-
<ClInclude Include="CRC.h">
532-
<FileType>CppCode</FileType>
533-
</ClInclude>
534-
</ItemGroup>
535530
<Import Project="$(BuildConfigPropsPath)Chakra.Build.targets" Condition="exists('$(BuildConfigPropsPath)Chakra.Build.targets')" />
536531
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
537532
<ImportGroup Label="ExtensionTargets">

lib/Backend/Chakra.Backend.vcxproj.filters

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,6 @@
367367
<ClInclude Include="FunctionCodeGenJitTimeData.h" />
368368
<ClInclude Include="FixedFieldInfo.h" />
369369
<ClInclude Include="ObjTypeSpecFldInfo.h" />
370-
<ClInclude Include="CRC.h" />
371370
<ClInclude Include="PageAllocatorPool.h" />
372371
<ClInclude Include="GlobOptBlockData.h" />
373372
<ClInclude Include="ValueInfo.h" />

lib/Backend/Encoder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
44
//-------------------------------------------------------------------------------------------------------
55
#include "Backend.h"
6-
#include "CRC.h"
6+
#include "Core/CRC.h"
77

88
///----------------------------------------------------------------------------
99
///

lib/Common/Core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ add_library (Chakra.Common.Core OBJECT
66
CommonCorePch.cpp
77
ConfigFlagsTable.cpp
88
ConfigParser.cpp
9+
CRC.cpp
910
DbgHelpSymbolManager.cpp
1011
DelayLoadLibrary.cpp
1112
EtwTraceCore.cpp

lib/Common/Core/CRC.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
#include "CommonCorePch.h"
7+
#include "Core/CRC.h"
8+
9+
unsigned int CalculateCRC32(unsigned int bufferCRC, size_t data)
10+
{
11+
/* update running CRC calculation with contents of a buffer */
12+
13+
bufferCRC = bufferCRC ^ 0xffffffffL;
14+
bufferCRC = crc_32_tab[(bufferCRC ^ data) & 0xFF] ^ (bufferCRC >> 8);
15+
return (bufferCRC ^ 0xffffffffL);
16+
}
17+
18+
unsigned int CalculateCRC32(const char* in)
19+
{
20+
unsigned int crc = (unsigned int)-1;
21+
while (*in != '\0')
22+
{
23+
crc = (crc >> 8) ^ crc_32_tab[(crc ^ *in) & 0xFF];
24+
in++;
25+
}
26+
return crc ^ (unsigned int)-1;
27+
}

lib/Backend/CRC.h renamed to lib/Common/Core/CRC.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
16
/*
27
* CRC32 code derived from work by Gary S. Brown.
38
*/
49

10+
#pragma once
11+
512
/*
613
* Pre-populated Table used for calculating CRC32.
714
*/
@@ -41,11 +48,6 @@ static const unsigned int crc_32_tab[] =
4148
0xB3667A2EL, 0xC4614AB8L, 0x5D681B02L, 0x2A6F2B94L, 0xB40BBE37L, 0xC30C8EA1L, 0x5A05DF1BL, 0x2D02EF8DL
4249
};
4350

44-
static unsigned int CalculateCRC32(unsigned int bufferCRC, size_t data)
45-
{
46-
/* update running CRC calculation with contents of a buffer */
51+
unsigned int CalculateCRC32(unsigned int bufferCRC, size_t data);
4752

48-
bufferCRC = bufferCRC ^ 0xffffffffL;
49-
bufferCRC = crc_32_tab[(bufferCRC ^ data) & 0xFF] ^ (bufferCRC >> 8);
50-
return (bufferCRC ^ 0xffffffffL);
51-
}
53+
unsigned int CalculateCRC32(const char* in);

lib/Common/Core/Chakra.Common.Core.vcxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<ClCompile Include="$(MSBuildThisFileDirectory)GlobalSecurityPolicy.cpp" />
4545
<ClCompile Include="$(MSBuildThisFileDirectory)Output.cpp" />
4646
<ClCompile Include="$(MSBuildThisFileDirectory)PerfCounter.cpp" />
47+
<ClCompile Include="CRC.cpp" />
4748
<None Include="PerfCounterImpl.cpp" />
4849
<ClCompile Include="$(MSBuildThisFileDirectory)PerfCounterSet.cpp" />
4950
<ClCompile Include="$(MSBuildThisFileDirectory)ProfileInstrument.cpp" />
@@ -67,6 +68,7 @@
6768
<ClInclude Include="CommonTypedefs.h" />
6869
<ClInclude Include="ConfigFlagsTable.h" />
6970
<ClInclude Include="ConfigParser.h" />
71+
<ClInclude Include="CRC.h" />
7072
<ClInclude Include="CriticalSection.h" />
7173
<ClInclude Include="DbgHelpSymbolManager.h" />
7274
<ClInclude Include="DelayLoadLibrary.h" />
@@ -100,4 +102,4 @@
100102
</ItemGroup>
101103
<Import Project="$(BuildConfigPropsPath)Chakra.Build.targets" Condition="exists('$(BuildConfigPropsPath)Chakra.Build.targets')" />
102104
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
103-
</Project>
105+
</Project>

lib/Parser/Parse.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4058,7 +4058,7 @@ ParseNodePtr Parser::ParseArgList( bool *pCallOfConstants, uint16 *pSpreadArgCou
40584058
}
40594059

40604060
if (pSpreadArgCount!=nullptr && (*pSpreadArgCount) > 0){
4061-
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(SpreadFeature, m_scriptContext);
4061+
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(ES6, SpreadFeature, m_scriptContext);
40624062
}
40634063

40644064
*pCount = static_cast<uint16>(count);
@@ -4230,7 +4230,7 @@ ParseNodePtr Parser::ParseArrayList(bool *pArrayOfTaggedInts, bool *pArrayOfInts
42304230
}
42314231

42324232
if (spreadCount != nullptr && *spreadCount > 0){
4233-
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(SpreadFeature, m_scriptContext);
4233+
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(ES6, SpreadFeature, m_scriptContext);
42344234
}
42354235

42364236
if (buildAST)
@@ -5256,7 +5256,7 @@ bool Parser::ParseFncDeclHelper(ParseNodePtr pnodeFnc, LPCOLESTR pNameHint, usho
52565256

52575257
if (pnodeFnc && pnodeFnc->AsParseNodeFnc()->IsGenerator())
52585258
{
5259-
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(Generator, m_scriptContext);
5259+
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(ES6, Generator, m_scriptContext);
52605260
}
52615261

52625262
if (fncExprScope && !*pHasName)
@@ -5288,7 +5288,7 @@ bool Parser::ParseFncDeclHelper(ParseNodePtr pnodeFnc, LPCOLESTR pNameHint, usho
52885288

52895289
if (fLambda)
52905290
{
5291-
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(Lambda, m_scriptContext);
5291+
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(ES6, Lambda, m_scriptContext);
52925292
}
52935293

52945294
uint uDeferSave = m_grfscr & fscrDeferFncParse;
@@ -5736,7 +5736,7 @@ bool Parser::ParseFncDeclHelper(ParseNodePtr pnodeFnc, LPCOLESTR pNameHint, usho
57365736
}
57375737

57385738
this->m_fUseStrictMode = oldStrictMode;
5739-
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(StrictModeFunction, m_scriptContext);
5739+
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(ES6, StrictModeFunction, m_scriptContext);
57405740
}
57415741

57425742
if (fDeferred)
@@ -6779,7 +6779,7 @@ void Parser::ParseFncFormals(ParseNodePtr pnodeFnc, ParseNodePtr pnodeParentFnc,
67796779
{
67806780
if (!m_currentNodeFunc->AsParseNodeFnc()->HasDefaultArguments())
67816781
{
6782-
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(DefaultArgFunction, m_scriptContext);
6782+
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(ES6, DefaultArgFunction, m_scriptContext);
67836783
}
67846784
pnodeT->AsParseNodeVar()->pnodeInit = pnodeInit;
67856785
pnodeT->ichLim = m_pscan->IchLimTok();
@@ -6816,7 +6816,7 @@ void Parser::ParseFncFormals(ParseNodePtr pnodeFnc, ParseNodePtr pnodeParentFnc,
68166816

68176817
if (seenRestParameter)
68186818
{
6819-
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(Rest, m_scriptContext);
6819+
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(ES6, Rest, m_scriptContext);
68206820
}
68216821

68226822
if (m_token.tk != tkRParen)
@@ -7586,7 +7586,7 @@ ParseNodePtr Parser::ParseClassDecl(BOOL isDeclaration, LPCOLESTR pNameHint, uin
75867586
{
75877587
pnodeClass = CreateNode(knopClassDecl);
75887588

7589-
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(Class, m_scriptContext);
7589+
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(ES6, Class, m_scriptContext);
75907590

75917591
cbMinConstructor = m_pscan->IecpMinTok();
75927592
}
@@ -7996,7 +7996,7 @@ ParseNodePtr Parser::ParseStringTemplateDecl(ParseNodePtr pnodeTagFnc)
79967996
}
79977997

79987998
}
7999-
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(StringTemplates, m_scriptContext);
7999+
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(ES6, StringTemplates, m_scriptContext);
80008000

80018001
OUTPUT_TRACE_DEBUGONLY(
80028002
Js::StringTemplateParsePhase,
@@ -9309,12 +9309,12 @@ ParseNodePtr Parser::ParseVariableDeclaration(
93099309
else if (declarationType == tkCONST)
93109310
{
93119311
pnodeThis = CreateBlockScopedDeclNode(pid, knopConstDecl);
9312-
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(Const, m_scriptContext);
9312+
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(ES6, Const, m_scriptContext);
93139313
}
93149314
else
93159315
{
93169316
pnodeThis = CreateBlockScopedDeclNode(pid, knopLetDecl);
9317-
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(Let, m_scriptContext);
9317+
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(ES6, Let, m_scriptContext);
93189318
}
93199319

93209320
if (pid == wellKnownPropertyPids.arguments)
@@ -10994,7 +10994,7 @@ void Parser::ParseStmtList(ParseNodePtr *ppnodeList, ParseNodePtr **pppnodeLast,
1099410994
m_currentNodeFunc->AsParseNodeFnc()->SetCanBeDeferred(false);
1099510995
m_InAsmMode = true;
1099610996

10997-
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(AsmJSFunction, m_scriptContext);
10997+
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(ES6, AsmJSFunction, m_scriptContext);
1099810998
}
1099910999
}
1100011000
else if (isOctalInString)
@@ -12550,7 +12550,7 @@ IdentPtr Parser::ParseSuper(bool fAllowCall)
1255012550
}
1255112551

1255212552
currentNodeFunc->AsParseNodeFnc()->SetHasSuperReference(TRUE);
12553-
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(Super, m_scriptContext);
12553+
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(ES6, Super, m_scriptContext);
1255412554

1255512555
// If we are defer parsing, we can skip verifying that the super reference is valid.
1255612556
// If it wasn't the parser would have thrown during upfront parsing and we wouldn't be defer parsing the function.

lib/Parser/RegexParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,7 +2715,7 @@ namespace UnifiedRegex
27152715
}
27162716
flags = (RegexFlags)(flags | UnicodeRegexFlag);
27172717
// For telemetry
2718-
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(UnicodeRegexFlag, scriptContext);
2718+
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(ES6, UnicodeRegexFlag, scriptContext);
27192719

27202720
break;
27212721
}
@@ -2728,7 +2728,7 @@ namespace UnifiedRegex
27282728
}
27292729
flags = (RegexFlags)(flags | StickyRegexFlag);
27302730
// For telemetry
2731-
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(StickyRegexFlag, scriptContext);
2731+
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(ES6, StickyRegexFlag, scriptContext);
27322732

27332733
break;
27342734
}

lib/Runtime/Base/ScriptContext.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#endif
3535

3636
#ifdef ENABLE_BASIC_TELEMETRY
37-
#include "ScriptContextTelemetry.h"
37+
#include "ScriptContext/ScriptContextTelemetry.h"
3838
#endif
3939

4040
namespace Js
@@ -176,7 +176,7 @@ namespace Js
176176
, rejitReasonCountsCap(nullptr)
177177
#endif
178178
#ifdef ENABLE_BASIC_TELEMETRY
179-
, telemetry(nullptr)
179+
, telemetry()
180180
#endif
181181
#ifdef INLINE_CACHE_STATS
182182
, cacheDataMap(nullptr)
@@ -336,7 +336,7 @@ namespace Js
336336
#endif
337337

338338
#ifdef ENABLE_BASIC_TELEMETRY
339-
this->telemetry = Anew(this->TelemetryAllocator(), ScriptContextTelemetry, *this);
339+
this->telemetry = Anew(this->TelemetryAllocator(), Js::ScriptContextTelemetry, this);
340340
#endif
341341

342342
#ifdef PROFILE_STRINGS
@@ -5981,7 +5981,7 @@ void ScriptContext::RegisterPrototypeChainEnsuredToHaveOnlyWritableDataPropertie
59815981
#endif
59825982

59835983
#ifdef ENABLE_BASIC_TELEMETRY
5984-
ScriptContextTelemetry& ScriptContext::GetTelemetry()
5984+
Js::ScriptContextTelemetry& ScriptContext::GetTelemetry()
59855985
{
59865986
return *this->telemetry;
59875987
}

lib/Runtime/Base/ScriptContext.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ using namespace PlatformAgnostic;
1919
class NativeCodeGenerator;
2020
class BackgroundParser;
2121
struct IActiveScriptDirect;
22-
#ifdef ENABLE_BASIC_TELEMETRY
23-
class ScriptContextTelemetry;
24-
#endif
2522
namespace Js
2623
{
24+
#ifdef ENABLE_BASIC_TELEMETRY
25+
class ScriptContextTelemetry;
26+
#endif
27+
2728
class ScriptContext;
2829
class ScriptEditQuery;
2930
class MutationBreakpoint;
@@ -737,9 +738,9 @@ namespace Js
737738
#ifdef ENABLE_BASIC_TELEMETRY
738739

739740
private:
740-
ScriptContextTelemetry* telemetry;
741+
Js::ScriptContextTelemetry * telemetry;
741742
public:
742-
ScriptContextTelemetry& GetTelemetry();
743+
Js::ScriptContextTelemetry& GetTelemetry();
743744
bool HasTelemetry();
744745

745746
#endif

lib/Runtime/Base/ThreadContext.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -382,18 +382,6 @@ class ThreadContext sealed :
382382

383383
virtual bool IsNumericProperty(Js::PropertyId propertyId) override;
384384

385-
#ifdef ENABLE_BASIC_TELEMETRY
386-
Js::LanguageStats* GetLanguageStats()
387-
{
388-
return langTel.GetLanguageStats();
389-
}
390-
391-
void ResetLangStats()
392-
{
393-
this->langTel.Reset();
394-
}
395-
#endif
396-
397385
#ifdef ENABLE_WASM_SIMD
398386
#if _M_IX86 || _M_AMD64
399387
// auxiliary SIMD values in memory to help JIT'ed code. E.g. used for Int8x16 shuffle.
@@ -442,10 +430,6 @@ class ThreadContext sealed :
442430
// The current heap enumeration object being used during enumeration.
443431
IActiveScriptProfilerHeapEnum* heapEnum;
444432

445-
#ifdef ENABLE_BASIC_TELEMETRY
446-
Js::LanguageTelemetry langTel;
447-
#endif
448-
449433
struct PropertyGuardEntry
450434
{
451435
public:

lib/Runtime/Language/InterpreterLoop.inl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,6 @@ Js::Var Js::InterpreterStackFrame::INTERPRETERLOOPNAME()
200200
#endif
201201
#endif
202202

203-
#ifdef ENABLE_BASIC_TELEMETRY
204-
if( TELEMETRY_OPCODE_OFFSET_ENABLED )
205-
{
206-
OpcodeTelemetry& opcodeTelemetry = this->scriptContext->GetTelemetry().GetOpcodeTelemetry();
207-
opcodeTelemetry.ProgramLocationFunctionId ( this->function->GetFunctionInfo()->GetLocalFunctionId() );
208-
opcodeTelemetry.ProgramLocationBytecodeOffset( this->m_reader.GetCurrentOffset() );
209-
}
210-
#endif
211-
212203
#if DEBUGGING_LOOP
213204
if (this->scriptContext->GetThreadContext()->GetDebugManager()->stepController.IsActive() &&
214205
this->scriptContext->GetThreadContext()->GetDebugManager()->stepController.IsStepComplete_AllowingFalsePositives(this))

lib/Runtime/Language/RuntimeLanguagePch.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@
5757
#include "Debug/DebugContext.h"
5858
#endif
5959

60-
#ifdef ENABLE_BASIC_TELEMETRY
61-
#include "ScriptContextTelemetry.h"
62-
#endif
63-
6460
// .inl files
6561
#include "Language/CacheOperators.inl"
6662
#include "Language/JavascriptMathOperators.inl"

lib/Runtime/Library/JavascriptDate.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
#include "RuntimeLibraryPch.h"
66
#include "Library/EngineInterfaceObject.h"
77
#include "Library/IntlEngineInterfaceExtensionObject.h"
8-
#ifdef ENABLE_BASIC_TELEMETRY
9-
#include "ScriptContextTelemetry.h"
10-
#endif
118

129
namespace Js
1310
{

lib/Runtime/Library/JavascriptMap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Var JavascriptMap::NewInstance(RecyclableObject* function, CallInfo callInfo, ..
5353

5454
Var newTarget = args.GetNewTarget();
5555
bool isCtorSuperCall = JavascriptOperators::GetAndAssertIsConstructorSuperCall(args);
56-
CHAKRATEL_LANGSTATS_INC_DATACOUNT(ES6_Map);
56+
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(ES6, Map, scriptContext);
5757

5858
JavascriptMap* mapObject = nullptr;
5959

lib/Runtime/Library/JavascriptPromise.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace Js
2828
ScriptContext* scriptContext = function->GetScriptContext();
2929
JavascriptLibrary* library = scriptContext->GetLibrary();
3030

31-
CHAKRATEL_LANGSTATS_INC_DATACOUNT(ES6_Promise);
31+
CHAKRATEL_LANGSTATS_INC_LANGFEATURECOUNT(ES6, Promise, scriptContext);
3232

3333
// SkipDefaultNewObject function flag should have prevented the default object from
3434
// being created, except when call true a host dispatch

0 commit comments

Comments
 (0)