summaryrefslogtreecommitdiffstats
path: root/lldb/tools/lldb-perf/darwin/sketch/main.cpp
blob: dba3b4dc5343086d6ab288b6c822e8d87e2f1a10 (plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
//
//  main.cpp
//  PerfTestDriver
//
//  Created by Enrico Granata on 3/6/13.
//  Copyright (c) 2013 Apple Inc. All rights reserved.
//

#include <CoreFoundation/CoreFoundation.h>

#include "lldb-perf/lib/Timer.h"
#include "lldb-perf/lib/Metric.h"
#include "lldb-perf/lib/Measurement.h"
#include "lldb-perf/lib/TestCase.h"
#include "lldb-perf/lib/Xcode.h"

#include <iostream>
#include <unistd.h>
#include <fstream>

using namespace lldb_perf;

class SketchTest : public TestCase
{
public:
    SketchTest () :
    m_fetch_frames_measurement ([this] (SBProcess process) -> void {
        Xcode::FetchFrames (process,false,false);
    }, "fetch-frames", "time to dump backtrace for every frame in every thread"),
    m_file_line_bp_measurement([] (SBTarget target,const char* file, uint32_t line) -> void {
        Xcode::CreateFileLineBreakpoint(target, file, line);
    }, "file-line-bkpt", "time to set a breakpoint given a file and line"),
    m_fetch_modules_measurement ([] (SBTarget target) -> void {
        Xcode::FetchModules(target);
    }, "fetch-modules", "time to get info for all modules in the process"),
    m_fetch_vars_measurement([this] (SBProcess process, int depth) -> void {
        auto threads_count = process.GetNumThreads();
        for (size_t thread_num = 0; thread_num < threads_count; thread_num++)
        {
            SBThread thread(process.GetThreadAtIndex(thread_num));
            SBFrame frame(thread.GetFrameAtIndex(0));
            Xcode::FetchVariables(frame,depth,GetVerbose());
            
        }
    }, "fetch-vars", "time to dump variables for the topmost frame in every thread"),
    m_run_expr_measurement([this] (SBFrame frame, const char* expr) -> void {
        SBValue value(frame.EvaluateExpression(expr, lldb::eDynamicCanRunTarget));
        Xcode::FetchVariable(value,0,GetVerbose());
    }, "run-expr", "time to evaluate an expression and display the result")
    {}
    
    virtual
    ~SketchTest ()
    {
    }
    
    virtual bool
	Setup (int argc, const char** argv)
    {
        SetVerbose(true);
        m_app_path.assign(argv[1]);
        m_doc_path.assign(argv[2]);
        m_out_path.assign(argv[3]);
        TestCase::Setup(argc,argv);
        m_target = m_debugger.CreateTarget(m_app_path.c_str());
        const char* file_arg = m_doc_path.c_str(); 
        const char* persist_arg = "-ApplePersistenceIgnoreState";
        const char* persist_skip = "YES";
        const char* empty = nullptr;
        const char* args[] = {file_arg,persist_arg,persist_skip,empty};
        SBLaunchInfo launch_info (args);
        m_file_line_bp_measurement(m_target, "SKTDocument.m",245);
        m_file_line_bp_measurement(m_target, "SKTDocument.m",283);
        m_file_line_bp_measurement(m_target, "SKTText.m",326);
        return Launch (launch_info);
    }
    
    void
    DoTest ()
    {
        m_fetch_frames_measurement(m_process);
        m_fetch_modules_measurement(m_target);
        m_fetch_vars_measurement(m_process,1);
    }
    
	virtual void
	TestStep (int counter, ActionWanted &next_action)
    {
        switch (counter)
        {
        case 0:
            {
                DoTest ();
                m_file_line_bp_measurement(m_target, "SKTDocument.m",254);
                next_action.Continue();
            }
            break;
                
        case 1:
            {
                DoTest ();
                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"properties");
                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"[properties description]");
                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"typeName");
                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"data");
                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"[data description]");
                next_action.Continue();
            }
            break;

        case 2:
            {
                DoTest ();
                next_action.Continue();
            }
            break;

        case 3:
            {
                DoTest ();
                next_action.StepOver(m_thread);
            }
            break;

        case 4:
            {
                DoTest ();
                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"layoutManager");
                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"contents");
                next_action.StepOver(m_thread);
            }
            break;
        
        case 5:
            {
                DoTest ();
                next_action.StepOver(m_thread);
            }
            break;

        case 6:
            {
                DoTest ();
                next_action.StepOver(m_thread);
            }
            break;

        case 7:
            {
                DoTest ();
                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"@\"an NSString\"");
                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"[(id)@\"an NSString\" description]");
                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"@[@1,@2,@3]");
                next_action.StepOut(m_thread);
            }
            break;

        case 8:
            {
                DoTest ();
                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"[graphics description]");
                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"[selectionIndexes description]");
                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"(BOOL)NSIntersectsRect(rect, graphicDrawingBounds)");
                next_action.Kill();
            }
            break;
        
        default:
            {
                next_action.Kill();
            }
            break;
        }
    }
    
    void
    Results ()
    {
        CFCMutableArray array;
        m_fetch_frames_measurement.Write(array);
        m_file_line_bp_measurement.Write(array);
        m_fetch_modules_measurement.Write(array);
        m_fetch_vars_measurement.Write(array);
        m_run_expr_measurement.Write(array);

        CFDataRef xmlData = CFPropertyListCreateData(kCFAllocatorDefault, array.get(), kCFPropertyListXMLFormat_v1_0, 0, NULL);
        
        CFURLRef file = CFURLCreateFromFileSystemRepresentation(NULL, (const UInt8*)m_out_path.c_str(), m_out_path.size(), FALSE);
        
        CFURLWriteDataAndPropertiesToResource(file,xmlData,NULL,NULL);
    }
    
private:
    Measurement<lldb_perf::TimeGauge, std::function<void(SBProcess)>> m_fetch_frames_measurement;
    Measurement<lldb_perf::TimeGauge, std::function<void(SBTarget, const char*, uint32_t)>> m_file_line_bp_measurement;
    Measurement<lldb_perf::TimeGauge, std::function<void(SBTarget)>> m_fetch_modules_measurement;
    Measurement<lldb_perf::TimeGauge, std::function<void(SBProcess,int)>> m_fetch_vars_measurement;
    Measurement<lldb_perf::TimeGauge, std::function<void(SBFrame,const char*)>> m_run_expr_measurement;
    
    std::string m_app_path;
    std::string m_doc_path;
    std::string m_out_path;
};

// argv[1] == path to app
// argv[2] == path to document
// argv[3] == path to result
int main(int argc, const char * argv[])
{
    SketchTest skt;
    TestCase::Run(skt,argc,argv);
    return 0;
}

OpenPOWER on IntegriCloud