Patchwork [1,of,2,V2] run-tests: added '--json' functionality to store timing data in json file

login
register
mail settings
Submitter Anurag Goel
Date June 22, 2014, 1:44 p.m.
Message ID <bdb3d7c108ba9a5ba38e.1403444683@ubuntu.ubuntu-domain>
Download mbox | patch
Permalink /patch/5037/
State Changes Requested
Headers show

Comments

Anurag Goel - June 22, 2014, 1:44 p.m.
# HG changeset patch
# User anuraggoel <anurag.dsps@gmail.com>
# Date 1403430215 -19800
#      Sun Jun 22 15:13:35 2014 +0530
# Node ID bdb3d7c108ba9a5ba38e1b3282dd18115ba6eed9
# Parent  f6e0718c2101207ba62ceccc7ca916f4e7d83b1d
run-tests: added '--json' functionality to store timing data in json file

This patch added a new functionality '--json'. While testing, if '--json'
is enabled then timing data gets stored in newly created "report.json" file,
in the following format.
testreport ={
    "test-xyz.t": 6.181909084320068
}

This "report.json" file will further accessed by html/javascript file to
plot graph between testname Vs testime.
Pierre-Yves David - June 23, 2014, 8:59 a.m.
On 06/22/2014 06:44 AM, Anurag Goel wrote:
> # HG changeset patch
> # User anuraggoel <anurag.dsps@gmail.com>
> # Date 1403430215 -19800
> #      Sun Jun 22 15:13:35 2014 +0530
> # Node ID bdb3d7c108ba9a5ba38e1b3282dd18115ba6eed9
> # Parent  f6e0718c2101207ba62ceccc7ca916f4e7d83b1d
> run-tests: added '--json' functionality to store timing data in json file

Why restricting this to timing data? Could we includes the success 
information too ?

>
> This patch added a new functionality '--json'. While testing, if '--json'
> is enabled then timing data gets stored in newly created "report.json" file,
> in the following format.
> testreport ={
>      "test-xyz.t": 6.181909084320068
> }
>
> This "report.json" file will further accessed by html/javascript file to
> plot graph between testname Vs testime.
>
> diff -r f6e0718c2101 -r bdb3d7c108ba tests/run-tests.py
> --- a/tests/run-tests.py	Sun Jun 22 01:35:29 2014 +0530
> +++ b/tests/run-tests.py	Sun Jun 22 15:13:35 2014 +0530
> @@ -58,6 +58,7 @@
>   import killdaemons as killmod
>   import Queue as queue
>   import unittest
> +import json
>
>   processlock = threading.Lock()
>
> @@ -185,6 +186,8 @@
>                " (default: $%s or %d)" % defaults['timeout'])
>       parser.add_option("--time", action="store_true",
>           help="time how long each test takes")
> +    parser.add_option("--json", action="store_true",
> +        help="store timing data in 'report.json' file")
>       parser.add_option("--tmpdir", type="string",
>           help="run tests in the given temporary directory"
>                " (implies --keep-tmpdir)")
> @@ -1341,9 +1344,19 @@
>                   os.environ['PYTHONHASHSEED'])
>           if self._runner.options.time:
>               self.printtimes(result.times)
> +        if self._runner.options.json:
> +            self.getjsonfile(result.times)
>
>           return result
>
> +    def getjsonfile(self, times):
> +        """Store timing data in json format in report.json file. """

extra space

> +
> +        fp = open("report.json", "w")
> +        timedata = dict(times)
> +        fp.writelines(("testreport =", (json.dumps(timedata, indent=2))))
> +        fp.close()
> +
>       def printtimes(self, times):
>           self.stream.writeln('# Producing time report')
>           times.sort(key=lambda t: (t[1], t[0]), reverse=True)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>
Anurag Goel - June 23, 2014, 9:56 a.m.
On Mon, Jun 23, 2014 at 2:29 PM, Pierre-Yves David <
pierre-yves.david@ens-lyon.org> wrote:

>
>
> On 06/22/2014 06:44 AM, Anurag Goel wrote:
>
>> # HG changeset patch
>> # User anuraggoel <anurag.dsps@gmail.com>
>> # Date 1403430215 -19800
>> #      Sun Jun 22 15:13:35 2014 +0530
>> # Node ID bdb3d7c108ba9a5ba38e1b3282dd18115ba6eed9
>> # Parent  f6e0718c2101207ba62ceccc7ca916f4e7d83b1d
>> run-tests: added '--json' functionality to store timing data in json file
>>
>
> Why restricting this to timing data? Could we includes the success
> information too ?


Yes, we can add success information too. But i am waiting for basic timing
information get accepted before adding more information up to next level.


>
>
>> This patch added a new functionality '--json'. While testing, if '--json'
>> is enabled then timing data gets stored in newly created "report.json"
>> file,
>> in the following format.
>> testreport ={
>>      "test-xyz.t": 6.181909084320068
>> }
>>
>> This "report.json" file will further accessed by html/javascript file to
>> plot graph between testname Vs testime.
>>
>> diff -r f6e0718c2101 -r bdb3d7c108ba tests/run-tests.py
>> --- a/tests/run-tests.py        Sun Jun 22 01:35:29 2014 +0530
>> +++ b/tests/run-tests.py        Sun Jun 22 15:13:35 2014 +0530
>> @@ -58,6 +58,7 @@
>>   import killdaemons as killmod
>>   import Queue as queue
>>   import unittest
>> +import json
>>
>>   processlock = threading.Lock()
>>
>> @@ -185,6 +186,8 @@
>>                " (default: $%s or %d)" % defaults['timeout'])
>>       parser.add_option("--time", action="store_true",
>>           help="time how long each test takes")
>> +    parser.add_option("--json", action="store_true",
>> +        help="store timing data in 'report.json' file")
>>       parser.add_option("--tmpdir", type="string",
>>           help="run tests in the given temporary directory"
>>                " (implies --keep-tmpdir)")
>> @@ -1341,9 +1344,19 @@
>>                   os.environ['PYTHONHASHSEED'])
>>           if self._runner.options.time:
>>               self.printtimes(result.times)
>> +        if self._runner.options.json:
>> +            self.getjsonfile(result.times)
>>
>>           return result
>>
>> +    def getjsonfile(self, times):
>> +        """Store timing data in json format in report.json file. """
>>
>
> extra space
>
>  +
>> +        fp = open("report.json", "w")
>> +        timedata = dict(times)
>> +        fp.writelines(("testreport =", (json.dumps(timedata, indent=2))))
>> +        fp.close()
>> +
>>       def printtimes(self, times):
>>           self.stream.writeln('# Producing time report')
>>           times.sort(key=lambda t: (t[1], t[0]), reverse=True)
>> _______________________________________________
>> Mercurial-devel mailing list
>> Mercurial-devel@selenic.com
>> http://selenic.com/mailman/listinfo/mercurial-devel
>>
>>
> --
> Pierre-Yves David
>
Pierre-Yves David - June 23, 2014, 9:58 a.m.
On 06/23/2014 02:56 AM, Anurag Goel wrote:
> On Mon, Jun 23, 2014 at 2:29 PM, Pierre-Yves David
> <pierre-yves.david@ens-lyon.org <mailto:pierre-yves.david@ens-lyon.org>>
> wrote:
>
>
>
>     On 06/22/2014 06:44 AM, Anurag Goel wrote:
>
>         # HG changeset patch
>         # User anuraggoel <anurag.dsps@gmail.com
>         <mailto:anurag.dsps@gmail.com>>
>         # Date 1403430215 -19800
>         #      Sun Jun 22 15:13:35 2014 +0530
>         # Node ID bdb3d7c108ba9a5ba38e1b3282dd18__115ba6eed9
>         # Parent  f6e0718c2101207ba62ceccc7ca916__f4e7d83b1d
>         run-tests: added '--json' functionality to store timing data in
>         json file
>
>
>     Why restricting this to timing data? Could we includes the success
>     information too ?
>
>
> Yes, we can add success information too. But i am waiting for basic
> timing information get accepted before adding more information up to
> next level.

Success information are more generic. Start by exporting then with 
--json. Then add timing information.

Patch

diff -r f6e0718c2101 -r bdb3d7c108ba tests/run-tests.py
--- a/tests/run-tests.py	Sun Jun 22 01:35:29 2014 +0530
+++ b/tests/run-tests.py	Sun Jun 22 15:13:35 2014 +0530
@@ -58,6 +58,7 @@ 
 import killdaemons as killmod
 import Queue as queue
 import unittest
+import json
 
 processlock = threading.Lock()
 
@@ -185,6 +186,8 @@ 
              " (default: $%s or %d)" % defaults['timeout'])
     parser.add_option("--time", action="store_true",
         help="time how long each test takes")
+    parser.add_option("--json", action="store_true",
+        help="store timing data in 'report.json' file")
     parser.add_option("--tmpdir", type="string",
         help="run tests in the given temporary directory"
              " (implies --keep-tmpdir)")
@@ -1341,9 +1344,19 @@ 
                 os.environ['PYTHONHASHSEED'])
         if self._runner.options.time:
             self.printtimes(result.times)
+        if self._runner.options.json:
+            self.getjsonfile(result.times)
 
         return result
 
+    def getjsonfile(self, times):
+        """Store timing data in json format in report.json file. """
+
+        fp = open("report.json", "w")
+        timedata = dict(times)
+        fp.writelines(("testreport =", (json.dumps(timedata, indent=2))))
+        fp.close()
+
     def printtimes(self, times):
         self.stream.writeln('# Producing time report')
         times.sort(key=lambda t: (t[1], t[0]), reverse=True)