Skip to content

Commit 0158724

Browse files
committed
Add warnings, improve warnings
1 parent b7f3eea commit 0158724

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

memprof.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ static void (*old_zend_execute_internal)(zend_execute_data *execute_data_ptr, zv
189189
static PHP_INI_MH((*origOnChangeMemoryLimit)) = NULL;
190190

191191
static int memprof_enabled = 0;
192+
static int memprof_dumped = 0;
192193
static int track_mallocs = 0;
193194

194195
static frame default_frame;
@@ -719,6 +720,7 @@ static void memprof_enable()
719720
MALLOC_HOOK_SET_OWN();
720721

721722
memprof_enabled = 1;
723+
memprof_dumped = 0;
722724

723725
if (is_zend_mm()) {
724726
/* There is no way to completely free a zend_mm_heap with custom
@@ -763,6 +765,10 @@ static void memprof_disable()
763765

764766
JudyLFreeArray(&allocs_set, PJE0);
765767
allocs_set = (Pvoid_t) NULL;
768+
769+
if (!memprof_dumped) {
770+
zend_error(E_WARNING, "Memprof profiling was enabled, but no profile was dumped. Did you forget to call one of memprof_dump_callgrind(), memprof_dump_pprof(), or memprof_dump_array() ?");
771+
}
766772
}
767773

768774
static void disable_opcache()
@@ -1244,7 +1250,7 @@ PHP_FUNCTION(memprof_dump_array)
12441250
}
12451251

12461252
if (!memprof_enabled) {
1247-
zend_throw_exception(EG(exception_class), "memprof is not enabled", 0);
1253+
zend_throw_exception(EG(exception_class), "memprof_dump_array(): memprof is not enabled", 0);
12481254
return;
12491255
}
12501256

@@ -1253,6 +1259,8 @@ PHP_FUNCTION(memprof_dump_array)
12531259
dump_frame_array(return_value, &default_frame);
12541260

12551261
} END_WITHOUT_MALLOC_TRACKING;
1262+
1263+
memprof_dumped = 1;
12561264
}
12571265
/* }}} */
12581266

@@ -1270,7 +1278,7 @@ PHP_FUNCTION(memprof_dump_callgrind)
12701278
}
12711279

12721280
if (!memprof_enabled) {
1273-
zend_throw_exception(EG(exception_class), "memprof is not enabled", 0);
1281+
zend_throw_exception(EG(exception_class), "memprof_dump_callgrind(): memprof is not enabled", 0);
12741282
return;
12751283
}
12761284

@@ -1289,6 +1297,8 @@ PHP_FUNCTION(memprof_dump_callgrind)
12891297
stream_printf(stream, "total: %zu %zu\n", total_size, total_count);
12901298

12911299
} END_WITHOUT_MALLOC_TRACKING;
1300+
1301+
memprof_dumped = 1;
12921302
}
12931303
/* }}} */
12941304

@@ -1305,7 +1315,7 @@ PHP_FUNCTION(memprof_dump_pprof)
13051315
}
13061316

13071317
if (!memprof_enabled) {
1308-
zend_throw_exception(EG(exception_class), "memprof is not enabled", 0);
1318+
zend_throw_exception(EG(exception_class), "memprof_dump_pprof(): memprof is not enabled", 0);
13091319
return;
13101320
}
13111321

@@ -1341,6 +1351,8 @@ PHP_FUNCTION(memprof_dump_pprof)
13411351
zend_hash_destroy(&symbols);
13421352

13431353
} END_WITHOUT_MALLOC_TRACKING;
1354+
1355+
memprof_dumped = 1;
13441356
}
13451357
/* }}} */
13461358

@@ -1393,7 +1405,7 @@ PHP_FUNCTION(memprof_enable)
13931405
}
13941406

13951407
if (memprof_enabled) {
1396-
zend_throw_exception(EG(exception_class), "memprof is already enabled", 0);
1408+
zend_throw_exception(EG(exception_class), "memprof_enable(): memprof is already enabled", 0);
13971409
return;
13981410
}
13991411

@@ -1414,7 +1426,7 @@ PHP_FUNCTION(memprof_disable)
14141426
}
14151427

14161428
if (!memprof_enabled) {
1417-
zend_throw_exception(EG(exception_class), "memprof is not enabled", 0);
1429+
zend_throw_exception(EG(exception_class), "memprof_disable(): memprof is not enabled", 0);
14181430
return;
14191431
}
14201432

0 commit comments

Comments
 (0)