Skip to content

Commit

Permalink
cli: Add a leaks sub-command.
Browse files Browse the repository at this point in the history
Merely invokes leaks.py
  • Loading branch information
jrfonseca committed Jan 22, 2016
1 parent 731ccce commit c4343f1
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions cli/CMakeLists.txt
Expand Up @@ -19,6 +19,7 @@ add_executable (apitrace
cli_diff.cpp
cli_diff_state.cpp
cli_diff_images.cpp
cli_leaks.cpp
cli_dump.cpp
cli_dump_images.cpp
cli_pager.cpp
Expand Down
1 change: 1 addition & 0 deletions cli/cli.hpp
Expand Up @@ -44,6 +44,7 @@ extern const Command diff_state_command;
extern const Command diff_images_command;
extern const Command dump_command;
extern const Command dump_images_command;
extern const Command leaks_command;
extern const Command pickle_command;
extern const Command repack_command;
extern const Command retrace_command;
Expand Down
85 changes: 85 additions & 0 deletions cli/cli_leaks.cpp
@@ -0,0 +1,85 @@
/*********************************************************************
*
* Copyright 2016 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*********************************************************************/

#include <string.h>
#include <iostream>

#include "cli.hpp"
#include "os_string.hpp"
#include "os_process.hpp"
#include "cli_resources.hpp"

static const char *synopsis = "Check trace for object leaks.";

static os::String
find_command(void)
{
return findScript("leaks.py");
}

static void
usage(void)
{
os::String command = find_command();

char *args[4];
args[0] = (char *) APITRACE_PYTHON_EXECUTABLE;
args[1] = (char *) command.str();
args[2] = (char *) "--help";
args[3] = NULL;

os::execute(args);
}

static int
command(int argc, char *argv[])
{
int i;

os::String command = find_command();

os::String apitracePath = os::getProcessName();

std::vector<const char *> args;
args.push_back("python");
args.push_back(command.str());
args.push_back("--apitrace");
args.push_back(apitracePath.str());
for (i = 1; i < argc; i++) {
args.push_back(argv[i]);
}
args.push_back(NULL);

return os::execute((char * const *)&args[0]);
}

const Command leaks_command = {
"leaks",
synopsis,
usage,
command
};
1 change: 1 addition & 0 deletions cli/cli_main.cpp
Expand Up @@ -71,6 +71,7 @@ static const Command * commands[] = {
&diff_images_command,
&dump_command,
&dump_images_command,
&leaks_command,
&pickle_command,
&sed_command,
&repack_command,
Expand Down

0 comments on commit c4343f1

Please sign in to comment.