1+ // Copyright (c) Microsoft Corporation.
2+ // Licensed under the MIT license.
3+
4+ using System ;
5+ using System . Collections . Generic ;
6+ using System . IO ;
7+ using LTTngCdsUnitTest . SourceDataCookers ;
8+ using Microsoft . Performance . SDK . Extensibility ;
9+ using Microsoft . Performance . SDK . Processing ;
10+ using Microsoft . Performance . Toolkit . Engine ;
11+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
12+
13+ namespace LTTngCdsUnitTest
14+ {
15+ [ TestClass ]
16+ public class LTTngCdsUnitTest
17+ {
18+ public static bool IsTraceProcessed = false ;
19+ public static object IsTraceProcessedLock = new object ( ) ;
20+
21+ private static RuntimeExecutionResults RuntimeExecutionResults ;
22+
23+ private static DataCookerPath LTTngEventDataCookerPath ;
24+
25+ public static void ProcessTrace ( )
26+ {
27+ lock ( IsTraceProcessedLock )
28+ {
29+ if ( ! IsTraceProcessed )
30+ {
31+ // Input data
32+ string [ ] lttngData = { @"..\..\..\..\TestData\LTTng\lttng-kernel-trace.ctf" } ;
33+ var lttngDataPath = new FileInfo ( lttngData [ 0 ] ) ;
34+ Assert . IsTrue ( lttngDataPath . Exists ) ;
35+
36+ var runtime = Engine . Create ( new FileDataSource ( lttngDataPath . FullName ) ) ;
37+
38+ // Enable our various types of data
39+ var lttngDataCooker = new LTTngEventDataCooker ( ) ;
40+ LTTngEventDataCookerPath = lttngDataCooker . Path ;
41+ runtime . EnableCooker ( LTTngEventDataCookerPath ) ;
42+
43+ //
44+ // Process our data.
45+ //
46+
47+ RuntimeExecutionResults = runtime . Process ( ) ;
48+
49+ IsTraceProcessed = true ;
50+ }
51+ }
52+ }
53+
54+ [ TestMethod ]
55+ public void TestLTTngEvent ( )
56+ {
57+ ProcessTrace ( ) ;
58+
59+ var eventData = RuntimeExecutionResults . QueryOutput < IReadOnlyList < LTTngEventWithContext > > (
60+ new DataOutputPath (
61+ LTTngEventDataCookerPath ,
62+ nameof ( LTTngEventDataCooker . Events ) ) ) ;
63+
64+ Assert . IsTrue ( eventData . Count == 936356 ) ;
65+
66+ var lttngEvent3 = eventData [ 3 ] ;
67+
68+ // Context
69+ Assert . IsTrue ( lttngEvent3 . LTTngContext . Clocks . Count == 1 ) ;
70+ Assert . IsTrue ( lttngEvent3 . LTTngContext . Clocks [ "monotonic" ] . Name == "monotonic" ) ;
71+ Assert . IsTrue ( lttngEvent3 . LTTngContext . Clocks [ "monotonic" ] . Frequency == 1000000000 ) ;
72+ Assert . IsTrue ( lttngEvent3 . LTTngContext . Clocks [ "monotonic" ] . Offset == 1565905093154690150 ) ;
73+ Assert . IsTrue ( lttngEvent3 . LTTngContext . CurrentCpu == 1 ) ;
74+ Assert . IsTrue ( lttngEvent3 . LTTngContext . Timestamp == 7120199554940 ) ;
75+ Assert . IsTrue ( lttngEvent3 . LTTngContext . TracerMajor == 9 &&
76+ lttngEvent3 . LTTngContext . TracerMinor == 10 ) ;
77+
78+ // LTTngEvent
79+ Assert . IsTrue ( lttngEvent3 . LTTngEvent . Id == 1178 ) ;
80+ Assert . IsTrue ( lttngEvent3 . LTTngEvent . Name == "sched_waking" ) ;
81+ Assert . IsTrue ( lttngEvent3 . LTTngEvent . Payload . Fields . Count == 4 ) ;
82+ Assert . IsTrue ( lttngEvent3 . LTTngEvent . StreamDefinedEventContext . Fields . Count == 3 ) ;
83+ Assert . IsTrue ( lttngEvent3 . LTTngEvent . StreamDefinedEventContext . FieldsByName . ContainsKey ( "_tid" ) ) ;
84+ Assert . IsTrue ( lttngEvent3 . LTTngEvent . StreamDefinedEventContext . FieldsByName . ContainsKey ( "_pid" ) ) ;
85+ Assert . IsTrue ( lttngEvent3 . LTTngEvent . StreamDefinedEventContext . FieldsByName . ContainsKey ( "_procname" ) ) ;
86+ Assert . IsTrue ( lttngEvent3 . LTTngEvent . WallClockTime == new DateTime ( 637015090133542450 ) ) ;
87+ Assert . IsTrue ( lttngEvent3 . LTTngEvent . Timestamp == new Microsoft . Performance . SDK . Timestamp ( 7120199554940 ) ) ;
88+ }
89+ }
90+ }
0 commit comments