Skip to content

Commit 6022d73

Browse files
committed
fix profiler
1 parent acfbcfa commit 6022d73

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/profiler.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ get_stmt_profile_next(profiler_iterator *pi)
181181
HASH_FIND,
182182
&found);
183183

184-
if (found)
184+
if (!found)
185185
elog(ERROR, "broken consistency of plpgsql_check profiler chunks");
186186

187187
pi->current_statement = 0;
@@ -820,14 +820,14 @@ update_persistent_profile(profiler_info *pinfo, PLpgSQL_function *func)
820820
else
821821
stmt_counter = -1;
822822

823+
hk.chunk_num = 0;
824+
823825
/* we should to enter empty chunks first */
824826
for (i = 0; i < profile->nstatements; i++)
825827
{
826828
profiler_stmt_reduced *prstmt;
827829
profiler_stmt *pstmt = &pinfo->stmts[i];
828830

829-
hk.chunk_num = 0;
830-
831831
if (stmt_counter == -1 || stmt_counter >= STATEMENTS_PER_CHUNK)
832832
{
833833
hk.chunk_num += 1;
@@ -944,17 +944,17 @@ profiler_update_map(profiler_profile *profile, PLpgSQL_stmt *stmt)
944944
int i;
945945

946946
/* calculate new size of map */
947-
for (lines = profile->stmts_map_max_lineno; stmt->lineno < lines;)
947+
for (lines = profile->stmts_map_max_lineno; lineno > lines;)
948948
if (lines < 10000)
949949
lines *= 2;
950950
else
951951
lines += 10000;
952952

953-
profile->stmts_map = realloc(profile->stmts_map,
953+
profile->stmts_map = repalloc(profile->stmts_map,
954954
lines * sizeof(profiler_map_entry));
955955

956956
for (i = profile->stmts_map_max_lineno; i < lines; i++)
957-
profile->stmts_map[i].stmt = NULL;
957+
memset(&profile->stmts_map[i], 0, sizeof(profiler_map_entry));
958958

959959
profile->stmts_map_max_lineno = lines;
960960
}

0 commit comments

Comments
 (0)