[2/4] reduce cookie tracking: count cookies

add an efficient cookie counting function

Change-Id: Iec879d797ed22cf47509d3aba0928e699ee96410