Exemple #1
0
bool CallStack::LeaveFrame(const std::string& name, 
                           const Time& leaveTime,
                           long& usecs,
                           bool longUnwind)
{
    bool success = false;

            SLOG_FROM(LOG_DEFAULT, "CallStack::LeaveFrame",
               "Leaving: " << name)

    if ( stack.size() > 0 ) {
        Frame& frame = stack.back();
        // If its the correct frame pop it...
        if ( frame.name == name ) {
            // Update the node in the call graph
            usecs = leaveTime.DiffUSecs(frame.startTime);
            activeNode->AddCall(usecs);

            // Remove the frame from the stack
            stack.pop_back();
            if ( !activeNode->IsRoot() ) {
                activeNode = activeNode->Parent();
            }

            success = true;
        } else {
            if (longUnwind) {
                success = true;
                Frame* pframe = &frame;
                bool found = false;
                do
                {
                    pframe = &stack.back();
                    found = (pframe->name == name);
                    success &= LeaveFrame(pframe->name,leaveTime,usecs,false);
                } while (stack.size() > 0 && !found);

                if (!found) {
                    success = false;
                }

            } else {
                usecs = -1;
                SLOG_FROM(LOG_ERROR, "CallStack::LeaveFrame",
                "Failed to leave frame " << name << " does not match statck " << stack.back().name;)
            }
        }
    } else {
Exemple #2
0
void DoTimedTest(const std::string& name,
                 size_t n,
                 std::function<void(size_t count)> f)
{
    Time start;
    f(n);
    Time stop;
    long duration_us = stop.DiffUSecs(start);
    long duration_ms = duration_us / 1000;
    double rate =   (n) /  (1.0 * duration_ms);
    double cost =   1000* duration_us / (1.0 * n);

    if ( baseline_duration == 0 )
    {
        baseline_duration = duration_us;

        cout << "| ";
        cout << setw(50) << left << name;
        cout << " | ";
        cout << left << setw(22) << duration_ms;
        cout << " | ";
        cout << setw(14) << left << rate;
        cout << " | ";
        cout << setw(14) << left << cost;
        cout << " |";
    } else {
        long durationRatio = (duration_us / baseline_duration);
        cout << "| ";
        cout << setw(50) << left << name;
        cout << " | ";
        std::stringstream buf;
        buf << left << duration_ms << " (x" << durationRatio<< ")";
        cout << setw(22) << buf.str();
        cout << " | ";
        cout << setw(14) << left << rate;
        cout << " | ";
        cout << setw(14) << left << cost;
        cout << " |";
    }

    results.AddRow(std::string(name),duration_us+0);

    cout << endl;
}
int NodeUserApp::Run() {
    exit = false;
    while ( !exit) {
        string name = application.ActiveNode()->Name();
        string shortName = name.substr(0,name.find("("));
        string cmd = term->GetLine("|" + shortName + "> ");
        try {
            Time start;
            Execute(cmd);
            Time stop;
            stringstream s;
            s << "\"" + cmd + "\" completed in ";
            s << stop.DiffUSecs(start) /1000 << "ms" << endl;;
            term->PutString(s.str());
        } catch ( Commands::ExecutionError& e ) {
            term->PutString(e.msg + "\n");
        }
    }
    return 0;
}
int main(int argc, const char *argv[])
{
    Terminal& term = Screen::Instance().MainTerminal();
    /*
     * Sanity check command line args
     */
    if ( argc != 2 ) {
        cout << "Usage: cgv <data file>" << endl;
        return 1;
    }

    /*
     * Build the call graph
     */
    term.PutString("Building call graph...");

    Time start;
    data = new CallgrindNative(argv[1]);
    Time end;

    COUT ( "done ("<< end.DiffUSecs(start)/1000 << "ms)" << endl)
    /*
     * Initialise the actual application and load user configuration
     */
    application = new NodeUserApp(data->RootNode(),nullptr);
    application->CommandDispatcher().AddCommand("annotate",&PrintAnnotation);

    if ( ENV::IsSet("CGV_CONFIG_FILE") ) { 
        string rcpath = ENV::GetEnvString("CGV_CONFIG_FILE");
        COUT ("Loading " + rcpath + "...");
        start.SetNow();
        CommandFile rcfile(rcpath);
        application->Execute(rcfile);
        end.SetNow();
        COUT ( "done (" << end.DiffUSecs(start)/1000 << "ms)" << endl);
    } else {
        // Check the unix home directory for a config file
        string homercpath = OS::Join(ENV::GetEnvString("HOME"),".cgvrc");
        if ( OS::Exists(homercpath) ) {
            COUT ("Loading " + homercpath + "...");
            start.SetNow();
            CommandFile homerc(homercpath);
            application->Execute(homerc);
            end.SetNow();
            COUT ( "done (" << end.DiffUSecs(start)/1000 << "ms)" << endl);
        }

        // Check the local directory for a config file
        if ( OS::Exists(".cgvrc") ) {
            COUT ("Loading ./.cgvrc ...");
            start.SetNow();
            CommandFile localrc(".cgvrc");
            application->Execute(localrc);
            end.SetNow();
            COUT ( "done (" << end.DiffUSecs(start)/1000 << "ms)" << endl);
        }
    }

    /*
     * Run the application
     */
    int ret =  application->Run();

    delete application;
    delete data;

    return ret;
}