Commit 52695898 by Vicent Martí

Merge pull request #709 from arrbee/profiling-with-scottg

Profiling with scottg
parents 88d6e044 e3557172
...@@ -53,6 +53,7 @@ OPTION (BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON) ...@@ -53,6 +53,7 @@ OPTION (BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON)
OPTION (THREADSAFE "Build libgit2 as threadsafe" OFF) OPTION (THREADSAFE "Build libgit2 as threadsafe" OFF)
OPTION (BUILD_CLAR "Build Tests using the Clar suite" ON) OPTION (BUILD_CLAR "Build Tests using the Clar suite" ON)
OPTION (TAGS "Generate tags" OFF) OPTION (TAGS "Generate tags" OFF)
OPTION (PROFILE "Generate profiling information" OFF)
# Platform specific compilation flags # Platform specific compilation flags
IF (MSVC) IF (MSVC)
...@@ -74,6 +75,10 @@ ELSE () ...@@ -74,6 +75,10 @@ ELSE ()
IF (NOT MINGW) # MinGW always does PIC and complains if we tell it to IF (NOT MINGW) # MinGW always does PIC and complains if we tell it to
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
ENDIF () ENDIF ()
IF (PROFILE)
SET(CMAKE_C_FLAGS "-pg ${CMAKE_C_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS "-pg ${CMAKE_EXE_LINKER_FLAGS}")
ENDIF ()
ENDIF() ENDIF()
# Build Debug by default # Build Debug by default
......
...@@ -61,7 +61,13 @@ char *colors[] = { ...@@ -61,7 +61,13 @@ char *colors[] = {
"\033[36m" /* cyan */ "\033[36m" /* cyan */
}; };
int printer(void *data, char usage, const char *line) int printer(
void *data,
git_diff_delta *delta,
git_diff_range *range,
char usage,
const char *line,
size_t line_len)
{ {
int *last_color = data, color = 0; int *last_color = data, color = 0;
......
...@@ -273,7 +273,7 @@ int main (int argc, char** argv) ...@@ -273,7 +273,7 @@ int main (int argc, char** argv)
// Once you have the entry object, you can access the content or subtree (or commit, in the case // Once you have the entry object, you can access the content or subtree (or commit, in the case
// of submodules) that it points to. You can also get the mode if you want. // of submodules) that it points to. You can also get the mode if you want.
git_tree_entry_2object(&objt, repo, entry); // blob git_tree_entry_to_object(&objt, repo, entry); // blob
// Remember to close the looked-up object once you are done using it // Remember to close the looked-up object once you are done using it
git_object_free(objt); git_object_free(objt);
......
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
/* Used as default value for git_buf->ptr so that people can always /* Used as default value for git_buf->ptr so that people can always
* assume ptr is non-NULL and zero terminated even for new git_bufs. * assume ptr is non-NULL and zero terminated even for new git_bufs.
*/ */
char git_buf_initbuf[1]; char git_buf__initbuf[1];
static char git_buf__oom; char git_buf__oom[1];
#define ENSURE_SIZE(b, d) \ #define ENSURE_SIZE(b, d) \
if ((d) > buf->asize && git_buf_grow(b, (d)) < 0)\ if ((d) > buf->asize && git_buf_grow(b, (d)) < 0)\
...@@ -25,7 +25,7 @@ void git_buf_init(git_buf *buf, size_t initial_size) ...@@ -25,7 +25,7 @@ void git_buf_init(git_buf *buf, size_t initial_size)
{ {
buf->asize = 0; buf->asize = 0;
buf->size = 0; buf->size = 0;
buf->ptr = git_buf_initbuf; buf->ptr = git_buf__initbuf;
if (initial_size) if (initial_size)
git_buf_grow(buf, initial_size); git_buf_grow(buf, initial_size);
...@@ -35,7 +35,7 @@ int git_buf_grow(git_buf *buf, size_t target_size) ...@@ -35,7 +35,7 @@ int git_buf_grow(git_buf *buf, size_t target_size)
{ {
int error = git_buf_try_grow(buf, target_size); int error = git_buf_try_grow(buf, target_size);
if (error != 0) if (error != 0)
buf->ptr = &git_buf__oom; buf->ptr = git_buf__oom;
return error; return error;
} }
...@@ -44,7 +44,7 @@ int git_buf_try_grow(git_buf *buf, size_t target_size) ...@@ -44,7 +44,7 @@ int git_buf_try_grow(git_buf *buf, size_t target_size)
char *new_ptr; char *new_ptr;
size_t new_size; size_t new_size;
if (buf->ptr == &git_buf__oom) if (buf->ptr == git_buf__oom)
return -1; return -1;
if (target_size <= buf->asize) if (target_size <= buf->asize)
...@@ -85,7 +85,7 @@ void git_buf_free(git_buf *buf) ...@@ -85,7 +85,7 @@ void git_buf_free(git_buf *buf)
{ {
if (!buf) return; if (!buf) return;
if (buf->ptr != git_buf_initbuf && buf->ptr != &git_buf__oom) if (buf->ptr != git_buf__initbuf && buf->ptr != git_buf__oom)
git__free(buf->ptr); git__free(buf->ptr);
git_buf_init(buf, 0); git_buf_init(buf, 0);
...@@ -98,11 +98,6 @@ void git_buf_clear(git_buf *buf) ...@@ -98,11 +98,6 @@ void git_buf_clear(git_buf *buf)
buf->ptr[0] = '\0'; buf->ptr[0] = '\0';
} }
bool git_buf_oom(const git_buf *buf)
{
return (buf->ptr == &git_buf__oom);
}
int git_buf_set(git_buf *buf, const char *data, size_t len) int git_buf_set(git_buf *buf, const char *data, size_t len)
{ {
if (len == 0 || data == NULL) { if (len == 0 || data == NULL) {
...@@ -164,7 +159,7 @@ int git_buf_vprintf(git_buf *buf, const char *format, va_list ap) ...@@ -164,7 +159,7 @@ int git_buf_vprintf(git_buf *buf, const char *format, va_list ap)
if (len < 0) { if (len < 0) {
git__free(buf->ptr); git__free(buf->ptr);
buf->ptr = &git_buf__oom; buf->ptr = git_buf__oom;
return -1; return -1;
} }
...@@ -244,7 +239,7 @@ char *git_buf_detach(git_buf *buf) ...@@ -244,7 +239,7 @@ char *git_buf_detach(git_buf *buf)
{ {
char *data = buf->ptr; char *data = buf->ptr;
if (buf->asize == 0 || buf->ptr == &git_buf__oom) if (buf->asize == 0 || buf->ptr == git_buf__oom)
return NULL; return NULL;
git_buf_init(buf, 0); git_buf_init(buf, 0);
...@@ -445,3 +440,22 @@ int git_buf_common_prefix(git_buf *buf, const git_strarray *strings) ...@@ -445,3 +440,22 @@ int git_buf_common_prefix(git_buf *buf, const git_strarray *strings)
return 0; return 0;
} }
bool git_buf_is_binary(const git_buf *buf)
{
size_t i;
int printable = 0, nonprintable = 0;
for (i = 0; i < buf->size; i++) {
unsigned char c = buf->ptr[i];
if (c > 0x1F && c < 0x7F)
printable++;
else if (c == '\0')
return true;
else if (!git__isspace(c))
nonprintable++;
}
return ((printable >> 7) < nonprintable);
}
...@@ -15,9 +15,10 @@ typedef struct { ...@@ -15,9 +15,10 @@ typedef struct {
size_t asize, size; size_t asize, size;
} git_buf; } git_buf;
extern char git_buf_initbuf[]; extern char git_buf__initbuf[];
extern char git_buf__oom[];
#define GIT_BUF_INIT { git_buf_initbuf, 0, 0 } #define GIT_BUF_INIT { git_buf__initbuf, 0, 0 }
/** /**
* Initialize a git_buf structure. * Initialize a git_buf structure.
...@@ -61,7 +62,10 @@ void git_buf_attach(git_buf *buf, char *ptr, size_t asize); ...@@ -61,7 +62,10 @@ void git_buf_attach(git_buf *buf, char *ptr, size_t asize);
* *
* @return false if no error, true if allocation error * @return false if no error, true if allocation error
*/ */
bool git_buf_oom(const git_buf *buf); GIT_INLINE(bool) git_buf_oom(const git_buf *buf)
{
return (buf->ptr == git_buf__oom);
}
/* /*
* Functions below that return int value error codes will return 0 on * Functions below that return int value error codes will return 0 on
...@@ -125,4 +129,7 @@ int git_buf_cmp(const git_buf *a, const git_buf *b); ...@@ -125,4 +129,7 @@ int git_buf_cmp(const git_buf *a, const git_buf *b);
/* Fill buf with the common prefix of a array of strings */ /* Fill buf with the common prefix of a array of strings */
int git_buf_common_prefix(git_buf *buf, const git_strarray *strings); int git_buf_common_prefix(git_buf *buf, const git_strarray *strings);
/* Check if buffer looks like it contains binary data */
bool git_buf_is_binary(const git_buf *buf);
#endif #endif
...@@ -174,15 +174,12 @@ static int file_is_binary_by_content( ...@@ -174,15 +174,12 @@ static int file_is_binary_by_content(
git_map *new_data) git_map *new_data)
{ {
git_buf search; git_buf search;
git_text_stats stats;
if ((delta->old_file.flags & BINARY_DIFF_FLAGS) == 0) { if ((delta->old_file.flags & BINARY_DIFF_FLAGS) == 0) {
search.ptr = old_data->data; search.ptr = old_data->data;
search.size = min(old_data->len, 4000); search.size = min(old_data->len, 4000);
git_text_gather_stats(&stats, &search); if (git_buf_is_binary(&search))
if (git_text_is_binary(&stats))
delta->old_file.flags |= GIT_DIFF_FILE_BINARY; delta->old_file.flags |= GIT_DIFF_FILE_BINARY;
else else
delta->old_file.flags |= GIT_DIFF_FILE_NOT_BINARY; delta->old_file.flags |= GIT_DIFF_FILE_NOT_BINARY;
...@@ -192,9 +189,7 @@ static int file_is_binary_by_content( ...@@ -192,9 +189,7 @@ static int file_is_binary_by_content(
search.ptr = new_data->data; search.ptr = new_data->data;
search.size = min(new_data->len, 4000); search.size = min(new_data->len, 4000);
git_text_gather_stats(&stats, &search); if (git_buf_is_binary(&search))
if (git_text_is_binary(&stats))
delta->new_file.flags |= GIT_DIFF_FILE_BINARY; delta->new_file.flags |= GIT_DIFF_FILE_BINARY;
else else
delta->new_file.flags |= GIT_DIFF_FILE_NOT_BINARY; delta->new_file.flags |= GIT_DIFF_FILE_NOT_BINARY;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment